TimerMetrics

Struct TimerMetrics 

Source
pub struct TimerMetrics;
Expand description

TimerMetrics

Volatile counters for timer executions keyed by (mode, delay_ms, label).

§What this measures

TimerMetrics is intended to answer two related questions:

  1. Which timers have been scheduled?

    • Use [ensure] at scheduling time to guarantee the timer appears in snapshots, even if it has not fired yet (e.g., newly-created interval timers).
  2. How many times has a given timer fired?

    • Use [increment] when a timer fires (one-shot completion or interval tick).

Note that this type does count executions/ticks of interval timers. Scheduling counts are tracked separately (e.g., via SystemMetricKind::TimerScheduled), and instruction costs are tracked via perf counters, because scheduling and execution are different signals.

§Cardinality and labels

Labels are used as metric keys. Keep labels stable and low-cardinality (avoid embedding principals, IDs, or other high-variance values).

§Thread safety / runtime model

This uses thread_local! storage. On the IC, this is the standard way to maintain mutable global state without unsafe.

Implementations§

Source§

impl TimerMetrics

Source

pub fn ensure(mode: TimerMode, delay: Duration, label: &str)

Ensure a timer key exists in the metrics table with an initial count of 0.

This is used at schedule time to make timers visible in snapshots before they have fired (particularly important for interval timers).

Idempotent: calling ensure repeatedly for the same key does not change the count.

Source

pub fn increment(mode: TimerMode, delay: Duration, label: &str)

Increment the execution counter for a timer key.

Use this when you want to count how many times a given timer (identified by (mode, delay_ms, label)) has fired.

This uses saturating arithmetic to avoid overflow.

Source

pub fn snapshot() -> TimerMetricsSnapshot

Snapshot all timer execution metrics.

Returns the current contents of the metrics table as a vector of entries. Callers may sort or page the results as needed at the API layer.

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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V