pub struct Timer { /* private fields */ }Implementations§
Source§impl Timer
impl Timer
pub fn new(labels: Labels) -> Self
Sourcepub fn with_sigdigs(labels: Labels, sigdigs: u8) -> Self
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.
Sourcepub fn with_sigdigs_from(labels: Labels, component: &Component) -> Self
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”.
Sourcepub fn record(&self, duration_nanos: u64)
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.
Sourcepub fn snapshot(&self) -> TimerSnapshot
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.
Sourcepub fn peek_snapshot(&self) -> TimerSnapshot
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.
Sourcepub fn enable_live_window(
&self,
config: LiveWindowConfig,
) -> Arc<LiveWindowHistogram> ⓘ
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.
Sourcepub fn peek_live_window(&self) -> HdrHistogram<u64>
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
recordon this Timer writes to the ring too (+~63 ns per record at default config; see thelive_window/record_enabledbench).
Returns the full rolling window merged into a fresh HDR histogram. Empty on the very first call (ring just created, no records captured yet).
Sourcepub fn live_window_active(&self) -> bool
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.
Sourcepub fn live_window(&self) -> Option<Arc<LiveWindowHistogram>>
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.