pub struct Histogram { /* private fields */ }
Expand description
A Histogram
groups recorded values into buckets of similar values and
tracks counts for recorded values that fall into those ranges.
Implementations§
source§impl Histogram
impl Histogram
sourcepub fn new(m: u32, r: u32, n: u32) -> Result<Self, Error>
pub fn new(m: u32, r: u32, n: u32) -> Result<Self, Error>
Construct a new histogram by providing the configuration directly.
-
m
- sets the minimum resolutionM = 2^m
. This is the smallest unit of quantification, which is also the smallest bucket width. If the input values are always integers, choosingm=0
would ensure precise recording for the smallest values. -
r
- sets the minimum resolution rangeR = 2^r - 1
. The selected value must be greater than the minimum resolutionm
. This sets the maximum value that the minimum resolution should extend to. -
n
- sets the maximum valueN = 2^n - 1
. The selected value must be greater than or equal to the minimum resolution ranger
.
Panics
This will panic if an invalid configuration is specified.
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Creates a Builder
with the default values m = 0
, r = 10
, n = 30
.
This would create a Histogram
with 11264 buckets which can store
values from 1 to 1_073_741_823 with values 1 to 1023 being stored in
buckets with a width of 1. Such a Histogram
would be appropriate for
latencies measured in nanoseconds where the max expected latency is one
second.
sourcepub fn increment(&self, value: u64, count: u32) -> Result<(), Error>
pub fn increment(&self, value: u64, count: u32) -> Result<(), Error>
Increment the histogram bucket corresponding to the provided value
by
the provided count
.
This operation wraps on overflow.
sourcepub fn decrement(&self, value: u64, count: u32) -> Result<(), Error>
pub fn decrement(&self, value: u64, count: u32) -> Result<(), Error>
Decrement the histogram bucket corresponding to the provided value
by
the provided count
.
This operation wraps on overflow.
sourcepub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>
pub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>
Retrieve the Bucket
which corresponds to the provided percentile.
An error will be returned if the percentile is invalid or if there are
no samples in the Histogram
.
Note: if you are reporting on multiple percentiles, it is more efficient
to use the percentiles
function to retrieve multiple percentiles in a
single call.
sourcepub fn percentiles(&self, percentiles: &[f64]) -> Result<Vec<Percentile>, Error>
pub fn percentiles(&self, percentiles: &[f64]) -> Result<Vec<Percentile>, Error>
Returns a set of percentiles in a single and efficient bulk operation. Note that the returned percentiles will be sorted from lowest to highest in the result, even if they do not appear in that order in the provided set of requested percentiles.
sourcepub fn merge(&self, other: &Self) -> Result<(), Error>
pub fn merge(&self, other: &Self) -> Result<(), Error>
Merges counts from the other Histogram
into this Histogram
. Returns
an error if there are differences in the configurations of both
Histogram
s.
sourcepub fn subtract(&self, other: &Self) -> Result<(), Error>
pub fn subtract(&self, other: &Self) -> Result<(), Error>
Subtracts the other Histogram
from this Histogram
. Returns an error
if there are differences in the configurations of both Histogram
s.
sourcepub fn subtract_and_clear(&self, other: &Self) -> Result<(), Error>
pub fn subtract_and_clear(&self, other: &Self) -> Result<(), Error>
Subtracts the other Histogram
from this Histogram
and clears the
other Histogram
. Returns an error if there are differences in the
configurations of both Histogram
s.