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: AtomicU64Implementations§
Source§impl Stats
impl Stats
Sourcepub async fn record_sent(&self)
pub async fn record_sent(&self)
Record a sent message.
Sourcepub async fn record_received(&self, latency_ns: u64)
pub async fn record_received(&self, latency_ns: u64)
Record a received message with latency in nanoseconds.
Sourcepub async fn record_error(&self)
pub async fn record_error(&self)
Record an error.
Sourcepub fn increment_connections(&self)
pub fn increment_connections(&self)
Increment connection count.
Sourcepub fn decrement_connections(&self)
pub fn decrement_connections(&self)
Decrement connection count.
Sourcepub fn increment_active_connections(&self)
pub fn increment_active_connections(&self)
Increment active connection count.
Sourcepub fn decrement_active_connections(&self)
pub fn decrement_active_connections(&self)
Decrement active connection count.
Sourcepub fn record_connection_attempt(&self)
pub fn record_connection_attempt(&self)
Record a connection attempt.
Sourcepub fn record_connection_failure(&self)
pub fn record_connection_failure(&self)
Record a connection failure.
Sourcepub fn record_crash_injected(&self)
pub fn record_crash_injected(&self)
Record an injected crash (simulated failure).
Sourcepub fn record_reconnect(&self)
pub fn record_reconnect(&self)
Record a successful reconnection.
Sourcepub fn record_reconnect_failure(&self)
pub fn record_reconnect_failure(&self)
Record a failed reconnection attempt.
Sourcepub fn record_duplicates(&self, count: u64)
pub fn record_duplicates(&self, count: u64)
Record duplicates detected by a client’s local SequenceTracker.
Sourcepub fn record_gaps(&self, count: u64)
pub fn record_gaps(&self, count: u64)
Record gaps detected by a client’s local SequenceTracker.
Sourcepub fn set_duplicates(&self, count: u64)
pub fn set_duplicates(&self, count: u64)
Set the absolute duplicate count.
Sourcepub fn set_head_loss(&self, count: u64)
pub fn set_head_loss(&self, count: u64)
Set head loss count (messages lost before first received).
Sourcepub async fn record_received_batch(&self, latencies_ns: &[u64])
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.
Sourcepub async fn snapshot(&self) -> StatsSnapshot
pub async fn snapshot(&self) -> StatsSnapshot
Get current snapshot of statistics.