Struct Histogram

Source
pub struct Histogram { /* private fields */ }
Expand description

Instance of a Histogram.

Implementations§

Source§

impl Histogram

Source

pub fn init( lowest_trackable_value: u64, highest_trackable_value: u64, significant_figures: u32, ) -> Result<Histogram>

Create a new Histogram instance. lowest_trackable_value..highest_trackable_value defines the range of values in the Histogram. lowest_trackable_value must be >= 1. significant_figures defines the precision, and must be in the range 1..5.

HistogramErr is the catch-all failure case. It doesn’t report much detail because the underlying library doesn’t.

§Example
let mut h = Histogram::init(1, 100000, 2).unwrap();
h.record_value(10);  // record a single count of '10'
Source

pub fn reset(&mut self)

Zero all histogram state in place.

Source

pub fn record_value(&mut self, value: u64) -> bool

Record a specific value. Returns true if successful.

h.record_value(5);
assert_eq!(h.total_count(), 1);
Source

pub fn record_values(&mut self, value: u64, count: u64) -> bool

Record multiple counts of a specific value. Returns true if successful.

h.record_values(5, 10);
assert_eq!(h.total_count(), 10);
Source

pub fn record_corrected_value( &mut self, value: u64, expected_interval: u64, ) -> bool

Record a value, correcting for coordinated omission. This should be used when accumulating latency measurements taked on a regular timebase (expected_interval). Any latency that’s well above that interval implies some kind of outage in which sampled were lost. This corrects for those lost samples to preserve the integrity of the overall statistics.

Source

pub fn record_corrected_values( &mut self, value: u64, count: u64, expected_interval: u64, ) -> bool

As with record_corrected_value() but multiple counts of the value.

Source

pub fn add(&mut self, other: &Histogram) -> u64

Sum two histograms, modifying self in place. Returns the number of samples dropped; samples will be dropped if they’re out of the range lowest_trackable_value .. highest_trackable_value.

Source

pub fn add_while_correcting_for_coordinated_omission( &mut self, other: &Histogram, expected_interval: u64, ) -> u64

As with add but corrects of potential lost samples while doing periodic latency measurements, as in record_corrected_value. Only one correction should be applied.

Source

pub fn total_count(&self) -> u64

Total of all counters

Source

pub fn min(&self) -> u64

Smallest recorded value.

h.record_value(1);
h.record_value(5);
assert_eq!(h.min(), 1);
Source

pub fn max(&self) -> u64

Largest recorded value.

h.record_value(1);
h.record_value(5);
assert_eq!(h.max(), 5);
Source

pub fn value_at_percentile(&self, percentile: f64) -> u64

Value at a particular percentile (0-100).

h.record_values(20, 10);
h.record_value(40);
assert_eq!(h.value_at_percentile(50.0), 20);
assert_eq!(h.value_at_percentile(99.0), 40);
Source

pub fn stddev(&self) -> f64

Standard deviation of values.

Source

pub fn mean(&self) -> f64

Mean of values.

Source

pub fn values_are_equivalent(&self, a: u64, b: u64) -> bool

Returns true if two values are the same according to the lowest, highest and significant figures parameters.

Source

pub fn lowest_equivalent_value(&self, value: u64) -> u64

Lowest value equivalent to the given value.

Source

pub fn count_at_value(&self, value: u64) -> u64

Count for a specific value.

Source

pub fn linear_iter<'a>(&'a self, value_units_per_bucket: u64) -> LinearIter<'a>

Linear iterator over values. Results are returned in equally weighted buckets.

let mut h = Histogram::init(1, 100000, 3).unwrap();
for i in 1..100 { h.record_values(i, i); }
for (i, c) in h.linear_iter(1).enumerate() {    // 100 buckets
    println!("bucket {} = {}", i, c.count_added_in_this_iteration_step);
}
Source

pub fn log_iter<'a>( &'a self, value_units_per_bucket: u64, log_base: f64, ) -> LogIter<'a>

Logarithmic iterator over values. Results are returned in logarithmically weighted buckets.

Source

pub fn recorded_iter<'a>(&'a self) -> RecordedIter<'a>

Iterator over recorded values.

Source

pub fn percentile_iter<'a>( &'a self, ticks_per_half_distance: u32, ) -> PercentileIter<'a>

Iterator over percentiles.

Source

pub fn encode(&self) -> Result<String>

Encode Histogram state into a Base64 encoded string.

Source

pub fn decode(base64: &String) -> Result<Histogram>

Decode Histogram state from a Base64 string generated by encode.

Trait Implementations§

Source§

impl Clone for Histogram

Source§

fn clone(&self) -> Self

Returns a duplicate 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 Drop for Histogram

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Histogram

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.