aios_collector/
collection_stats.rs1use aios_spec::RawEvent;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum RawEventKind {
10 AppTransition,
12 BinderTransaction,
14 ProcStateChange,
16 FileSystemAccess,
18 NotificationPosted,
20 NotificationInteraction,
22 ScreenState,
24 SystemState,
26}
27
28#[derive(Debug, Clone, Default)]
30pub struct RawEventStats {
31 app_transition: u64,
32 binder_transaction: u64,
33 proc_state_change: u64,
34 file_system_access: u64,
35 notification_posted: u64,
36 notification_interaction: u64,
37 screen_state: u64,
38 system_state: u64,
39}
40
41impl RawEventStats {
42 pub fn record(&mut self, event: &RawEvent) {
44 match event {
45 RawEvent::AppTransition(_) => self.app_transition += 1,
46 RawEvent::BinderTransaction(_) => self.binder_transaction += 1,
47 RawEvent::ProcStateChange(_) => self.proc_state_change += 1,
48 RawEvent::FileSystemAccess(_) => self.file_system_access += 1,
49 RawEvent::NotificationPosted(_) => self.notification_posted += 1,
50 RawEvent::NotificationInteraction(_) => self.notification_interaction += 1,
51 RawEvent::ScreenState(_) => self.screen_state += 1,
52 RawEvent::SystemState(_) => self.system_state += 1,
53 }
54 }
55
56 pub fn count(&self, kind: RawEventKind) -> u64 {
58 match kind {
59 RawEventKind::AppTransition => self.app_transition,
60 RawEventKind::BinderTransaction => self.binder_transaction,
61 RawEventKind::ProcStateChange => self.proc_state_change,
62 RawEventKind::FileSystemAccess => self.file_system_access,
63 RawEventKind::NotificationPosted => self.notification_posted,
64 RawEventKind::NotificationInteraction => self.notification_interaction,
65 RawEventKind::ScreenState => self.screen_state,
66 RawEventKind::SystemState => self.system_state,
67 }
68 }
69
70 pub fn total(&self) -> u64 {
72 self.summary_fields()
73 .into_iter()
74 .map(|(_, count)| count)
75 .sum()
76 }
77
78 pub fn summary_fields(&self) -> Vec<(&'static str, u64)> {
80 vec![
81 ("app_transition", self.app_transition),
82 ("binder_transaction", self.binder_transaction),
83 ("proc_state_change", self.proc_state_change),
84 ("file_system_access", self.file_system_access),
85 ("notification_posted", self.notification_posted),
86 ("notification_interaction", self.notification_interaction),
87 ("screen_state", self.screen_state),
88 ("system_state", self.system_state),
89 ]
90 }
91
92 pub fn summary_line(&self) -> String {
94 let parts: Vec<String> = self
95 .summary_fields()
96 .into_iter()
97 .filter(|(_, count)| *count > 0)
98 .map(|(kind, count)| format!("{kind}={count}"))
99 .collect();
100
101 if parts.is_empty() {
102 "none".to_string()
103 } else {
104 parts.join(" ")
105 }
106 }
107}