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}