Skip to main content

Histogram

Struct Histogram 

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

Histogram for tracking value distributions.

Uses power-of-two bucket boundaries for efficient indexing. Bucket boundaries: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, inf

§Example

use reovim_kernel::debug::Histogram;

static RESPONSE_TIMES: Histogram = Histogram::new();

fn handle_request() {
    let start = std::time::Instant::now();
    // ... handle request ...
    RESPONSE_TIMES.record(start.elapsed().as_micros() as u64);
}

Implementations§

Source§

impl Histogram

Source

pub const fn new() -> Self

Create a new histogram.

Source

pub fn record(&self, value: u64)

Record a value in the histogram.

Value 0 goes to bucket 0. Values 1-1 go to bucket 1 (2^0). Values 2-3 go to bucket 2 (2^1). And so on…

Source

pub fn mean(&self) -> f64

Get the mean value of all recorded samples.

Source

pub fn count(&self) -> u64

Get the total count of recorded samples.

Source

pub fn sum(&self) -> u64

Get the sum of all recorded values.

Source

pub fn buckets(&self) -> [u64; 16]

Get bucket counts.

Source

pub fn reset(&self)

Reset all histogram data.

Trait Implementations§

Source§

impl Default for Histogram

Source§

fn default() -> Self

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

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