Documentation ¶
Index ¶
- func ParsePercentiles(percentiles string) ([]float64, error)
- func Round(v float64) float64
- func RoundToDigits(v float64, digits int) float64
- type Bucket
- type Counter
- type Histogram
- func (h *Histogram) Clone() *Histogram
- func (h *Histogram) CopyFrom(src *Histogram)
- func (h *Histogram) Export() *HistogramData
- func (h *Histogram) Log(msg string, percentiles []float64)
- func (h *Histogram) Print(out io.Writer, msg string, percentiles []float64)
- func (h *Histogram) Record(v float64)
- func (h *Histogram) RecordN(v float64, n int)
- func (h *Histogram) Reset()
- func (h *Histogram) Transfer(src *Histogram)
- type HistogramData
- type Interval
- type Occurrence
- type Percentile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParsePercentiles ¶ added in v0.3.7
ParsePercentiles extracts the percentiles from string (flag).
func RoundToDigits ¶ added in v0.5.0
RoundToDigits rounds the input to digits number of digits after decimal point. Note this incorrectly rounds the last digit of negative numbers.
Types ¶
type Bucket ¶ added in v0.3.7
type Bucket struct { Interval Percent float64 // Cumulative percentile Count int64 // How many in this bucket }
Bucket is the data for 1 bucket: an Interval and the occurrence Count for that interval.
type Counter ¶
type Counter struct { Count int64 Min float64 Max float64 Sum float64 // contains filtered or unexported fields }
Counter is a type whose instances record values and calculate stats (count, average, min, max, and stddev).
type Histogram ¶
type Histogram struct { Counter Offset float64 // offset applied to data before fitting into buckets Divider float64 // divider applied to data before fitting into buckets // Don't access directly (outside of this package): Hdata []int32 // numValues buckets (one more than values, for last one) }
Histogram extends Counter and adds a histogram. Must be created using NewHistogram or anotherHistogram.Clone() and not directly.
func Merge ¶ added in v0.6.0
Merge two different histogram with different scale parameters Lowest offset and highest divider value will be selected on new Histogram as scale parameters.
func NewHistogram ¶
NewHistogram creates a new histogram (sets up the buckets). Divider value can not be zero, otherwise returns zero.
func (*Histogram) Export ¶ added in v0.3.7
func (h *Histogram) Export() *HistogramData
Export translate the internal representation of the histogram data in an externally usable one. Calculates the request Percentiles.
func (*Histogram) Print ¶
Print dumps the histogram (and counter) to the provided writer. Also calculates the percentiles. Use Export() once and Print if you are going to need the Export results too.
type HistogramData ¶ added in v0.3.7
type HistogramData struct { Count int64 Min float64 Max float64 Sum float64 Avg float64 StdDev float64 Data []Bucket Percentiles []Percentile `json:"Percentiles,omitempty"` }
HistogramData is the exported Histogram data, a sorted list of intervals covering [Min, Max]. Pure data, so Counter for instance is flattened.
func (*HistogramData) CalcPercentile ¶ added in v0.6.0
func (e *HistogramData) CalcPercentile(percentile float64) float64
CalcPercentile returns the value for an input percentile e.g., for 90. as input returns an estimate of the original value threshold where 90.0% of the data is below said threshold. with 3 data points 10, 20, 30; p0-p33.33 == 10, p 66.666 = 20, p100 = 30 p33.333 - p66.666 = linear between 10 and 20; so p50 = 15 TODO: consider spreading the count of the bucket evenly from start to end so the % grows by at least to 1/N on start of range, and for last range when start == end we should get to that % faster.
func (*HistogramData) CalcPercentiles ¶ added in v0.6.0
func (e *HistogramData) CalcPercentiles(percentiles []float64) *HistogramData
CalcPercentiles calculates the requested percentile and adds them to the HistogramData. Potential TODO: sort or assume sorting and calculate all the percentiles in 1 pass (greater and greater values).
type Interval ¶ added in v0.3.7
Interval is a range from start to end. Interval are left closed, open right expect the last one which includes Max. i.e., [Start, End] with the next one being [PrevEnd, NextEnd].
type Occurrence ¶ added in v1.35.0
type Occurrence struct {
// contains filtered or unexported fields
}
Occurrence is a type that stores the occurrences of the keys. Could be directly an alias for map[string]int but keeping the outer struct for parity with Counter and Histogram and to keep 1.38's API.
func NewOccurrence ¶ added in v1.35.0
func NewOccurrence() *Occurrence
NewOccurrence create a new occurrence (map).
func (*Occurrence) AggregateAndToString ¶ added in v1.39.0
func (o *Occurrence) AggregateAndToString(totals map[string]int) string
AggregateAndToString aggregates the data from the object into the passed in totals map and returns a string suitable for printing usage counts per key of the incoming object.
func (*Occurrence) Record ¶ added in v1.35.0
func (o *Occurrence) Record(key string)
Record records a new occurrence of the key.
type Percentile ¶ added in v0.3.7
type Percentile struct { Percentile float64 // For this Percentile Value float64 // value at that Percentile }
Percentile value for the percentile.