reth_trie_parallel/
proof_task_metrics.rs1use crate::value_encoder::ValueEncoderStats;
2use reth_metrics::{metrics::Histogram, Metrics};
3use reth_trie::{
4 hashed_cursor::{HashedCursorMetrics, HashedCursorMetricsCache},
5 trie_cursor::{TrieCursorMetrics, TrieCursorMetricsCache},
6 TrieType,
7};
8use std::time::Duration;
9
10#[derive(Clone, Metrics)]
12#[metrics(scope = "trie.proof_task")]
13pub struct ProofTaskTrieMetrics {
14 blinded_account_nodes: Histogram,
16 blinded_storage_nodes: Histogram,
18 storage_worker_idle_time_seconds: Histogram,
20 account_worker_idle_time_seconds: Histogram,
23 deferred_encoder_dispatched: Histogram,
25 deferred_encoder_from_cache: Histogram,
27 deferred_encoder_sync: Histogram,
29 deferred_encoder_dispatched_missing_root: Histogram,
31}
32
33impl ProofTaskTrieMetrics {
34 pub fn record_account_nodes(&self, count: usize) {
36 self.blinded_account_nodes.record(count as f64);
37 }
38
39 pub fn record_storage_nodes(&self, count: usize) {
41 self.blinded_storage_nodes.record(count as f64);
42 }
43
44 pub fn record_storage_worker_idle_time(&self, duration: Duration) {
46 self.storage_worker_idle_time_seconds.record(duration.as_secs_f64());
47 }
48
49 pub fn record_account_worker_idle_time(&self, duration: Duration) {
51 self.account_worker_idle_time_seconds.record(duration.as_secs_f64());
52 }
53
54 pub(crate) fn record_value_encoder_stats(&self, stats: &ValueEncoderStats) {
56 self.deferred_encoder_dispatched.record(stats.dispatched_count as f64);
57 self.deferred_encoder_from_cache.record(stats.from_cache_count as f64);
58 self.deferred_encoder_sync.record(stats.sync_count as f64);
59 self.deferred_encoder_dispatched_missing_root
60 .record(stats.dispatched_missing_root_count as f64);
61 }
62}
63
64#[derive(Clone, Debug)]
66pub struct ProofTaskCursorMetrics {
67 pub account_trie_cursor: TrieCursorMetrics,
69 pub account_hashed_cursor: HashedCursorMetrics,
71 pub storage_trie_cursor: TrieCursorMetrics,
73 pub storage_hashed_cursor: HashedCursorMetrics,
75}
76
77impl ProofTaskCursorMetrics {
78 pub fn new() -> Self {
80 Self {
81 account_trie_cursor: TrieCursorMetrics::new(TrieType::State),
82 account_hashed_cursor: HashedCursorMetrics::new(TrieType::State),
83 storage_trie_cursor: TrieCursorMetrics::new(TrieType::Storage),
84 storage_hashed_cursor: HashedCursorMetrics::new(TrieType::Storage),
85 }
86 }
87
88 pub fn record(&mut self, cache: &mut ProofTaskCursorMetricsCache) {
93 self.account_trie_cursor.record(&mut cache.account_trie_cursor);
94 self.account_hashed_cursor.record(&mut cache.account_hashed_cursor);
95 self.storage_trie_cursor.record(&mut cache.storage_trie_cursor);
96 self.storage_hashed_cursor.record(&mut cache.storage_hashed_cursor);
97 cache.reset();
98 }
99}
100
101impl Default for ProofTaskCursorMetrics {
102 fn default() -> Self {
103 Self::new()
104 }
105}
106
107#[derive(Clone, Debug, Default, Copy)]
109pub struct ProofTaskCursorMetricsCache {
110 pub account_trie_cursor: TrieCursorMetricsCache,
112 pub account_hashed_cursor: HashedCursorMetricsCache,
114 pub storage_trie_cursor: TrieCursorMetricsCache,
116 pub storage_hashed_cursor: HashedCursorMetricsCache,
118}
119
120impl ProofTaskCursorMetricsCache {
121 pub fn extend(&mut self, other: &Self) {
125 self.account_trie_cursor.extend(&other.account_trie_cursor);
126 self.account_hashed_cursor.extend(&other.account_hashed_cursor);
127 self.storage_trie_cursor.extend(&other.storage_trie_cursor);
128 self.storage_hashed_cursor.extend(&other.storage_hashed_cursor);
129 }
130
131 pub const fn reset(&mut self) {
133 self.account_trie_cursor.reset();
134 self.account_hashed_cursor.reset();
135 self.storage_trie_cursor.reset();
136 self.storage_hashed_cursor.reset();
137 }
138
139 pub fn record_spans(&self) {
141 self.account_trie_cursor.record_span("account_trie_cursor");
142 self.account_hashed_cursor.record_span("account_hashed_cursor");
143 self.storage_trie_cursor.record_span("storage_trie_cursor");
144 self.storage_hashed_cursor.record_span("storage_hashed_cursor");
145 }
146}