|
| 1 | +//! Metrics for the sparse state trie |
| 2 | +
|
| 3 | +use reth_metrics::{metrics::Histogram, Metrics}; |
| 4 | + |
| 5 | +/// Metrics for the sparse state trie |
| 6 | +#[derive(Default, Debug)] |
| 7 | +pub(crate) struct SparseStateTrieMetrics { |
| 8 | + /// Number of account nodes that were skipped during a multiproof reveal due to being redundant |
| 9 | + /// (i.e. they were already revealed) |
| 10 | + pub(crate) multiproof_skipped_account_nodes: u64, |
| 11 | + /// Number of total account nodes, including those that were skipped. |
| 12 | + pub(crate) multiproof_total_account_nodes: u64, |
| 13 | + /// Number of storage nodes that were skipped during a multiproof reveal due to being redundant |
| 14 | + /// (i.e. they were already revealed) |
| 15 | + pub(crate) multiproof_skipped_storage_nodes: u64, |
| 16 | + /// Number of total storage nodes, including those that were skipped. |
| 17 | + pub(crate) multiproof_total_storage_nodes: u64, |
| 18 | + /// The actual metrics we will record into the histogram |
| 19 | + pub(crate) histograms: SparseStateTrieHistograms, |
| 20 | +} |
| 21 | + |
| 22 | +impl SparseStateTrieMetrics { |
| 23 | + /// Record the metrics into the histograms |
| 24 | + pub(crate) fn record(&self) { |
| 25 | + self.histograms |
| 26 | + .multiproof_skipped_account_nodes |
| 27 | + .record(self.multiproof_skipped_account_nodes as f64); |
| 28 | + self.histograms |
| 29 | + .multiproof_total_account_nodes |
| 30 | + .record(self.multiproof_total_account_nodes as f64); |
| 31 | + self.histograms |
| 32 | + .multiproof_skipped_storage_nodes |
| 33 | + .record(self.multiproof_skipped_storage_nodes as f64); |
| 34 | + self.histograms |
| 35 | + .multiproof_total_storage_nodes |
| 36 | + .record(self.multiproof_total_storage_nodes as f64); |
| 37 | + } |
| 38 | + |
| 39 | + /// Increment the skipped account nodes counter |
| 40 | + pub(crate) fn increment_skipped_account_nodes(&mut self) { |
| 41 | + self.multiproof_skipped_account_nodes += 1; |
| 42 | + } |
| 43 | + |
| 44 | + /// Increment the total account nodes counter |
| 45 | + pub(crate) fn increment_total_account_nodes(&mut self) { |
| 46 | + self.multiproof_total_account_nodes += 1; |
| 47 | + } |
| 48 | + |
| 49 | + /// Increment the skipped storage nodes counter |
| 50 | + pub(crate) fn increment_skipped_storage_nodes(&mut self) { |
| 51 | + self.multiproof_skipped_storage_nodes += 1; |
| 52 | + } |
| 53 | + |
| 54 | + /// Increment the total storage nodes counter |
| 55 | + pub(crate) fn increment_total_storage_nodes(&mut self) { |
| 56 | + self.multiproof_total_storage_nodes += 1; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +/// Metrics for the sparse state trie |
| 61 | +#[derive(Metrics)] |
| 62 | +#[metrics(scope = "sparse_state_trie")] |
| 63 | +pub(crate) struct SparseStateTrieHistograms { |
| 64 | + /// Histogram of account nodes that were skipped during a multiproof reveal due to being |
| 65 | + /// redundant (i.e. they were already revealed) |
| 66 | + pub(crate) multiproof_skipped_account_nodes: Histogram, |
| 67 | + /// Histogram of total account nodes, including those that were skipped. |
| 68 | + pub(crate) multiproof_total_account_nodes: Histogram, |
| 69 | + /// Histogram of storage nodes that were skipped during a multiproof reveal due to being |
| 70 | + /// redundant (i.e. they were already revealed) |
| 71 | + pub(crate) multiproof_skipped_storage_nodes: Histogram, |
| 72 | + /// Histogram of total storage nodes, including those that were skipped. |
| 73 | + pub(crate) multiproof_total_storage_nodes: Histogram, |
| 74 | +} |
0 commit comments