metrics

package
v0.0.0-...-d6cb97c Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Histogram

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

Histogram is a shameless and low-rent knock of the chromium project's histogram:

https://chromium.googlesource.com/chromium/src/base/+/master/metrics/histogram.h

It logically stores a running histogram of uint64 values and shares some important features of its inspiration:

  • It acccepts a correctness deficit in return for not needing to lock. IOW, concurrent calls to Sample may clobber each other.
  • It trades compactness and ease of arithmatic across histograms for precision. Samples lose precision up to the range of the values which are stored in a bucket

Only implemented: Log2-based histogram

func NewByteHistogram

func NewByteHistogram() Histogram

NewByteHistogram stringifies values using humanize over byte values

func NewTimeHistogram

func NewTimeHistogram() Histogram

func (*Histogram) Add

func (h *Histogram) Add(other Histogram)

Add returns a new Histogram which is the result of adding this and other bucket-wise.

func (Histogram) Delta

func (h Histogram) Delta(other Histogram) Histogram

Delta returns a new Histogram which is the result of subtracting other from this bucket-wise. The intent is to capture changes in the state of histogram which is collecting samples over some time period. It will panic if any bucket from other is larger than the corresponding bucket in this.

func (Histogram) Mean

func (h Histogram) Mean() uint64

Mean returns 0 if there are no samples, and h.Sum()/h.Samples otherwise.

func (Histogram) Report

func (h Histogram) Report() string

Report returns an ASCII graph of the non-zero range of normalized buckets. IOW, it returns a basic graph of the histogram

func (*Histogram) Sample

func (h *Histogram) Sample(v uint64)

Sample adds a uint64 data point to the histogram

func (*Histogram) SampleLen

func (h *Histogram) SampleLen(l int)

SampleLen is a convenience wrapper around Sample which internally type asserts the int to a uint64

func (*Histogram) SampleTimeSince

func (h *Histogram) SampleTimeSince(t time.Time)

SampleTimeSince is a convenience wrapper around Sample which takes the duration since |t|, if 0, rounds to 1 and passes to Sample() as an uint64 number of nanoseconds.

func (Histogram) Samples

func (h Histogram) Samples() uint64

Samples returns the number of samples contained in the histogram

func (Histogram) String

func (h Histogram) String() string

func (Histogram) Sum

func (h Histogram) Sum() uint64

Sum return the sum of sampled values, note that Sum can be overflowed without overflowing the histogram buckets.

type ToStringFunc

type ToStringFunc func(v uint64) string

Jump to

Keyboard shortcuts

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