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 account_worker_storage_wait_seconds: Histogram,
35}
36
37impl ProofTaskTrieMetrics {
38 pub fn record_account_nodes(&self, count: usize) {
40 self.blinded_account_nodes.record(count as f64);
41 }
42
43 pub fn record_storage_nodes(&self, count: usize) {
45 self.blinded_storage_nodes.record(count as f64);
46 }
47
48 pub fn record_storage_worker_idle_time(&self, duration: Duration) {
50 self.storage_worker_idle_time_seconds.record(duration.as_secs_f64());
51 }
52
53 pub fn record_account_worker_idle_time(&self, duration: Duration) {
55 self.account_worker_idle_time_seconds.record(duration.as_secs_f64());
56 }
57
58 pub(crate) fn record_value_encoder_stats(&self, stats: &ValueEncoderStats) {
60 self.deferred_encoder_dispatched.record(stats.dispatched_count as f64);
61 self.deferred_encoder_from_cache.record(stats.from_cache_count as f64);
62 self.deferred_encoder_sync.record(stats.sync_count as f64);
63 self.deferred_encoder_dispatched_missing_root
64 .record(stats.dispatched_missing_root_count as f64);
65 self.account_worker_storage_wait_seconds.record(stats.storage_wait_time.as_secs_f64());
66 }
67}
68
69#[derive(Clone, Debug)]
71pub struct ProofTaskCursorMetrics {
72 pub account_trie_cursor: TrieCursorMetrics,
74 pub account_hashed_cursor: HashedCursorMetrics,
76 pub storage_trie_cursor: TrieCursorMetrics,
78 pub storage_hashed_cursor: HashedCursorMetrics,
80}
81
82impl ProofTaskCursorMetrics {
83 pub fn new() -> Self {
85 Self {
86 account_trie_cursor: TrieCursorMetrics::new(TrieType::State),
87 account_hashed_cursor: HashedCursorMetrics::new(TrieType::State),
88 storage_trie_cursor: TrieCursorMetrics::new(TrieType::Storage),
89 storage_hashed_cursor: HashedCursorMetrics::new(TrieType::Storage),
90 }
91 }
92
93 pub fn record(&mut self, cache: &mut ProofTaskCursorMetricsCache) {
98 self.account_trie_cursor.record(&mut cache.account_trie_cursor);
99 self.account_hashed_cursor.record(&mut cache.account_hashed_cursor);
100 self.storage_trie_cursor.record(&mut cache.storage_trie_cursor);
101 self.storage_hashed_cursor.record(&mut cache.storage_hashed_cursor);
102 cache.reset();
103 }
104}
105
106impl Default for ProofTaskCursorMetrics {
107 fn default() -> Self {
108 Self::new()
109 }
110}
111
112#[derive(Clone, Debug, Default, Copy)]
114pub struct ProofTaskCursorMetricsCache {
115 pub account_trie_cursor: TrieCursorMetricsCache,
117 pub account_hashed_cursor: HashedCursorMetricsCache,
119 pub storage_trie_cursor: TrieCursorMetricsCache,
121 pub storage_hashed_cursor: HashedCursorMetricsCache,
123}
124
125impl ProofTaskCursorMetricsCache {
126 pub fn extend(&mut self, other: &Self) {
130 self.account_trie_cursor.extend(&other.account_trie_cursor);
131 self.account_hashed_cursor.extend(&other.account_hashed_cursor);
132 self.storage_trie_cursor.extend(&other.storage_trie_cursor);
133 self.storage_hashed_cursor.extend(&other.storage_hashed_cursor);
134 }
135
136 pub const fn reset(&mut self) {
138 self.account_trie_cursor.reset();
139 self.account_hashed_cursor.reset();
140 self.storage_trie_cursor.reset();
141 self.storage_hashed_cursor.reset();
142 }
143
144 pub fn record_spans(&self) {
146 self.account_trie_cursor.record_span("account_trie_cursor");
147 self.account_hashed_cursor.record_span("account_hashed_cursor");
148 self.storage_trie_cursor.record_span("storage_trie_cursor");
149 self.storage_hashed_cursor.record_span("storage_hashed_cursor");
150 }
151}