Skip to main content

ExitLatencyHistogram

Struct ExitLatencyHistogram 

Source
pub struct ExitLatencyHistogram {
    buckets: [u64; 32],
    count: u64,
    sum: u64,
    min: u64,
    max: u64,
}
Expand description

Fixed-memory histogram of exit latencies.

The histogram keeps enough state to report the count, minimum, maximum, mean and a conservative percentile without storing the samples. This is what a hot path can afford: one comparison chain and a few integer operations per exit, no allocation and no lock.

Fields§

§buckets: [u64; 32]

Number of samples per bucket.

§count: u64

Total number of samples.

§sum: u64

Saturating sum of every sample (used by Self::mean).

§min: u64

Smallest sample, u64::MAX while the histogram is empty.

§max: u64

Largest sample, 0 while the histogram is empty.

Implementations§

Source§

impl ExitLatencyHistogram

Source

pub const fn new() -> Self

Creates an empty histogram.

Source

pub const fn bucket_for(sample: u64) -> usize

Returns the bucket index for sample.

  • 0 maps to bucket 0;
  • 1 maps to bucket 1, 2..=3 to bucket 2, 4..=7 to bucket 3, and so on (2^(k-1) .. 2^k maps to bucket k);
  • every sample that would fall beyond the last bucket is clamped into it, so this function never returns a value >= EXIT_LATENCY_BUCKETS.
Source

pub const fn bucket_lower_bound(index: usize) -> u64

Lower bound (inclusive) of index, or u64::MAX for an invalid index.

Bucket 0 has a lower bound of 0; bucket k >= 1 starts at 2^(k-1). The last bucket starts at 2^(EXIT_LATENCY_BUCKETS - 2) and is open-ended.

Source

pub const fn bucket_upper_bound(index: usize) -> u64

Upper bound (exclusive) of index as an integer, or u64::MAX for an invalid index.

Bucket 0 holds only 0, so its upper bound is 1. The last bucket is open-ended (it also absorbs every sample that would fall beyond it), so its reported upper bound is u64::MAX.

Source

pub fn record(&mut self, sample: u64)

Records one sample.

The bucket population, the count and the sum saturate; the minimum and the maximum are exact.

Source

pub const fn count(&self) -> u64

Number of recorded samples.

Source

pub const fn sum(&self) -> u64

Total (saturating) sum of the recorded samples.

Source

pub const fn min(&self) -> Option<u64>

Smallest recorded sample, or None if the histogram is empty.

Source

pub const fn max(&self) -> Option<u64>

Largest recorded sample, or None if the histogram is empty.

Source

pub const fn mean(&self) -> Option<u64>

Integer mean of the recorded samples, or None if the histogram is empty.

The division truncates towards zero. If the sum saturated, the mean is a lower bound of the true mean (documented, never a panic).

Source

pub fn bucket_count(&self, index: usize) -> u64

Population of index, or 0 for an invalid index.

Source

pub fn percentile(&self, p: u8) -> Option<u64>

Conservative percentile of the distribution.

p is clamped to 0..=100. The returned value is the upper bound of the bucket that contains the nearest-rank sample, not an exact sample: it is therefore always greater than or equal to the exact percentile, and it is expressed in the same unit as the samples. This keeps the histogram allocation-free; a caller that needs exact percentiles must keep the raw samples elsewhere.

p = 0 returns the upper bound of the first non-empty bucket (the lowest latency bucket in use), never a panic. An empty histogram returns None.

Source

pub fn reset(&mut self)

Resets the histogram to its initial (empty) state.

Trait Implementations§

Source§

impl Clone for ExitLatencyHistogram

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ExitLatencyHistogram

Source§

impl Debug for ExitLatencyHistogram

Source§

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

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

impl Default for ExitLatencyHistogram

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ExitLatencyHistogram

Source§

impl PartialEq for ExitLatencyHistogram

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ExitLatencyHistogram

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.