Documentation ¶
Index ¶
- func HistogramsEqual(histogram1 Histogram, histogram2 Histogram) bool
- type FloatSlidingWindow
- type Histogram
- type HistogramOptions
- type MockHistogram
- func (m *MockHistogram) AddSample(value float64, weight float64)
- func (m *MockHistogram) IsEmpty() bool
- func (m *MockHistogram) Merge(other *Histogram)
- func (m *MockHistogram) Percentile(percentile float64) float64
- func (m *MockHistogram) String() string
- func (m *MockHistogram) SubtractSample(value float64, weight float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HistogramsEqual ¶
HistogramsEqual is a helper function for comparing 2 histograms.
Types ¶
type FloatSlidingWindow ¶
type FloatSlidingWindow interface { // Add a value to the end of the queue. On overflow returns true and the // oldest value, which is also removed from the buffer. Otherwise // returns (false, _). Push(value float64) (bool, float64) // Returns the elements in the buffer, ordered by time of insertion // (oldest first). Contents() []float64 // Returns a pointer to the most recently added element. The pointer can // be used to modify the last element. It is only valid until the next // call to Push(). Return nil if called on an empty buffer. Head() *float64 // Reset the contents of the window. Clear() }
FloatSlidingWindow is a buffer with a fixed capacity. Elements are inserted/removed in the FIFO order. Elements are removed from the buffer only when it runs out of capacity and a new element is inserted.
func NewFloatSlidingWindow ¶
func NewFloatSlidingWindow(size int) FloatSlidingWindow
NewFloatSlidingWindow returns a new instance of FloatSlidingWindowImpl with a given size.
type Histogram ¶
type Histogram interface { // Returns an approximation of the given percentile of the distribution. // Note: the argument passed to Percentile() is a number between // 0 and 1. For example 0.5 corresponds to the median and 0.9 to the // 90th percentile. // If the histogram is empty, Percentile() returns 0.0. Percentile(percentile float64) float64 // Add a sample with a given value and weight. AddSample(value float64, weight float64) // Remove a sample with a given value and weight. Note that the total // weight of samples with a given value cannot be negative. SubtractSample(value float64, weight float64) // Add all samples from another histogram. Requires the histograms to be // of the exact same type. Merge(other *Histogram) // Returns true if the histogram is empty. IsEmpty() bool // Returns a human-readable text description of the histogram. String() string }
Histogram represents an approximate distribution of some variable.
func NewHistogram ¶
func NewHistogram(options *HistogramOptions) Histogram
NewHistogram returns a new Histogram instance using given options.
type HistogramOptions ¶
type HistogramOptions interface { // Returns the number of buckets in the histogram. NumBuckets() int // Returns the index of the bucket to which the given value falls. // If the value is outside of the range covered by the histogram, it // returns the closest bucket (either the first or the last one). FindBucket(value float64) int // Returns the start of the bucket with a given index. If the index is // outside the [0..NumBuckets() - 1] range, the result is undefined. GetBucketStart(bucket int) float64 // Returns the minimum weight for a bucket to be considered non-empty. Epsilon() float64 }
HistogramOptions define the number and size of buckets of a histogram.
func NewExponentialHistogramOptions ¶
func NewExponentialHistogramOptions( maxValue float64, firstBucketSize float64, ratio float64, epsilon float64) (HistogramOptions, error)
NewExponentialHistogramOptions returns HistogramOptions describing a histogram with exponentially growing bucket boundaries. The first bucket covers the range [0..firstBucketSize). Consecutive buckets are of the form [x(n)..x(n) * ratio) for n = 1 .. numBuckets - 1. The last bucket start is larger or equal to maxValue. Requires maxValue > 0, firstBucketSize > 0, ratio > 1, epsilon > 0.
func NewLinearHistogramOptions ¶
func NewLinearHistogramOptions( maxValue float64, bucketSize float64, epsilon float64) (HistogramOptions, error)
NewLinearHistogramOptions returns HistogramOptions describing a histogram with a given number of fixed-size buckets, with the first bucket start at 0.0 and the last bucket start larger or equal to maxValue. Requires maxValue > 0, bucketSize > 0, epsilon > 0.
type MockHistogram ¶
MockHistogram is a mock implementation of Histogram interface.
func (*MockHistogram) AddSample ¶
func (m *MockHistogram) AddSample(value float64, weight float64)
AddSample is a mock implementation of Histogram.AddSample.
func (*MockHistogram) IsEmpty ¶
func (m *MockHistogram) IsEmpty() bool
IsEmpty is a mock implementation of Histogram.IsEmpty.
func (*MockHistogram) Merge ¶
func (m *MockHistogram) Merge(other *Histogram)
Merge is a mock implementation of Histogram.Merge.
func (*MockHistogram) Percentile ¶
func (m *MockHistogram) Percentile(percentile float64) float64
Percentile is a mock implementation of Histogram.Percentile.
func (*MockHistogram) String ¶
func (m *MockHistogram) String() string
String is a mock implementation of Histogram.String.
func (*MockHistogram) SubtractSample ¶
func (m *MockHistogram) SubtractSample(value float64, weight float64)
SubtractSample is a mock implementation of Histogram.SubtractSample.