use std::sync::atomic::{AtomicU64, Ordering};
use super::CarrierAction;
#[derive(Debug, Default)]
pub struct CarrierCounters {
armed_timer_gauge: AtomicU64,
timer_wakes: AtomicU64,
connect_attempts: AtomicU64,
frames_sent: AtomicU64,
}
impl CarrierCounters {
pub fn snapshot(&self) -> CarrierCounterSnapshot {
CarrierCounterSnapshot {
armed_timer_gauge: self.armed_timer_gauge.load(Ordering::Relaxed),
timer_wakes: self.timer_wakes.load(Ordering::Relaxed),
connect_attempts: self.connect_attempts.load(Ordering::Relaxed),
frames_sent: self.frames_sent.load(Ordering::Relaxed),
}
}
pub fn record_actions(&self, actions: &[CarrierAction]) {
for action in actions {
match action {
CarrierAction::StartAttempt { generation: _ } => {
self.connect_attempts.fetch_add(1, Ordering::Relaxed);
}
CarrierAction::EmitEvent(_)
| CarrierAction::CancelAttempt { generation: _ }
| CarrierAction::CloseSocket { key: _, cause: _ } => {}
}
}
}
pub(crate) fn record_frame_sent(&self) {
self.frames_sent.fetch_add(1, Ordering::Relaxed);
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct CarrierCounterSnapshot {
pub armed_timer_gauge: u64,
pub timer_wakes: u64,
pub connect_attempts: u64,
pub frames_sent: u64,
}