1use std::sync::atomic::{AtomicU64, Ordering};
9
10pub struct BridgeMetrics {
12 push_count: AtomicU64,
14
15 pop_count: AtomicU64,
17
18 full_count: AtomicU64,
20}
21
22impl BridgeMetrics {
23 pub(crate) fn new() -> Self {
24 Self {
25 push_count: AtomicU64::new(0),
26 pop_count: AtomicU64::new(0),
27 full_count: AtomicU64::new(0),
28 }
29 }
30
31 pub(crate) fn record_push(&self) {
32 self.push_count.fetch_add(1, Ordering::Relaxed);
33 }
34
35 pub(crate) fn record_pop(&self) {
36 self.pop_count.fetch_add(1, Ordering::Relaxed);
37 }
38
39 pub(crate) fn record_pops(&self, n: u64) {
40 self.pop_count.fetch_add(n, Ordering::Relaxed);
41 }
42
43 pub(crate) fn record_full(&self) {
44 self.full_count.fetch_add(1, Ordering::Relaxed);
45 }
46
47 pub fn pushes(&self) -> u64 {
49 self.push_count.load(Ordering::Relaxed)
50 }
51
52 pub fn pops(&self) -> u64 {
54 self.pop_count.load(Ordering::Relaxed)
55 }
56
57 pub fn full_events(&self) -> u64 {
59 self.full_count.load(Ordering::Relaxed)
60 }
61
62 pub fn in_flight(&self) -> u64 {
64 let pushed = self.pushes();
65 let popped = self.pops();
66 pushed.saturating_sub(popped)
67 }
68}