measure

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package measure holds the harness's measurement primitives: a mergeable latency histogram, named time series and growth slopes. It is a leaf package with no dependencies outside the standard library.

Index

Constants

View Source
const (

	// MinTrackable and MaxTrackable bound the range the buckets resolve.
	// Values outside it are counted in the bucket of MinTrackable or
	// MaxTrackable; Min and Max still report the true extremes.
	MinTrackable = time.Microsecond
	// MaxTrackable is the highest bucketed value; see MinTrackable.
	MaxTrackable = 24 * time.Hour
)

Variables

This section is empty.

Functions

func Slope

func Slope(points []Point, from time.Time) (perHour, r2 float64)

Slope fits an ordinary least squares line of V against hours since the earliest included point, over the points with T >= from, and returns the slope in units per hour and the coefficient of determination r2 in [0, 1].

It returns (0, 0) when fewer than two points are included or every included point shares one timestamp. When every included V is equal the slope is 0 and r2 is defined as 0: there is no variance for the line to explain, so a flat series must not read as a strong trend.

Types

type Histogram

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

Histogram is a log-linear latency histogram over 1 µs to 24 h with at most 1% relative error on quantiles. The zero value is an empty histogram ready for use. Record is safe for concurrent use and lock-free.

Count, Quantile, Min, Max, Mean and Marshal may be called while Record runs and see an approximate snapshot, suitable for monitoring. Merge and Unmarshal are for use after recording has stopped. Merging into h while h is recorded into is safe; merging from a histogram that is still being recorded into may miss in-flight records.

func NewHistogram

func NewHistogram() *Histogram

NewHistogram returns an empty histogram.

func (*Histogram) Count

func (h *Histogram) Count() int64

Count returns the number of recorded observations.

func (*Histogram) MarshalJSON

func (h *Histogram) MarshalJSON() ([]byte, error)

MarshalJSON writes the count, sum, extremes and non-empty buckets.

func (*Histogram) Max

func (h *Histogram) Max() time.Duration

Max returns the largest recorded duration, or 0 for an empty histogram.

func (*Histogram) Mean

func (h *Histogram) Mean() time.Duration

Mean returns the exact arithmetic mean, or 0 for an empty histogram.

func (*Histogram) Merge

func (h *Histogram) Merge(o *Histogram)

Merge adds o's observations to h. A nil or empty o is a no-op.

func (*Histogram) Min

func (h *Histogram) Min() time.Duration

Min returns the smallest recorded duration, or 0 for an empty histogram.

func (*Histogram) Quantile

func (h *Histogram) Quantile(q float64) time.Duration

Quantile returns the q-quantile (0 <= q <= 1) as the midpoint of the bucket holding that rank, clamped to the observed [Min, Max]. Quantile(0) is Min, Quantile(1) is Max, and an empty histogram returns 0. A q outside [0, 1] or NaN is treated as the nearest end.

func (*Histogram) Record

func (h *Histogram) Record(d time.Duration)

Record adds one observation. A negative duration is recorded as zero.

func (*Histogram) UnmarshalJSON

func (h *Histogram) UnmarshalJSON(b []byte) error

UnmarshalJSON replaces h's contents with the decoded histogram. It must not race with Record.

type Point

type Point struct {
	T time.Time `json:"t"`
	V float64   `json:"v"`
}

Point is one sample of a series.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder collects samples into named series. The zero value is ready for use and Add is safe for concurrent use.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns an empty recorder.

func (*Recorder) Add

func (r *Recorder) Add(name, unit string, t time.Time, v float64)

Add appends a sample to the named series, creating it on first use. The series' unit is fixed by its first Add; later units for the same name are ignored. Samples are kept in call order. A NaN or infinite value is dropped, because JSON cannot represent it and it would make run.json unwritable.

func (*Recorder) Series

func (r *Recorder) Series() []Series

Series returns a deep copy of every series, sorted by name.

type Series

type Series struct {
	Name   string  `json:"name"`
	Unit   string  `json:"unit"`
	Points []Point `json:"points"`
}

Series is a named, ordered sequence of samples with a display unit.

Jump to

Keyboard shortcuts

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