refactor(irtt-stats): rename WindowEvent to StatsEvent

This commit is contained in:
Nils Andreas Svee committed 2026-05-13 13:12:06 +07:00
1 parent 05f9732760
commit 0dd137a59e
1 file changed
+17 -17
+17 -17
View File
@@ -59,8 +59,8 @@ pub enum SampleMode {
pub struct StatsCollector { pub struct StatsCollector {
config: StatsConfig, config: StatsConfig,
cumulative: CoreStats, cumulative: CoreStats,
rolling_count: Option<VecDeque<WindowEvent>>, rolling_count: Option<VecDeque<StatsEvent>>,
rolling_time: Option<VecDeque<WindowEvent>>, rolling_time: Option<VecDeque<StatsEvent>>,
} }
impl StatsCollector { impl StatsCollector {
@@ -74,16 +74,16 @@ impl StatsCollector {
} }
pub fn process(&mut self, event: &ClientEvent) -> EventStatsUpdate { pub fn process(&mut self, event: &ClientEvent) -> EventStatsUpdate {
let Some(window_event) = WindowEvent::from_client_event(event) else { let Some(stats_event) = StatsEvent::from_client_event(event) else {
return EventStatsUpdate::default(); return EventStatsUpdate::default();
}; };
let update = self.cumulative.apply(window_event.clone()); let update = self.cumulative.apply(stats_event.clone());
if let (Some(limit), Some(window)) = if let (Some(limit), Some(window)) =
(self.config.rolling_count, self.rolling_count.as_mut()) (self.config.rolling_count, self.rolling_count.as_mut())
{ {
window.push_back(window_event.clone()); window.push_back(stats_event.clone());
while window.len() > limit { while window.len() > limit {
window.pop_front(); window.pop_front();
} }
@@ -92,8 +92,8 @@ impl StatsCollector {
if let (Some(duration), Some(window)) = if let (Some(duration), Some(window)) =
(self.config.rolling_time, self.rolling_time.as_mut()) (self.config.rolling_time, self.rolling_time.as_mut())
{ {
let cutoff = window_event.at().checked_sub(duration); let cutoff = stats_event.at().checked_sub(duration);
window.push_back(window_event); window.push_back(stats_event);
if let Some(cutoff) = cutoff { if let Some(cutoff) = cutoff {
while window.front().is_some_and(|event| event.at() < cutoff) { while window.front().is_some_and(|event| event.at() < cutoff) {
window.pop_front(); window.pop_front();
@@ -278,10 +278,10 @@ impl CoreStats {
} }
} }
fn apply(&mut self, event: WindowEvent) -> EventStatsUpdate { fn apply(&mut self, event: StatsEvent) -> EventStatsUpdate {
let mut update = EventStatsUpdate::default(); let mut update = EventStatsUpdate::default();
match event { match event {
WindowEvent::Sent { StatsEvent::Sent {
bytes, bytes,
send_call_ns, send_call_ns,
timer_error_ns, timer_error_ns,
@@ -293,7 +293,7 @@ impl CoreStats {
self.send_call.push_ns(send_call_ns); self.send_call.push_ns(send_call_ns);
self.timer_error.push_ns(timer_error_ns); self.timer_error.push_ns(timer_error_ns);
} }
WindowEvent::UniqueReply { StatsEvent::UniqueReply {
is_late, sample, .. is_late, sample, ..
} => { } => {
let sample = *sample; let sample = *sample;
@@ -343,18 +343,18 @@ impl CoreStats {
} }
} }
} }
WindowEvent::DuplicateReply { .. } => { StatsEvent::DuplicateReply { .. } => {
self.events.duplicate_replies += 1; self.events.duplicate_replies += 1;
self.packets.packets_received += 1; self.packets.packets_received += 1;
self.packets.duplicates += 1; self.packets.duplicates += 1;
} }
WindowEvent::Loss { .. } => { StatsEvent::Loss { .. } => {
self.events.loss_events += 1; self.events.loss_events += 1;
} }
WindowEvent::Warning { .. } => { StatsEvent::Warning { .. } => {
self.events.warning_events += 1; self.events.warning_events += 1;
} }
WindowEvent::UntrackedLate { .. } => { StatsEvent::UntrackedLate { .. } => {
self.events.untracked_late_replies += 1; self.events.untracked_late_replies += 1;
} }
} }
@@ -454,7 +454,7 @@ impl CoreStats {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
enum WindowEvent { enum StatsEvent {
Sent { Sent {
at: Instant, at: Instant,
bytes: usize, bytes: usize,
@@ -480,7 +480,7 @@ enum WindowEvent {
}, },
} }
impl WindowEvent { impl StatsEvent {
fn from_client_event(event: &ClientEvent) -> Option<Self> { fn from_client_event(event: &ClientEvent) -> Option<Self> {
match event { match event {
ClientEvent::EchoSent { ClientEvent::EchoSent {
@@ -695,7 +695,7 @@ impl RunningStats {
} }
} }
fn snapshot_window(events: &VecDeque<WindowEvent>) -> Snapshot { fn snapshot_window(events: &VecDeque<StatsEvent>) -> Snapshot {
let mut core = CoreStats::new(SampleMode::RunningOnly); let mut core = CoreStats::new(SampleMode::RunningOnly);
for event in events { for event in events {
core.apply(event.clone()); core.apply(event.clone());