fortio: fortio.org/fortio/stats Index | Files

package stats

import "fortio.org/fortio/stats"

Index

Package Files

stats.go

func ParsePercentiles Uses

func ParsePercentiles(percentiles string) ([]float64, error)

ParsePercentiles extracts the percentiles from string (flag).

func Round Uses

func Round(v float64) float64

Round rounds to 4 digits after the decimal point.

func RoundToDigits Uses

func RoundToDigits(v float64, digits int) float64

RoundToDigits rounds the input to digits number of digits after decimal point. Note this incorrectly rounds the last digit of negative numbers.

type Bucket Uses

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 Uses

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,stddev).

func (*Counter) Avg Uses

func (c *Counter) Avg() float64

Avg returns the average.

func (*Counter) Log Uses

func (c *Counter) Log(msg string)

Log outputs the stats to the logger.

func (*Counter) Print Uses

func (c *Counter) Print(out io.Writer, msg string)

Print prints stats.

func (*Counter) Record Uses

func (c *Counter) Record(v float64)

Record records a data point.

func (*Counter) RecordN Uses

func (c *Counter) RecordN(v float64, n int)

RecordN efficiently records the same value N times

func (*Counter) Reset Uses

func (c *Counter) Reset()

Reset clears the counter to reset it to original 'no data' state.

func (*Counter) StdDev Uses

func (c *Counter) StdDev() float64

StdDev returns the standard deviation.

func (*Counter) Transfer Uses

func (c *Counter) Transfer(src *Counter)

Transfer merges the data from src into this Counter and clears src.

type Histogram Uses

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 an histogram. Must be created using NewHistogram or anotherHistogram.Clone() and not directly.

func Merge Uses

func Merge(h1 *Histogram, h2 *Histogram) *Histogram

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 Uses

func NewHistogram(Offset float64, Divider float64) *Histogram

NewHistogram creates a new histogram (sets up the buckets). Divider value can not be zero, otherwise returns zero

func (*Histogram) Clone Uses

func (h *Histogram) Clone() *Histogram

Clone returns a copy of the histogram.

func (*Histogram) CopyFrom Uses

func (h *Histogram) CopyFrom(src *Histogram)

CopyFrom sets the content of this object to a copy of the src.

func (*Histogram) Export Uses

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) Log Uses

func (h *Histogram) Log(msg string, percentiles []float64)

Log Logs the histogram to the counter.

func (*Histogram) Print Uses

func (h *Histogram) Print(out io.Writer, msg string, percentiles []float64)

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.

func (*Histogram) Record Uses

func (h *Histogram) Record(v float64)

Record records a data point.

func (*Histogram) RecordN Uses

func (h *Histogram) RecordN(v float64, n int)

RecordN efficiently records a data point N times.

func (*Histogram) Reset Uses

func (h *Histogram) Reset()

Reset clears the data. Reset it to NewHistogram state.

func (*Histogram) Transfer Uses

func (h *Histogram) Transfer(src *Histogram)

Transfer merges the data from src into this Histogram and clears src.

type HistogramData Uses

type HistogramData struct {
    Count       int64
    Min         float64
    Max         float64
    Sum         float64
    Avg         float64
    StdDev      float64
    Data        []Bucket
    Percentiles []Percentile
}

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 Uses

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 Uses

func (e *HistogramData) CalcPercentiles(percentiles []float64) *HistogramData

CalcPercentiles calculates the requested percentile and add them to the HistogramData. Potential TODO: sort or assume sorting and calculate all the percentiles in 1 pass (greater and greater values).

func (*HistogramData) Print Uses

func (e *HistogramData) Print(out io.Writer, msg string)

Print dumps the histogram (and counter) to the provided writer. Also calculates the percentile.

type Interval Uses

type Interval struct {
    Start float64
    End   float64
}

Interval is a range from start to end. Interval are left closed, open right expect the last one which includes Max. ie [Start, End[ with the next one being [PrevEnd, NextEnd[.

type Percentile Uses

type Percentile struct {
    Percentile float64 // For this Percentile
    Value      float64 // value at that Percentile
}

Percentile value for the percentile

Package stats imports 9 packages (graph) and is imported by 10 packages. Updated 2018-09-12. Refresh now. Tools for package owners.