reth_trie_parallel/
proof_task_metrics.rs1use reth_metrics::{metrics::Histogram, Metrics};
2use reth_trie::{
3 hashed_cursor::{HashedCursorMetrics, HashedCursorMetricsCache},
4 trie_cursor::{TrieCursorMetrics, TrieCursorMetricsCache},
5 TrieType,
6};
7
8#[derive(Clone, Metrics)]
10#[metrics(scope = "trie.proof_task")]
11pub struct ProofTaskTrieMetrics {
12 blinded_account_nodes: Histogram,
14 blinded_storage_nodes: Histogram,
16}
17
18impl ProofTaskTrieMetrics {
19 pub fn record_account_nodes(&self, count: usize) {
21 self.blinded_account_nodes.record(count as f64);
22 }
23
24 pub fn record_storage_nodes(&self, count: usize) {
26 self.blinded_storage_nodes.record(count as f64);
27 }
28}
29
30#[derive(Clone, Debug)]
32pub struct ProofTaskCursorMetrics {
33 pub account_trie_cursor: TrieCursorMetrics,
35 pub account_hashed_cursor: HashedCursorMetrics,
37 pub storage_trie_cursor: TrieCursorMetrics,
39 pub storage_hashed_cursor: HashedCursorMetrics,
41}
42
43impl ProofTaskCursorMetrics {
44 pub fn new() -> Self {
46 Self {
47 account_trie_cursor: TrieCursorMetrics::new(TrieType::State),
48 account_hashed_cursor: HashedCursorMetrics::new(TrieType::State),
49 storage_trie_cursor: TrieCursorMetrics::new(TrieType::Storage),
50 storage_hashed_cursor: HashedCursorMetrics::new(TrieType::Storage),
51 }
52 }
53
54 pub fn record(&mut self, cache: &mut ProofTaskCursorMetricsCache) {
59 self.account_trie_cursor.record(&mut cache.account_trie_cursor);
60 self.account_hashed_cursor.record(&mut cache.account_hashed_cursor);
61 self.storage_trie_cursor.record(&mut cache.storage_trie_cursor);
62 self.storage_hashed_cursor.record(&mut cache.storage_hashed_cursor);
63 cache.reset();
64 }
65}
66
67impl Default for ProofTaskCursorMetrics {
68 fn default() -> Self {
69 Self::new()
70 }
71}
72
73#[derive(Clone, Debug, Default, Copy)]
75pub struct ProofTaskCursorMetricsCache {
76 pub account_trie_cursor: TrieCursorMetricsCache,
78 pub account_hashed_cursor: HashedCursorMetricsCache,
80 pub storage_trie_cursor: TrieCursorMetricsCache,
82 pub storage_hashed_cursor: HashedCursorMetricsCache,
84}
85
86impl ProofTaskCursorMetricsCache {
87 pub fn extend(&mut self, other: &Self) {
91 self.account_trie_cursor.extend(&other.account_trie_cursor);
92 self.account_hashed_cursor.extend(&other.account_hashed_cursor);
93 self.storage_trie_cursor.extend(&other.storage_trie_cursor);
94 self.storage_hashed_cursor.extend(&other.storage_hashed_cursor);
95 }
96
97 pub const fn reset(&mut self) {
99 self.account_trie_cursor.reset();
100 self.account_hashed_cursor.reset();
101 self.storage_trie_cursor.reset();
102 self.storage_hashed_cursor.reset();
103 }
104
105 pub fn record_spans(&self) {
107 self.account_trie_cursor.record_span("account_trie_cursor");
108 self.account_hashed_cursor.record_span("account_hashed_cursor");
109 self.storage_trie_cursor.record_span("storage_trie_cursor");
110 self.storage_hashed_cursor.record_span("storage_hashed_cursor");
111 }
112}