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_sync: Histogram,
23 deferred_encoder_dispatched_missing_root: Histogram,
25 account_worker_storage_wait_seconds: Histogram,
29}
30
31impl ProofTaskTrieMetrics {
32 pub fn record_storage_worker_idle_time(&self, duration: Duration) {
34 self.storage_worker_idle_time_seconds.record(duration.as_secs_f64());
35 }
36
37 pub fn record_account_worker_idle_time(&self, duration: Duration) {
39 self.account_worker_idle_time_seconds.record(duration.as_secs_f64());
40 }
41
42 pub(crate) fn record_value_encoder_stats(&self, stats: &ValueEncoderStats) {
44 self.deferred_encoder_dispatched.record(stats.dispatched_count as f64);
45 self.deferred_encoder_sync.record(stats.sync_count as f64);
46 self.deferred_encoder_dispatched_missing_root
47 .record(stats.dispatched_missing_root_count as f64);
48 self.account_worker_storage_wait_seconds.record(stats.storage_wait_time.as_secs_f64());
49 }
50}
51
52#[derive(Clone, Debug)]
54pub struct ProofTaskCursorMetrics {
55 pub account_trie_cursor: TrieCursorMetrics,
57 pub account_hashed_cursor: HashedCursorMetrics,
59 pub storage_trie_cursor: TrieCursorMetrics,
61 pub storage_hashed_cursor: HashedCursorMetrics,
63}
64
65impl ProofTaskCursorMetrics {
66 pub fn new() -> Self {
68 Self {
69 account_trie_cursor: TrieCursorMetrics::new(TrieType::State),
70 account_hashed_cursor: HashedCursorMetrics::new(TrieType::State),
71 storage_trie_cursor: TrieCursorMetrics::new(TrieType::Storage),
72 storage_hashed_cursor: HashedCursorMetrics::new(TrieType::Storage),
73 }
74 }
75
76 pub fn record(&mut self, cache: &mut ProofTaskCursorMetricsCache) {
81 self.account_trie_cursor.record(&mut cache.account_trie_cursor);
82 self.account_hashed_cursor.record(&mut cache.account_hashed_cursor);
83 self.storage_trie_cursor.record(&mut cache.storage_trie_cursor);
84 self.storage_hashed_cursor.record(&mut cache.storage_hashed_cursor);
85 cache.reset();
86 }
87}
88
89impl Default for ProofTaskCursorMetrics {
90 fn default() -> Self {
91 Self::new()
92 }
93}
94
95#[derive(Clone, Debug, Default, Copy)]
97pub struct ProofTaskCursorMetricsCache {
98 pub account_trie_cursor: TrieCursorMetricsCache,
100 pub account_hashed_cursor: HashedCursorMetricsCache,
102 pub storage_trie_cursor: TrieCursorMetricsCache,
104 pub storage_hashed_cursor: HashedCursorMetricsCache,
106}
107
108impl ProofTaskCursorMetricsCache {
109 pub fn extend(&mut self, other: &Self) {
113 self.account_trie_cursor.extend(&other.account_trie_cursor);
114 self.account_hashed_cursor.extend(&other.account_hashed_cursor);
115 self.storage_trie_cursor.extend(&other.storage_trie_cursor);
116 self.storage_hashed_cursor.extend(&other.storage_hashed_cursor);
117 }
118
119 pub const fn reset(&mut self) {
121 self.account_trie_cursor.reset();
122 self.account_hashed_cursor.reset();
123 self.storage_trie_cursor.reset();
124 self.storage_hashed_cursor.reset();
125 }
126
127 pub fn record_spans(&self) {
129 self.account_trie_cursor.record_span("account_trie_cursor");
130 self.account_hashed_cursor.record_span("account_hashed_cursor");
131 self.storage_trie_cursor.record_span("storage_trie_cursor");
132 self.storage_hashed_cursor.record_span("storage_hashed_cursor");
133 }
134}