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 storage_worker_idle_time_seconds: Histogram,
16 account_worker_idle_time_seconds: Histogram,
19 deferred_encoder_dispatched: Histogram,
21 deferred_encoder_from_cache: Histogram,
23 deferred_encoder_sync: Histogram,
25 deferred_encoder_dispatched_missing_root: Histogram,
27 account_worker_storage_wait_seconds: Histogram,
31}
32
33impl ProofTaskTrieMetrics {
34 pub fn record_storage_worker_idle_time(&self, duration: Duration) {
36 self.storage_worker_idle_time_seconds.record(duration.as_secs_f64());
37 }
38
39 pub fn record_account_worker_idle_time(&self, duration: Duration) {
41 self.account_worker_idle_time_seconds.record(duration.as_secs_f64());
42 }
43
44 pub(crate) fn record_value_encoder_stats(&self, stats: &ValueEncoderStats) {
46 self.deferred_encoder_dispatched.record(stats.dispatched_count as f64);
47 self.deferred_encoder_from_cache.record(stats.from_cache_count as f64);
48 self.deferred_encoder_sync.record(stats.sync_count as f64);
49 self.deferred_encoder_dispatched_missing_root
50 .record(stats.dispatched_missing_root_count as f64);
51 self.account_worker_storage_wait_seconds.record(stats.storage_wait_time.as_secs_f64());
52 }
53}
54
55#[derive(Clone, Debug)]
57pub struct ProofTaskCursorMetrics {
58 pub account_trie_cursor: TrieCursorMetrics,
60 pub account_hashed_cursor: HashedCursorMetrics,
62 pub storage_trie_cursor: TrieCursorMetrics,
64 pub storage_hashed_cursor: HashedCursorMetrics,
66}
67
68impl ProofTaskCursorMetrics {
69 pub fn new() -> Self {
71 Self {
72 account_trie_cursor: TrieCursorMetrics::new(TrieType::State),
73 account_hashed_cursor: HashedCursorMetrics::new(TrieType::State),
74 storage_trie_cursor: TrieCursorMetrics::new(TrieType::Storage),
75 storage_hashed_cursor: HashedCursorMetrics::new(TrieType::Storage),
76 }
77 }
78
79 pub fn record(&mut self, cache: &mut ProofTaskCursorMetricsCache) {
84 self.account_trie_cursor.record(&mut cache.account_trie_cursor);
85 self.account_hashed_cursor.record(&mut cache.account_hashed_cursor);
86 self.storage_trie_cursor.record(&mut cache.storage_trie_cursor);
87 self.storage_hashed_cursor.record(&mut cache.storage_hashed_cursor);
88 cache.reset();
89 }
90}
91
92impl Default for ProofTaskCursorMetrics {
93 fn default() -> Self {
94 Self::new()
95 }
96}
97
98#[derive(Clone, Debug, Default, Copy)]
100pub struct ProofTaskCursorMetricsCache {
101 pub account_trie_cursor: TrieCursorMetricsCache,
103 pub account_hashed_cursor: HashedCursorMetricsCache,
105 pub storage_trie_cursor: TrieCursorMetricsCache,
107 pub storage_hashed_cursor: HashedCursorMetricsCache,
109}
110
111impl ProofTaskCursorMetricsCache {
112 pub fn extend(&mut self, other: &Self) {
116 self.account_trie_cursor.extend(&other.account_trie_cursor);
117 self.account_hashed_cursor.extend(&other.account_hashed_cursor);
118 self.storage_trie_cursor.extend(&other.storage_trie_cursor);
119 self.storage_hashed_cursor.extend(&other.storage_hashed_cursor);
120 }
121
122 pub const fn reset(&mut self) {
124 self.account_trie_cursor.reset();
125 self.account_hashed_cursor.reset();
126 self.storage_trie_cursor.reset();
127 self.storage_hashed_cursor.reset();
128 }
129
130 pub fn record_spans(&self) {
132 self.account_trie_cursor.record_span("account_trie_cursor");
133 self.account_hashed_cursor.record_span("account_hashed_cursor");
134 self.storage_trie_cursor.record_span("storage_trie_cursor");
135 self.storage_hashed_cursor.record_span("storage_hashed_cursor");
136 }
137}