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
- func Slope(points []Point, from time.Time) (perHour, r2 float64)
- type Histogram
- func (h *Histogram) Count() int64
- func (h *Histogram) MarshalJSON() ([]byte, error)
- func (h *Histogram) Max() time.Duration
- func (h *Histogram) Mean() time.Duration
- func (h *Histogram) Merge(o *Histogram)
- func (h *Histogram) Min() time.Duration
- func (h *Histogram) Quantile(q float64) time.Duration
- func (h *Histogram) Record(d time.Duration)
- func (h *Histogram) UnmarshalJSON(b []byte) error
- type Point
- type Recorder
- type Series
Constants ¶
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 ¶
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 (*Histogram) MarshalJSON ¶
MarshalJSON writes the count, sum, extremes and non-empty buckets.
func (*Histogram) Quantile ¶
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) UnmarshalJSON ¶
UnmarshalJSON replaces h's contents with the decoded histogram. It must not race with Record.
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 (*Recorder) Add ¶
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.