kaspa_consensus_core/api/
counters.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2
3#[derive(Default)]
4pub struct ProcessingCounters {
5    pub blocks_submitted: AtomicU64,
6    pub header_counts: AtomicU64,
7    pub dep_counts: AtomicU64,
8    pub mergeset_counts: AtomicU64,
9    pub body_counts: AtomicU64,
10    pub txs_counts: AtomicU64,
11    pub chain_block_counts: AtomicU64,
12    pub chain_disqualified_counts: AtomicU64,
13    pub mass_counts: AtomicU64,
14}
15
16impl ProcessingCounters {
17    pub fn snapshot(&self) -> ProcessingCountersSnapshot {
18        ProcessingCountersSnapshot {
19            blocks_submitted: self.blocks_submitted.load(Ordering::Relaxed),
20            header_counts: self.header_counts.load(Ordering::Relaxed),
21            dep_counts: self.dep_counts.load(Ordering::Relaxed),
22            mergeset_counts: self.mergeset_counts.load(Ordering::Relaxed),
23            body_counts: self.body_counts.load(Ordering::Relaxed),
24            txs_counts: self.txs_counts.load(Ordering::Relaxed),
25            chain_block_counts: self.chain_block_counts.load(Ordering::Relaxed),
26            chain_disqualified_counts: self.chain_disqualified_counts.load(Ordering::Relaxed),
27            mass_counts: self.mass_counts.load(Ordering::Relaxed),
28        }
29    }
30}
31
32#[derive(Debug, PartialEq, Eq)]
33pub struct ProcessingCountersSnapshot {
34    pub blocks_submitted: u64,
35    pub header_counts: u64,
36    pub dep_counts: u64,
37    pub mergeset_counts: u64,
38    pub body_counts: u64,
39    pub txs_counts: u64,
40    pub chain_block_counts: u64,
41    pub chain_disqualified_counts: u64,
42    pub mass_counts: u64,
43}
44
45impl core::ops::Sub for &ProcessingCountersSnapshot {
46    type Output = ProcessingCountersSnapshot;
47
48    fn sub(self, rhs: Self) -> Self::Output {
49        Self::Output {
50            blocks_submitted: self.blocks_submitted.saturating_sub(rhs.blocks_submitted),
51            header_counts: self.header_counts.saturating_sub(rhs.header_counts),
52            dep_counts: self.dep_counts.saturating_sub(rhs.dep_counts),
53            mergeset_counts: self.mergeset_counts.saturating_sub(rhs.mergeset_counts),
54            body_counts: self.body_counts.saturating_sub(rhs.body_counts),
55            txs_counts: self.txs_counts.saturating_sub(rhs.txs_counts),
56            chain_block_counts: self.chain_block_counts.saturating_sub(rhs.chain_block_counts),
57            chain_disqualified_counts: self.chain_disqualified_counts.saturating_sub(rhs.chain_disqualified_counts),
58            mass_counts: self.mass_counts.saturating_sub(rhs.mass_counts),
59        }
60    }
61}