pub struct SparseHistogram {
    pub config: Config,
    pub index: Vec<usize>,
    pub count: Vec<u64>,
}
Expand description

This histogram is a sparse, columnar representation of the regular Histogram. It is significantly smaller than a regular Histogram when a large number of buckets are zero, which is a frequent occurence. It stores an individual vector for each field of non-zero buckets. Assuming index[0] = n, (index[0], count[0]) corresponds to the nth bucket.

Fields§

§config: Config

parameters representing the resolution and the range of the histogram tracking request latencies

§index: Vec<usize>

indices for the non-zero buckets in the histogram

§count: Vec<u64>

histogram bucket counts corresponding to the indices

Implementations§

source§

impl SparseHistogram

source

pub fn new(grouping_power: u8, max_value_power: u8) -> Result<Self, Error>

Construct a new histogram from the provided parameters. See the documentation for crate::Config to understand their meaning.

source

pub fn with_config(config: &Config) -> Self

Creates a new histogram using a provided crate::Config.

source

pub fn wrapping_add( &self, h: &SparseHistogram ) -> Result<SparseHistogram, Error>

Adds the other histogram to this histogram and returns the result as a new histogram.

An error is returned if the two histograms have incompatible parameters. Buckets which have values in both histograms are allowed to wrap.

source

pub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>

Return a single percentile from this histogram.

The percentile should be in the inclusive range 0.0..=100.0. For example, the 50th percentile (median) can be found using 50.0.

source

pub fn downsample(&self, grouping_power: u8) -> Result<SparseHistogram, Error>

Returns a new histogram with a reduced grouping power. The reduced grouping power should lie in the range (0..existing grouping power).

This works by iterating over every bucket in the existing histogram and inserting the contained values into the new histogram. While we do not know the exact values of the data points (only that they lie within the bucket’s range), it does not matter since the bucket is not split during downsampling and any value can be used.

Trait Implementations§

source§

impl Clone for SparseHistogram

source§

fn clone(&self) -> SparseHistogram

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 Debug for SparseHistogram

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&Histogram> for SparseHistogram

source§

fn from(histogram: &Histogram) -> Self

Converts to this type from the input type.
source§

impl From<&Snapshot> for SparseHistogram

source§

fn from(snapshot: &Snapshot) -> Self

Converts to this type from the input type.
source§

impl PartialEq for SparseHistogram

source§

fn eq(&self, other: &SparseHistogram) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for SparseHistogram

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.