stats

package
v0.0.0-...-79b8380 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: Apache-2.0, BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TimeNow is used for testing.
	TimeNow = time.Now
)

Functions

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 Counter

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

Counter is a counter that keeps track of its recent values over a given period of time, and with a given resolution. Use newCounter() to instantiate.

func (*Counter) Delta10m

func (c *Counter) Delta10m() int64

Delta10m returns the delta for the last 10 minutes.

func (*Counter) Delta1h

func (c *Counter) Delta1h() int64

Delta1h returns the delta for the last hour.

func (*Counter) Delta1m

func (c *Counter) Delta1m() int64

Delta1m returns the delta for the last minute.

func (*Counter) Incr

func (c *Counter) Incr(delta int64)

Incr increments the current value of the counter by 'delta'.

func (*Counter) LastUpdate

func (c *Counter) LastUpdate() time.Time

LastUpdate returns the last update time of the counter.

func (*Counter) Rate10m

func (c *Counter) Rate10m() float64

Rate10m returns the rate of change of the counter in the last 10 minutes.

func (*Counter) Rate1h

func (c *Counter) Rate1h() float64

Rate1h returns the rate of change of the counter in the last hour.

func (*Counter) Rate1m

func (c *Counter) Rate1m() float64

Rate1m returns the rate of change of the counter in the last minute.

func (*Counter) Reset

func (c *Counter) Reset()

Reset resets the counter to an empty state.

func (*Counter) Set

func (c *Counter) Set(value int64)

Set updates the current value of the counter.

func (*Counter) Value

func (c *Counter) Value() int64

Value returns the current value of the counter.

type Histogram

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

A Histogram accumulates values in the form of a histogram. The type of the values is int64, which is suitable for keeping track of things like RPC latency in milliseconds. New histogram objects should be obtained via the New() function.

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

func (h *Histogram) Delta10m() HistogramValue

Delta10m returns the change in the last 10 minutes.

func (*Histogram) Delta1h

func (h *Histogram) Delta1h() HistogramValue

Delta1h returns the change in the last hour.

func (*Histogram) Delta1m

func (h *Histogram) Delta1m() HistogramValue

Delta1m returns the change in the last 10 minutes.

func (*Histogram) LastUpdate

func (h *Histogram) LastUpdate() time.Time

LastUpdate returns the time at which the object was last updated.

func (*Histogram) Opts

func (h *Histogram) Opts() HistogramOptions

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

func (*Histogram) Value

func (h *Histogram) Value() HistogramValue

Value returns the accumulated state of the histogram since it was created.

type HistogramBucket

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

HistogramBucket is 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
	// SmallestBucketSize is the size of the first bucket. Bucket sizes are
	// rounded down to the nearest integer.
	SmallestBucketSize float64
	// MinValue is the lower bound of the first bucket.
	MinValue int64
}

HistogramOptions contains the parameters that define the histogram's buckets.

type HistogramValue

type HistogramValue 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
	// 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
}

HistogramValue is the value of Histogram objects.

func (HistogramValue) Print

func (v HistogramValue) Print(w io.Writer)

Print writes textual output of the histogram values.

func (HistogramValue) String

func (v HistogramValue) String() string

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

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

func (stats *Stats) Clear()

Clear resets the stats, removing all values.

func (*Stats) Print

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

Print writes textual output of the Stats.

func (*Stats) String

func (stats *Stats) String() string

String returns the textual output of the Stats as string.

type Tracker

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

Tracker is a min/max value tracker that keeps track of its min/max values over a given period of time, and with a given resolution. The initial min and max values are math.MaxInt64 and math.MinInt64 respectively.

func (*Tracker) LastUpdate

func (t *Tracker) LastUpdate() time.Time

LastUpdate returns the last update time of the range.

func (*Tracker) Max

func (t *Tracker) Max() int64

Max returns the maximum value of the tracker.

func (*Tracker) Max10m

func (t *Tracker) Max10m() int64

Max10m returns the maximum value for the last 10 minutes.

func (*Tracker) Max1h

func (t *Tracker) Max1h() int64

Max1h returns the maximum value for the last hour.

func (*Tracker) Max1m

func (t *Tracker) Max1m() int64

Max1m returns the maximum value for the last 1 minute.

func (*Tracker) Min

func (t *Tracker) Min() int64

Min returns the minimum value of the tracker

func (*Tracker) Min10m

func (t *Tracker) Min10m() int64

Min10m returns the minimum value for the last 10 minutes.

func (*Tracker) Min1h

func (t *Tracker) Min1h() int64

Min1h returns the minimum value for the last hour.

func (*Tracker) Min1m

func (t *Tracker) Min1m() int64

Min1m returns the minimum value for the last 1 minute.

func (*Tracker) Push

func (t *Tracker) Push(value int64)

Push adds a new value if it is a new minimum or maximum.

func (*Tracker) Reset

func (t *Tracker) Reset()

Reset resets the range to an empty state.

Jump to

Keyboard shortcuts

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