Struct histogram::Histogram

source ·
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

source

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 resolution M = 2^m. This is the smallest unit of quantification, which is also the smallest bucket width. If the input values are always integers, choosing m=0 would ensure precise recording for the smallest values.

  • r - sets the minimum resolution range R = 2^r - 1. The selected value must be greater than the minimum resolution m. This sets the maximum value that the minimum resolution should extend to.

  • n - sets the maximum value N = 2^n - 1. The selected value must be greater than or equal to the minimum resolution range r.

Panics

This will panic if an invalid configuration is specified.

source

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.

source

pub fn clear(&self)

Resets the Histogram by zeroing out the count for every bucket.

source

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.

source

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.

source

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.

source

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.

source

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 Histograms.

source

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 Histograms.

source

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 Histograms.

source

pub fn buckets(&self) -> usize

Trait Implementations§

source§

impl Clone for Histogram

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> IntoIterator for &'a Histogram

§

type Item = Bucket

The type of the elements being iterated over.
§

type IntoIter = HistogramIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.