printer

package
v0.1.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParquetResultDetail added in v0.1.24

type ParquetResultDetail struct {
	Timestamp       int64  `parquet:"timestamp,timestamp(millisecond)"`
	Latency         int64  `parquet:"latency"`
	Error           string `parquet:"error,optional,dict"`
	Status          string `parquet:"status,dict"`
	RequestPayload  string `parquet:"request_payload,optional"`
	ResponsePayload string `parquet:"response_payload,optional"`
}

ParquetResultDetail is the Parquet-optimized version of ResultDetail

type ReportPrinter

type ReportPrinter struct {
	Out    io.Writer
	Report *runner.Report
}

ReportPrinter is used for printing the report

func (*ReportPrinter) Print

func (rp *ReportPrinter) Print(format string) error

Print the report using the given format If format is "csv" detailed listing is printer in csv format. Otherwise the summary of results is printed.

Supported Format:

summary
csv
json
pretty
html
influx-summary
influx-details
parquet
Example (Parquet)

ExampleReportPrinter_Print_parquet demonstrates using Print method with parquet format.

package main

import (
	"fmt"
	"os"

	"github.com/chalk-ai/ghz/printer"
	"github.com/chalk-ai/ghz/runner"
)

func main() {
	// Run the benchmark
	report, err := runner.Run(
		"helloworld.Greeter.SayHello",
		"localhost:50051",
		runner.WithProtoFile("greeter.proto", []string{}),
		runner.WithDataFromFile("data.json"),
		runner.WithInsecure(true),
	)

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// Open a file for output
	file, err := os.Create("results.parquet")
	if err != nil {
		fmt.Println("Error creating file:", err.Error())
		os.Exit(1)
	}
	defer file.Close()

	// Create printer with file as output
	printer := printer.ReportPrinter{
		Out:    file,
		Report: report,
	}

	// Use Print method with parquet format
	if err := printer.Print("parquet"); err != nil {
		fmt.Println("Error writing parquet:", err.Error())
		os.Exit(1)
	}

	fmt.Println("Results saved to results.parquet")
}

func (*ReportPrinter) WriteParquetFile added in v0.1.27

func (rp *ReportPrinter) WriteParquetFile(outputPath string) error

WriteParquetFile writes the report details to a parquet file

Example

ExampleReportPrinter_WriteParquetFile demonstrates how to save report details to a parquet file.

package main

import (
	"fmt"
	"os"

	"github.com/chalk-ai/ghz/printer"
	"github.com/chalk-ai/ghz/runner"
)

func main() {
	// Run the benchmark
	report, err := runner.Run(
		"helloworld.Greeter.SayHello",
		"localhost:50051",
		runner.WithProtoFile("greeter.proto", []string{}),
		runner.WithDataFromFile("data.json"),
		runner.WithInsecure(true),
	)

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// Create printer
	printer := printer.ReportPrinter{
		Out:    os.Stdout,
		Report: report,
	}

	// Save results to parquet file
	if err := printer.WriteParquetFile("results.parquet"); err != nil {
		fmt.Println("Error writing parquet file:", err.Error())
		os.Exit(1)
	}

	fmt.Println("Results saved to results.parquet")
}

func (*ReportPrinter) WriteParquetSampleFile added in v0.1.27

func (rp *ReportPrinter) WriteParquetSampleFile(outputPath string) error

WriteParquetSampleFile writes the report sample details to a parquet file

Example

ExampleReportPrinter_WriteParquetSampleFile demonstrates how to save sampled results to a parquet file. This is useful when you've enabled data sampling with WithDataSamplingRate.

package main

import (
	"fmt"
	"os"

	"github.com/chalk-ai/ghz/printer"
	"github.com/chalk-ai/ghz/runner"
)

func main() {
	// Run the benchmark with data sampling enabled
	report, err := runner.Run(
		"helloworld.Greeter.SayHello",
		"localhost:50051",
		runner.WithProtoFile("greeter.proto", []string{}),
		runner.WithDataFromFile("data.json"),
		runner.WithInsecure(true),
		runner.WithDataSamplingRate(0.1), // Sample 10% of requests
	)

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// Create printer
	printer := printer.ReportPrinter{
		Out:    os.Stdout,
		Report: report,
	}

	// Save sampled results with payloads to parquet file
	if err := printer.WriteParquetSampleFile("sampled_results.parquet"); err != nil {
		fmt.Println("Error writing parquet file:", err.Error())
		os.Exit(1)
	}

	fmt.Println("Sampled results saved to sampled_results.parquet")
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL