Skip to main content

Timer

Struct Timer 

Source
pub struct Timer { /* private fields */ }

Implementations§

Source§

impl Timer

Source

pub fn new(labels: Labels) -> Self

Source

pub fn with_sigdigs(labels: Labels, sigdigs: u8) -> Self

Construct a Timer with explicit HDR significant-digits precision. Use this from a call site that already knows the desired precision.

Source

pub fn with_sigdigs_from(labels: Labels, component: &Component) -> Self

Construct a Timer whose underlying histogram uses the HDR significant-digits precision configured on the nearest ancestor of component that declares crate::instruments::histogram::HDR_SIGDIGS_PROP. Falls back to the default if no ancestor declares it. SRD 40 §“HDR significant digits — subtree-scoped setting”.

Source

pub fn record(&self, duration_nanos: u64)

Record a duration in nanoseconds. If the live-window ring has been activated via Self::enable_live_window it receives the sample too — otherwise the cold path is a single atomic load + null check.

Source

pub fn snapshot(&self) -> TimerSnapshot

Snapshot: returns the delta histogram and the current count.

The count returned is the absolute total (not delta) — reporters compute deltas by comparing with their previous snapshot.

Source

pub fn peek_snapshot(&self) -> TimerSnapshot

Non-draining snapshot — clones the histogram without resetting it. Use for “live read-through” consumers (e.g., the now() path in the windowed metrics layer) that shouldn’t steal data from the next snapshot(). See Histogram::peek_snapshot.

Source

pub fn enable_live_window( &self, config: LiveWindowConfig, ) -> Arc<LiveWindowHistogram> ⓘ

Explicitly activate the sliding-window live view with a non-default config. Idempotent — second and subsequent calls return the existing ring, ignoring the passed config.

Callers who are happy with LiveWindowConfig::default do not need to call this — Self::peek_live_window auto-activates with defaults on first use. This method is only for callers that want tighter bounds, a different window size, or more slots before the first peek fires.

Source

pub fn peek_live_window(&self) -> HdrHistogram<u64>

Peek the sliding-window view. Auto-activates the ring with LiveWindowConfig::default on first call — subsequent calls just read.

Cost model:

  • Before the first peek ever: zero hot-path overhead on record (the OnceLock is empty, the record path branches past it).
  • Starting with the first peek: every subsequent record on this Timer writes to the ring too (+~63 ns per record at default config; see the live_window/record_enabled bench).

Returns the full rolling window merged into a fresh HDR histogram. Empty on the very first call (ring just created, no records captured yet).

Source

pub fn live_window_active(&self) -> bool

True when the live-window ring has been activated (either explicitly via Self::enable_live_window or lazily via a first Self::peek_live_window call). Useful for diagnostics / benches — does not trigger activation.

Source

pub fn live_window(&self) -> Option<Arc<LiveWindowHistogram>>

Direct access to the live-window ring if it’s already active. Unlike Self::peek_live_window, does NOT lazily activate — returns None if nothing has peeked yet. Useful for callers that want to read the ring’s config / len() without triggering activation.

Source

pub fn count(&self) -> u64

Current total count (without snapshotting).

Source

pub fn labels(&self) -> &Labels

Auto Trait Implementations§

§

impl !Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnsafeUnpin for Timer

§

impl UnwindSafe for Timer

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.