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
impl SparseHistogram
Sourcepub fn new(grouping_power: u8, max_value_power: u8) -> Result<Self, Error>
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.
Sourcepub fn with_config(config: &Config) -> Self
pub fn with_config(config: &Config) -> Self
Creates a new histogram using a provided crate::Config
.
Sourcepub fn wrapping_add(
&self,
h: &SparseHistogram,
) -> Result<SparseHistogram, Error>
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.
Sourcepub fn checked_sub(&self, h: &SparseHistogram) -> Result<SparseHistogram, Error>
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.
Sourcepub fn percentiles(
&self,
percentiles: &[f64],
) -> Result<Option<Vec<(f64, Bucket)>>, Error>
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.
Sourcepub fn percentile(&self, percentile: f64) -> Result<Option<Bucket>, Error>
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
.
Sourcepub fn downsample(&self, grouping_power: u8) -> Result<SparseHistogram, Error>
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
impl Clone for SparseHistogram
Source§fn clone(&self) -> SparseHistogram
fn clone(&self) -> SparseHistogram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more