Skip to main content

LatencyTracker

Struct LatencyTracker 

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

Captures per-operation latency samples for a single thread.

The tracker is intentionally thread-local: each thread keeps a Vec<Duration> and the runner concatenates them at finish. There is no shared state, so sample collection introduces no synchronization that would distort the measurement.

Implementations§

Source§

impl LatencyTracker

Source

pub fn new(rate: usize) -> Self

Create a tracker that samples 1 of every rate iterations.

rate = 1 records every iteration. rate = 100 records 1%. Pass at least 1; values below are clamped.

Source

pub fn record<F, R>(&mut self, iter_index: usize, f: F) -> R
where F: FnOnce() -> R,

Run the closure and, if iter_index is on the sampling schedule, record its duration.

iter_index is the 0-based iteration counter on the calling thread. The tracker records the sample when iter_index % sample_rate == 0.

§Example
use dev_stress::LatencyTracker;

let mut t = LatencyTracker::new(1);
t.record(0, || std::hint::black_box(1 + 1));
t.record(1, || std::hint::black_box(1 + 1));
assert_eq!(t.samples_count(), 2);
Source

pub fn samples_count(&self) -> usize

Number of samples currently held by this tracker.

Source

pub fn into_samples(self) -> Vec<Duration>

Move all samples out of this tracker.

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, 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.