Struct SparseHistogram

Source
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 checked_sub(&self, h: &SparseHistogram) -> Result<SparseHistogram, Error>

Subtracts the other histogram to this histogram and returns the result as a new histogram. The other histogram is expected to be a subset of the current histogram, i.e., for every bucket in the other histogram should have a count less than or equal to the corresponding bucket in this histogram.

An error is returned if the two histograms have incompatible parameters or if the other histogram is not a subset of this histogram.

Source

pub fn percentiles( &self, percentiles: &[f64], ) -> Result<Option<Vec<(f64, Bucket)>>, Error>

Return a collection of percentiles from this histogram.

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

The results will be sorted by the percentile.

Source

pub fn percentile(&self, percentile: f64) -> Result<Option<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<&SparseHistogram> for Histogram

Source§

fn from(other: &SparseHistogram) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a SparseHistogram

Source§

type Item = Bucket

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'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
Source§

impl PartialEq for SparseHistogram

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.