iris_core/multicore/
subscription_stats.rs1use std::fmt;
6use std::sync::atomic::{AtomicU64, Ordering};
7use std::sync::Arc;
8
9#[derive(Default)]
12pub struct SubscriptionStats {
13 pub dispatched: AtomicU64,
15
16 pub dropped: AtomicU64,
18
19 pub processed: Arc<AtomicU64>,
22
23 pub actively_processing: Arc<AtomicU64>,
26
27 pub flushed: Arc<AtomicU64>,
30}
31
32impl SubscriptionStats {
33 pub fn new() -> Self {
35 Self {
36 dispatched: AtomicU64::new(0),
37 dropped: AtomicU64::new(0),
38 processed: Arc::new(AtomicU64::new(0)),
39 actively_processing: Arc::new(AtomicU64::new(0)),
40 flushed: Arc::new(AtomicU64::new(0)),
41 }
42 }
43
44 pub fn snapshot(&self) -> SubscriptionStats {
46 SubscriptionStats {
47 dispatched: AtomicU64::new(self.get_dispatched()),
48 dropped: AtomicU64::new(self.get_dropped()),
49 processed: Arc::new(AtomicU64::new(self.get_processed())),
50 actively_processing: Arc::new(AtomicU64::new(self.get_actively_processing())),
51 flushed: Arc::new(AtomicU64::new(self.get_flushed())),
52 }
53 }
54
55 pub fn get_dispatched(&self) -> u64 {
57 self.dispatched.load(Ordering::Relaxed)
58 }
59
60 pub fn get_dropped(&self) -> u64 {
62 self.dropped.load(Ordering::Relaxed)
63 }
64
65 pub fn get_processed(&self) -> u64 {
67 self.processed.load(Ordering::Relaxed)
68 }
69
70 pub fn get_actively_processing(&self) -> u64 {
72 self.actively_processing.load(Ordering::Relaxed)
73 }
74
75 pub fn get_flushed(&self) -> u64 {
77 self.flushed.load(Ordering::Relaxed)
78 }
79}
80
81impl fmt::Display for SubscriptionStats {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 write!(
85 f,
86 "Processed: {}\nDropped: {}\nFlushed (to disk): {}",
87 self.get_processed(),
88 self.get_dropped(),
89 self.get_flushed(),
90 )
91 }
92}