Skip to main content

Stats

Struct Stats 

Source
pub struct Stats {
    pub sent_count: AtomicU64,
    pub received_count: AtomicU64,
    pub error_count: AtomicU64,
    pub connections: AtomicU64,
    pub active_connections: AtomicU64,
    pub connection_attempts: AtomicU64,
    pub connection_failures: AtomicU64,
    pub crashes_injected: AtomicU64,
    pub reconnects: AtomicU64,
    pub reconnect_failures: AtomicU64,
    /* private fields */
}
Expand description

Statistics collector for latency and throughput measurement.

Thread-safe statistics aggregator using atomic counters and HDR histogram. Designed for high-throughput benchmarking with minimal contention.

§Example

use lightbench::metrics::Stats;
use std::sync::Arc;

let stats = Arc::new(Stats::new());

// Record sent messages
stats.record_sent().await;

// Record received with latency (nanoseconds)
stats.record_received(1_000_000).await; // 1ms latency

// Get snapshot for reporting
let snapshot = stats.snapshot().await;
println!("Received: {}", snapshot.received_count);

Fields§

§sent_count: AtomicU64§received_count: AtomicU64§error_count: AtomicU64§connections: AtomicU64§active_connections: AtomicU64§connection_attempts: AtomicU64§connection_failures: AtomicU64§crashes_injected: AtomicU64§reconnects: AtomicU64§reconnect_failures: AtomicU64

Implementations§

Source§

impl Stats

Source

pub fn new() -> Self

Create a new statistics collector.

Source

pub async fn record_sent(&self)

Record a sent message.

Source

pub async fn record_received(&self, latency_ns: u64)

Record a received message with latency in nanoseconds.

Source

pub async fn record_error(&self)

Record an error.

Source

pub fn increment_connections(&self)

Increment connection count.

Source

pub fn decrement_connections(&self)

Decrement connection count.

Source

pub fn increment_active_connections(&self)

Increment active connection count.

Source

pub fn decrement_active_connections(&self)

Decrement active connection count.

Source

pub fn record_connection_attempt(&self)

Record a connection attempt.

Source

pub fn record_connection_failure(&self)

Record a connection failure.

Source

pub fn record_crash_injected(&self)

Record an injected crash (simulated failure).

Source

pub fn record_reconnect(&self)

Record a successful reconnection.

Source

pub fn record_reconnect_failure(&self)

Record a failed reconnection attempt.

Source

pub fn record_duplicates(&self, count: u64)

Record duplicates detected by a client’s local SequenceTracker.

Source

pub fn record_gaps(&self, count: u64)

Record gaps detected by a client’s local SequenceTracker.

Source

pub fn set_duplicates(&self, count: u64)

Set the absolute duplicate count.

Source

pub fn set_gaps(&self, count: u64)

Set the absolute gap count.

Source

pub fn set_head_loss(&self, count: u64)

Set head loss count (messages lost before first received).

Source

pub async fn record_received_batch(&self, latencies_ns: &[u64])

Record a batch of received latencies with minimal locking.

More efficient than calling record_received in a loop.

Source

pub async fn snapshot(&self) -> StatsSnapshot

Get current snapshot of statistics.

Source

pub async fn reset(&self)

Reset all statistics.

Trait Implementations§

Source§

impl Default for Stats

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Stats

§

impl !RefUnwindSafe for Stats

§

impl Send for Stats

§

impl Sync for Stats

§

impl Unpin for Stats

§

impl UnsafeUnpin for Stats

§

impl UnwindSafe for Stats

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