Skip to main content

reth_trie_sparse/
metrics.rs

1//! Metrics for the sparse state trie
2
3use reth_metrics::{metrics::Histogram, Metrics};
4
5/// Metrics for the sparse state trie
6#[derive(Default, Debug)]
7pub(crate) struct SparseStateTrieMetrics {
8    /// Number of total account nodes, including those that were skipped.
9    pub(crate) multiproof_total_account_nodes: u64,
10    /// Number of total storage nodes, including those that were skipped.
11    pub(crate) multiproof_total_storage_nodes: u64,
12    /// The actual metrics we will record into the histogram
13    pub(crate) histograms: SparseStateTrieInnerMetrics,
14}
15
16impl SparseStateTrieMetrics {
17    /// Record the metrics into the histograms
18    pub(crate) fn record(&mut self) {
19        use core::mem::take;
20        self.histograms
21            .multiproof_total_account_nodes
22            .record(take(&mut self.multiproof_total_account_nodes) as f64);
23        self.histograms
24            .multiproof_total_storage_nodes
25            .record(take(&mut self.multiproof_total_storage_nodes) as f64);
26    }
27
28    /// Increment the total account nodes counter by the given count
29    pub(crate) const fn increment_total_account_nodes(&mut self, count: u64) {
30        self.multiproof_total_account_nodes += count;
31    }
32
33    /// Increment the total storage nodes counter by the given count
34    pub(crate) const fn increment_total_storage_nodes(&mut self, count: u64) {
35        self.multiproof_total_storage_nodes += count;
36    }
37}
38
39/// Metrics for the sparse state trie
40#[derive(Metrics)]
41#[metrics(scope = "sparse_state_trie")]
42pub(crate) struct SparseStateTrieInnerMetrics {
43    /// Histogram of total account nodes, including those that were skipped.
44    pub(crate) multiproof_total_account_nodes: Histogram,
45    /// Histogram of total storage nodes, including those that were skipped.
46    pub(crate) multiproof_total_storage_nodes: Histogram,
47}
48
49/// Metrics for the parallel sparse trie
50#[derive(Metrics, Clone)]
51#[metrics(scope = "parallel_sparse_trie")]
52pub(crate) struct ParallelSparseTrieMetrics {
53    /// A histogram for the number of subtries updated when calculating hashes.
54    pub(crate) subtries_updated: Histogram,
55    /// A histogram for the time it took to update lower subtrie hashes.
56    pub(crate) subtrie_hash_update_latency: Histogram,
57    /// A histogram for the time it took to update the upper subtrie hashes.
58    pub(crate) subtrie_upper_hash_latency: Histogram,
59}
60
61impl PartialEq for ParallelSparseTrieMetrics {
62    fn eq(&self, _other: &Self) -> bool {
63        // It does not make sense to compare metrics, so return true, all are equal
64        true
65    }
66}
67
68impl Eq for ParallelSparseTrieMetrics {}