Skip to main content

SubMsTimer

Struct SubMsTimer 

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

Autostart stopwatch with named checkpoints. Not thread-safe; use one per task or synchronise externally.

Implementations§

Source§

impl SubMsTimer

Source

pub fn nanos_now() -> u64

Single source of truth for monotonic-clock reads across the subms harness. Returns nanoseconds since a process-local epoch (snapshotted on first call); meaningful only as a delta against another nanos_now() reading.

Prefer SubMsTimer::tick + SubMsTick::elapsed_ns in hot loops - it’s one fewer atomic load + one fewer arithmetic op because we don’t normalise against the process epoch on each call.

Source

pub fn tick() -> SubMsTick

Snapshot the monotonic clock for the “start tick / do work / read delta” pattern. Recipes use this inside their bench loops instead of std::time::Instant::now(). Cost is identical to a raw Instant::now() (the return is a #[repr(transparent)] wrapper).

Source

pub fn measure_ns<F, T>(f: F) -> (T, u64)
where F: FnOnce() -> T,

Time a closure. Returns the closure result and elapsed nanoseconds. Convenient when the call is on the hot path and the caller doesn’t care about retaining a tick handle.

Source

pub fn unnamed() -> SubMsTimer

Autostart unnamed timer.

Source

pub fn new(name: &str) -> SubMsTimer

Autostart timer with a display name (printed in the header).

Source

pub fn start(&mut self) -> &mut SubMsTimer

Reset to t=0 and clear all checkpoints.

Source

pub fn reset(&mut self) -> &mut SubMsTimer

Alias of start.

Source

pub fn mark(&mut self, label: &str) -> u64

Record a checkpoint with the given label. Returns the elapsed-since-start ns.

Source

pub fn lap(&mut self, label: &str) -> u64

Alias of mark - emphasises “split / next leg” semantics.

Source

pub fn stop(&mut self, label: &str) -> u64

Final checkpoint; the timer stops accumulating after this.

Source

pub fn is_stopped(&self) -> bool

true after stop is called.

Source

pub fn elapsed_ns(&self) -> u64

Elapsed since start. Frozen at stop-time if stopped.

Source

pub fn name(&self) -> &str

Source

pub fn checkpoints(&self) -> &[SubMsTimerCheckpoint]

Source

pub fn print<W>(&self, out: &mut W) -> Result<(), Error>
where W: Write,

Print a fixed-width timeline. Byte-equivalent to Java’s SubMsTimer.print.

Layout:

timer "parse-request"  total=3.2us
  headers-read         +1.1us       1.1us
  body-decoded         +800ns       1.9us
  served *             +1.3us       3.2us

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more