stats

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 11 Imported by: 0

Documentation

Overview

Package stats tracks the statistics associated with benchmark runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BenchResults

type BenchResults struct {
	// TestOperation is the workload mode for this benchmark run. This could be unary,
	// stream or unconstrained.
	TestOperation string
	// Features represents the configured feature options for this run.
	Features Features
	// Data contains the statistical data of interest from the benchmark run.
	Data RunData
}

BenchResults records features and results of a benchmark run. A collection of these structs is usually serialized and written to a file after a benchmark execution, and could later be read for pretty-printing or comparison with other benchmark results.

type FeatureIndex

type FeatureIndex int

FeatureIndex is an enum for features that usually differ across individual benchmark runs in a single execution. These are usually configured by the user through command line flags.

const (
	MaxConcurrentCallsIndex FeatureIndex = iota
	// MaxFeatureIndex is a place holder to indicate the total number of feature
	// indices we have. Any new feature indices should be added above this.
	MaxFeatureIndex
)

FeatureIndex enum values corresponding to individually settable features.

type Features

type Features struct {
	// BenchTime indicates the duration of the benchmark run.
	BenchTime time.Duration
	// MaxConcurrentCalls is the number of concurrent RPCs made during this
	// benchmark run.
	MaxConcurrentCalls int
	// Instance count in one service
	Namespace string
	// Metadata count in each instance
	Service string
	// size for client send message
	ArraySize int
}

Features represent configured options for a specific benchmark run. This is usually constructed from command line arguments passed by the caller. See benchmark/benchmain/main.go for defined command line flags. This is also part of the BenchResults struct which is serialized and written to a file.

func (Features) PrintableName

func (f Features) PrintableName(wantFeatures []bool) string

PrintableName returns a one line name which includes the features specified by 'wantFeatures' which is a bitmask of wanted features, indexed by FeaturesIndex.

func (Features) String

func (f Features) String() string

String returns all the feature values as a string.

type Histogram

type Histogram struct {
	// Count is the total number of values added to the histogram.
	Count int64
	// Sum is the sum of all the values added to the histogram.
	Sum int64
	// SumOfSquares is the sum of squares of all values.
	SumOfSquares int64
	// Min is the minimum of all the values added to the histogram.
	Min int64
	// Max is the maximum of all the values added to the histogram.
	Max int64
	// Buckets contains all the buckets of the histogram.
	Buckets []HistogramBucket
	// contains filtered or unexported fields
}

Histogram accumulates values in the form of a histogram with exponentially increased bucket sizes.

func NewHistogram

func NewHistogram(opts HistogramOptions) *Histogram

NewHistogram returns a pointer to a new Histogram object that was created with the provided options.

func (*Histogram) Add

func (h *Histogram) Add(value int64) error

Add adds a value to the histogram.

func (*Histogram) Clear

func (h *Histogram) Clear()

Clear resets all the content of histogram.

func (*Histogram) Merge

func (h *Histogram) Merge(h2 *Histogram)

Merge takes another histogram h2, and merges its content into h. The two histograms must be created by equivalent HistogramOptions.

func (*Histogram) Opts

func (h *Histogram) Opts() HistogramOptions

Opts returns a copy of the options used to create the Histogram.

func (*Histogram) Print

func (h *Histogram) Print(w io.Writer)

Print writes textual output of the histogram values.

func (*Histogram) PrintWithUnit

func (h *Histogram) PrintWithUnit(w io.Writer, unit float64)

PrintWithUnit writes textual output of the histogram values . Data in histogram is divided by a Unit before print.

func (*Histogram) String

func (h *Histogram) String() string

String returns the textual output of the histogram values as string.

type HistogramBucket

type HistogramBucket struct {
	// LowBound is the lower bound of the bucket.
	LowBound float64
	// Count is the number of values in the bucket.
	Count int64
}

HistogramBucket represents one histogram bucket.

type HistogramOptions

type HistogramOptions struct {
	// NumBuckets is the number of buckets.
	NumBuckets int
	// GrowthFactor is the growth factor of the buckets. A value of 0.1
	// indicates that bucket N+1 will be 10% larger than bucket N.
	GrowthFactor float64
	// BaseBucketSize is the size of the first bucket.
	BaseBucketSize float64
	// MinValue is the lower bound of the first bucket.
	MinValue int64
}

HistogramOptions contains the parameters that define the histogram's buckets. The first bucket of the created histogram (with index 0) contains [min, min+n) where n = BaseBucketSize, min = MinValue. Bucket i (i>=1) contains [min + n * m^(i-1), min + n * m^i), where m = 1+GrowthFactor. The type of the values is int64.

type RunData

type RunData struct {
	// TotalOps is the number of operations executed during this benchmark run.
	// Only makes sense for unary and streaming workloads.
	TotalOps uint64
	// SendOps is the number of send operations executed during this benchmark
	// run. Only makes sense for unconstrained workloads.
	SendOps uint64
	// RecvOps is the number of receive operations executed during this benchmark
	// run. Only makes sense for unconstrained workloads.
	RecvOps uint64
	// AllocedBytes is the average memory allocation in bytes per operation.
	AllocedBytes float64
	// Allocs is the average number of memory allocations per operation.
	Allocs float64
	// Fiftieth is the 50th percentile latency.
	Fiftieth time.Duration
	// Ninetieth is the 90th percentile latency.
	Ninetieth time.Duration
	// Ninetyninth is the 99th percentile latency.
	NinetyNinth time.Duration
	// Average is the average latency.
	Average time.Duration
}

RunData contains statistical data of interest from a benchmark run.

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats is a helper for gathering statistics about individual benchmark runs.

func NewStats

func NewStats(numBuckets int) *Stats

NewStats creates a new Stats instance. If numBuckets is not positive, the default value (16) will be used.

func (*Stats) AddDuration

func (s *Stats) AddDuration(d time.Duration)

AddDuration adds an elapsed duration per operation to the stats. This is used by unary and stream modes where request and response stats are equal.

func (*Stats) EndRun

func (s *Stats) EndRun(count uint64)

EndRun is to be invoked to indicate the end of the ongoing benchmark run. It computes a bunch of stats and dumps them to stdout.

func (*Stats) EndUnconstrainedRun

func (s *Stats) EndUnconstrainedRun(req uint64, resp uint64)

EndUnconstrainedRun is similar to EndRun, but is to be used for unconstrained workloads.

func (*Stats) GetResults

func (s *Stats) GetResults() []BenchResults

GetResults returns the results from all benchmark runs.

func (*Stats) StartRun

func (s *Stats) StartRun(operation string, f Features)

StartRun is to be invoked to indicate the start of a new benchmark run.

Jump to

Keyboard shortcuts

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