Skip to main content

Histogram

Struct Histogram 

Source
pub struct Histogram<V> {
    pub name: &'static str,
    pub unit: &'static str,
    pub description: &'static str,
    /* private fields */
}
Expand description

A histogram instrument with branchless base-2 exponential bucket pick.

32 buckets span [2^-10, 2^22) — roughly [0.001, 4_000_000). Values outside that range saturate to bucket 0 or bucket 31. V is the observed value type: f64 for latencies/sizes, u64 for counts.

v1 baseline: single bucket slab per instrument; tag identity is accepted for API symmetry but not accumulated. C9 will shard by attr-set.

Fields§

§name: &'static str§unit: &'static str§description: &'static str

Implementations§

Source§

impl<V> Histogram<V>

Source

pub const fn new(name: &'static str) -> Self

Source

pub const fn unit(self, unit: &'static str) -> Self

Source

pub const fn description(self, desc: &'static str) -> Self

Source

pub const fn exponential_base(self, base: f64) -> Self

Set the exponential base. Only 2.0 is supported for the branchless bucket pick; other bases will fall back to bucket 0.

Source

pub const fn exponential_min(self, min: f64) -> Self

Set the lower bound of bucket 0 (must be a power of 2 for the fast path).

Source

pub fn count(&self) -> u64

Return the total observation count.

Source

pub fn sum(&self) -> f64

Return the running sum as f64.

Source

pub fn bucket_snapshot(&self) -> [u64; 32]

Return a snapshot of per-bucket counts.

Source

pub fn snapshot_and_reset(&self) -> (u64, u64, [u64; 32])

Snapshot all state (count, sum_bits, bucket counts) and reset atomics to zero.

Called by the drainer at snapshot time. Each atomic is swapped to 0 — any observations racing the swap appear in the NEXT snapshot window (not lost).

Source§

impl Histogram<f64>

Source

pub fn record(&self, value: f64)

Record an f64 observation. Negative values are treated as their absolute magnitude for bucket assignment.

Source§

impl Histogram<u64>

Source

pub fn record(&self, value: u64)

Record a u64 observation (cast to f64 for bucket assignment).

Auto Trait Implementations§

§

impl<V> !Freeze for Histogram<V>

§

impl<V> RefUnwindSafe for Histogram<V>

§

impl<V> Send for Histogram<V>
where PhantomData<V>: Send,

§

impl<V> Sync for Histogram<V>
where PhantomData<V>: Sync,

§

impl<V> Unpin for Histogram<V>
where PhantomData<V>: Unpin,

§

impl<V> UnsafeUnpin for Histogram<V>

§

impl<V> UnwindSafe for Histogram<V>

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

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.