@std/data/histogram.ms#
Import each required symbol with import Name from "@std/data/histogram.ms".
Histogram Type#
A latency histogram. It records non-negative Int values, usually nanoseconds, in fixed
memory and answers count, extremes, mean and percentiles.
Values below 64 are exact. Larger values fall in buckets about 3% wide, so a percentile
is an upper bound within that error. A histogram has one owner; other promises send
their observations to that owner over a pipe.
Example: latency.time(() => handle(request)) records one span, and
latency.percentile(99.0) returns the value that 99% of observations do not exceed.
opaque type Histogram {
}Histogram.count#
Observations recorded so far.
fn count() IntHistogram.max#
Largest observation, or null when empty.
fn max() Int?Histogram.mean#
Mean of the observations, or 0.0 when empty. It is exact, not bucketed.
fn mean() FloatHistogram.min#
Smallest observation, or null when empty.
fn min() Int?Histogram.percentile#
Value at or below which p percent of observations fall, for p in 0.0 through
100.0; null when empty. The answer is the top of the matching bucket, never above
the largest observation. A p outside the range gives null.
fn percentile(p Float) Int?Histogram.record#
Adds one observation. A negative value is recorded as 0, so a clock that steps back counts as an instant measurement.
var fn record(value Int) VoidHistogram.record_duration#
Adds one duration as nanoseconds. A negative duration is recorded as 0, like
record.
var fn record_duration(elapsed Duration) VoidHistogram.reset#
Discards every observation and returns the histogram to its empty state.
var fn reset() VoidHistogram.time#
Runs work, records how long it took in nanoseconds on the monotonic clock, and
returns its result. A normal return, including an error Result, is recorded; a
fault or cancellation that prevents returning is not.
var fn time[T](work fn() T) Thistogram Function#
Creates an empty histogram.
fn histogram() Histogram { ... }