stats

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartialPrintString added in v1.7.0

func PartialPrintString(noneEmptyPos []bool, f Features, shared bool) string

PartialPrintString can print certain features with different format.

func RunTestMain

func RunTestMain(m *testing.M) int

RunTestMain runs the tests with enabling injection of benchmark stats. It returns an exit code to pass to os.Exit.

Types

type BenchResults added in v1.7.0

type BenchResults struct {
	RunMode           string
	Features          Features
	Latency           []percentLatency
	Operations        int
	NsPerOp           int64
	AllocedBytesPerOp int64
	AllocsPerOp       int64
	SharedPosion      []bool
}

BenchResults records features and result of a benchmark.

type Features added in v1.7.0

type Features struct {
	NetworkMode        string
	EnableTrace        bool
	Latency            time.Duration
	Kbps               int
	Mtu                int
	MaxConcurrentCalls int
	ReqSizeBytes       int
	RespSizeBytes      int
	EnableCompressor   bool
	EnableChannelz     bool
}

Features contains most fields for a benchmark

func (Features) ConciseString added in v1.12.0

func (f Features) ConciseString() string

ConciseString returns the concise textual output of the Features as string, skipping setting with default value.

func (Features) String added in v1.7.0

func (f Features) String() string

String returns the textual output of the Features as 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 added in v1.5.0

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 Stats

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

Stats is a simple helper for gathering additional statistics like histogram during benchmarks. This is not thread safe.

func AddStats

func AddStats(b *testing.B, numBuckets int) *Stats

AddStats adds a new unnamed Stats instance to the current benchmark. You need to run benchmarks by calling RunTestMain() to inject the stats to the benchmark results. If numBuckets is not positive, the default value (16) will be used. Please note that this calls b.ResetTimer() since it may be blocked until the previous benchmark stats is printed out. So AddStats() should typically be called at the very beginning of each benchmark function.

func AddStatsWithName

func AddStatsWithName(b *testing.B, name string, numBuckets int) *Stats

AddStatsWithName adds a new named Stats instance to the current benchmark. With this, you can add multiple stats in a single benchmark. You need to run benchmarks by calling RunTestMain() to inject the stats to the benchmark results. If numBuckets is not positive, the default value (16) will be used. Please note that this calls b.ResetTimer() since it may be blocked until the previous benchmark stats is printed out. So AddStatsWithName() should typically be called at the very beginning of each benchmark function.

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) Add

func (stats *Stats) Add(d time.Duration)

Add adds an elapsed time per operation to the stats.

func (*Stats) BenchString added in v1.7.0

func (stats *Stats) BenchString() string

BenchString output latency stats as the format as time + unit.

func (*Stats) Clear

func (stats *Stats) Clear()

Clear resets the stats, removing all values.

func (*Stats) GetBenchmarkResults added in v1.7.0

func (stats *Stats) GetBenchmarkResults() BenchResults

GetBenchmarkResults returns the result of the benchmark including features and result.

func (*Stats) Print

func (stats *Stats) Print(w io.Writer)

Print writes textual output of the Stats.

func (*Stats) SetBenchmarkResult added in v1.7.0

func (stats *Stats) SetBenchmarkResult(mode string, features Features, o int, allocdBytes, allocs int64, sharedPos []bool)

SetBenchmarkResult sets features of benchmark and basic results.

func (*Stats) SortLatency added in v1.7.0

func (stats *Stats) SortLatency()

SortLatency blocks the output

func (*Stats) String

func (stats *Stats) String() string

String returns the textual output of the Stats as string.

Jump to

Keyboard shortcuts

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