reth_trie_parallel/
metrics.rs

1use crate::stats::ParallelTrieStats;
2use metrics::Histogram;
3use reth_metrics::Metrics;
4use reth_trie::metrics::{TrieRootMetrics, TrieType};
5
6/// Parallel state root metrics.
7#[derive(Debug)]
8pub struct ParallelStateRootMetrics {
9    /// State trie metrics.
10    pub state_trie: TrieRootMetrics,
11    /// Parallel trie metrics.
12    pub parallel: ParallelTrieMetrics,
13    /// Storage trie metrics.
14    pub storage_trie: TrieRootMetrics,
15}
16
17impl Default for ParallelStateRootMetrics {
18    fn default() -> Self {
19        Self {
20            state_trie: TrieRootMetrics::new(TrieType::State),
21            parallel: ParallelTrieMetrics::new_with_labels(&[("type", "root")]),
22            storage_trie: TrieRootMetrics::new(TrieType::Storage),
23        }
24    }
25}
26
27impl ParallelStateRootMetrics {
28    /// Record state trie metrics
29    pub fn record_state_trie(&self, stats: ParallelTrieStats) {
30        self.state_trie.record(stats.trie_stats());
31        self.parallel.record(stats);
32    }
33}
34
35/// Parallel state root metrics.
36#[derive(Metrics)]
37#[metrics(scope = "trie_parallel")]
38pub struct ParallelTrieMetrics {
39    /// The number of storage roots computed in parallel.
40    pub precomputed_storage_roots: Histogram,
41    /// The number of leaves for which we did not pre-compute the storage roots.
42    pub missed_leaves: Histogram,
43}
44
45impl ParallelTrieMetrics {
46    /// Record parallel trie metrics.
47    pub fn record(&self, stats: ParallelTrieStats) {
48        self.precomputed_storage_roots.record(stats.precomputed_storage_roots() as f64);
49        self.missed_leaves.record(stats.missed_leaves() as f64);
50    }
51}