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: u64Total number of samples.
sum: u64Saturating sum of every sample (used by Self::mean).
min: u64Smallest sample, u64::MAX while the histogram is empty.
max: u64Largest sample, 0 while the histogram is empty.
Implementations§
Source§impl ExitLatencyHistogram
impl ExitLatencyHistogram
Sourcepub const fn bucket_for(sample: u64) -> usize
pub const fn bucket_for(sample: u64) -> usize
Returns the bucket index for sample.
0maps to bucket 0;1maps to bucket 1,2..=3to bucket 2,4..=7to bucket 3, and so on (2^(k-1) .. 2^kmaps to bucketk);- every sample that would fall beyond the last bucket is clamped into
it, so this function never returns a value
>= EXIT_LATENCY_BUCKETS.
Sourcepub const fn bucket_lower_bound(index: usize) -> u64
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.
Sourcepub const fn bucket_upper_bound(index: usize) -> u64
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.
Sourcepub fn record(&mut self, sample: u64)
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.
Sourcepub const fn min(&self) -> Option<u64>
pub const fn min(&self) -> Option<u64>
Smallest recorded sample, or None if the histogram is empty.
Sourcepub const fn max(&self) -> Option<u64>
pub const fn max(&self) -> Option<u64>
Largest recorded sample, or None if the histogram is empty.
Sourcepub const fn mean(&self) -> Option<u64>
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).
Sourcepub fn bucket_count(&self, index: usize) -> u64
pub fn bucket_count(&self, index: usize) -> u64
Population of index, or 0 for an invalid index.
Sourcepub fn percentile(&self, p: u8) -> Option<u64>
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.
Trait Implementations§
Source§impl Clone for ExitLatencyHistogram
impl Clone for ExitLatencyHistogram
impl Copy for ExitLatencyHistogram
Source§impl Debug for ExitLatencyHistogram
impl Debug for ExitLatencyHistogram
Source§impl Default for ExitLatencyHistogram
impl Default for ExitLatencyHistogram
impl Eq for ExitLatencyHistogram
Source§impl PartialEq for ExitLatencyHistogram
impl PartialEq for ExitLatencyHistogram
impl StructuralPartialEq for ExitLatencyHistogram
Auto Trait Implementations§
impl Forget for ExitLatencyHistogram
impl Freeze for ExitLatencyHistogram
impl Move for ExitLatencyHistogram
impl RefUnwindSafe for ExitLatencyHistogram
impl Send for ExitLatencyHistogram
impl Sync for ExitLatencyHistogram
impl Unpin for ExitLatencyHistogram
impl UnsafeUnpin for ExitLatencyHistogram
impl UnwindSafe for ExitLatencyHistogram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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