github.com/ethereum/go-ethereum@v1.16.1/metrics/histogram.go (about) 1 package metrics 2 3 type HistogramSnapshot interface { 4 Count() int64 5 Max() int64 6 Mean() float64 7 Min() int64 8 Percentile(float64) float64 9 Percentiles([]float64) []float64 10 Size() int 11 StdDev() float64 12 Sum() int64 13 Variance() float64 14 } 15 16 // Histogram calculates distribution statistics from a series of int64 values. 17 type Histogram interface { 18 Clear() 19 Update(int64) 20 Snapshot() HistogramSnapshot 21 } 22 23 // GetOrRegisterHistogram returns an existing Histogram or constructs and 24 // registers a new StandardHistogram. 25 func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram { 26 return getOrRegister(name, func() Histogram { return NewHistogram(s) }, r) 27 } 28 29 // GetOrRegisterHistogramLazy returns an existing Histogram or constructs and 30 // registers a new StandardHistogram. 31 func GetOrRegisterHistogramLazy(name string, r Registry, s func() Sample) Histogram { 32 return getOrRegister(name, func() Histogram { return NewHistogram(s()) }, r) 33 } 34 35 // NewHistogram constructs a new StandardHistogram from a Sample. 36 func NewHistogram(s Sample) Histogram { 37 return &StandardHistogram{s} 38 } 39 40 // NewRegisteredHistogram constructs and registers a new StandardHistogram from 41 // a Sample. 42 func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram { 43 c := NewHistogram(s) 44 if nil == r { 45 r = DefaultRegistry 46 } 47 r.Register(name, c) 48 return c 49 } 50 51 // StandardHistogram is the standard implementation of a Histogram and uses a 52 // Sample to bound its memory use. 53 type StandardHistogram struct { 54 sample Sample 55 } 56 57 // Clear clears the histogram and its sample. 58 func (h *StandardHistogram) Clear() { h.sample.Clear() } 59 60 // Snapshot returns a read-only copy of the histogram. 61 func (h *StandardHistogram) Snapshot() HistogramSnapshot { 62 return h.sample.Snapshot() 63 } 64 65 // Update samples a new value. 66 func (h *StandardHistogram) Update(v int64) { h.sample.Update(v) }