Skip to main content

StatsCollector

Struct StatsCollector 

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

Stateful statistics collector for irtt-client events.

A collector maintains cumulative statistics and, when configured, rolling windows. Rolling snapshots are recomputed from retained normalized events.

§Example

Feed a short stream of irtt-client events to a finite-mode collector and read back a cumulative snapshot:

use irtt_stats::{StatsCollector, StatsConfig};

let mut collector = StatsCollector::new(StatsConfig::finite());
for (seq, rtt_ms) in [10_u64, 30, 20].into_iter().enumerate() {
    collector.process(&reply(seq as u32, rtt_ms));
}

let snapshot = collector.snapshot();
assert_eq!(snapshot.events.echo_replies, 3);
assert_eq!(snapshot.rtt.primary.count, 3);
// Finite mode retains exact samples, so the round-trip metric reports an
// exact median: the middle of the sorted 10, 20, 30 ms samples.
assert_eq!(snapshot.rtt.primary.median_ns, Some(20_000_000.0));

Implementations§

Source§

impl StatsCollector

Source

pub fn new(config: StatsConfig) -> Self

Creates a collector with the supplied configuration.

Source

pub fn process(&mut self, event: &ClientEvent) -> EventStatsUpdate

Processes one client event and returns the per-event statistics update.

Updates currently report whether the event contributed a unique reply timing sample and any adjacent-sequence IPDV pairs completed by this event.

Source

pub fn snapshot(&self) -> Snapshot

Returns a snapshot of all events processed by this collector.

This is the snapshot StatsConfig::samples applies to, so under SampleMode::Exact every timing metric here reports a median once it has samples.

Source

pub fn rolling_count(&self) -> Option<Snapshot>

Returns the configured count-based rolling snapshot, if enabled.

The snapshot is recomputed from the retained rolling events using running statistics only, whatever StatsConfig::samples is set to, so its timing metrics report no median. A rolling window is a bounded recent view rather than the run’s retained history.

§Example
use irtt_stats::{StatsCollector, StatsConfig};

let mut collector = StatsCollector::new(StatsConfig {
    rolling_count: Some(2),
    ..StatsConfig::finite()
});
collector.process(&sent(0, 0, 10));
collector.process(&sent(1, 10, 10));
collector.process(&sent(2, 20, 10));

// The window keeps only the last two normalized events...
let rolling = collector.rolling_count().unwrap();
assert_eq!(rolling.packets.packets_sent, 2);
// ...and is recomputed with running statistics, so it reports no median
// even though the collector retains exact samples for its cumulative
// snapshot.
assert_eq!(rolling.send_call.median_ns, None);

// The cumulative snapshot still sees every event.
let cumulative = collector.snapshot();
assert_eq!(cumulative.packets.packets_sent, 3);
assert_eq!(cumulative.send_call.median_ns, Some(10_000.0));
Source

pub fn rolling_time(&self) -> Option<Snapshot>

Returns the configured time-based rolling snapshot, if enabled.

Like StatsCollector::rolling_count, this is recomputed with running statistics only and reports no medians.

§Example
use std::time::Duration;

use irtt_stats::{StatsCollector, StatsConfig};

let mut collector = StatsCollector::new(StatsConfig {
    rolling_time: Some(Duration::from_millis(15)),
    ..StatsConfig::finite()
});
collector.process(&sent(0, 0, 10));
collector.process(&sent(1, 10, 10));
collector.process(&sent(2, 30, 10));

// A 15 ms window anchored at the latest event (30 ms) retains only the
// events from the last 15 ms — here just the final send.
let rolling = collector.rolling_time().unwrap();
assert_eq!(rolling.packets.packets_sent, 1);

Trait Implementations§

Source§

impl Clone for StatsCollector

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StatsCollector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for StatsCollector

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StatsCollector

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.