Skip to main content

reth_storage_overlay/
manager_metrics.rs

1use reth_metrics::{
2    metrics::{Counter, Histogram},
3    Metrics,
4};
5use std::time::Duration;
6
7/// Metrics for state trie overlay management.
8#[derive(Clone, Metrics)]
9#[metrics(scope = "sync.block_validation.state_trie_overlay")]
10pub(crate) struct StateTrieOverlayMetrics {
11    /// Duration of overlay computation in seconds.
12    pub(crate) overlay_computation_duration_seconds: Histogram,
13    /// Number of requests satisfied by an existing overlay cache entry.
14    pub(crate) overlay_cache_reuses: Counter,
15    /// Number of overlay cache entries populated by computing an overlay.
16    pub(crate) overlay_cache_fills: Counter,
17    /// Time spent waiting for an in-progress overlay computation, in seconds.
18    pub(crate) overlay_wait_duration_seconds: Histogram,
19}
20
21/// Metrics for execution overlay management.
22#[derive(Clone, Metrics)]
23#[metrics(scope = "sync.block_validation.execution_overlay")]
24pub(crate) struct ExecutionOverlayMetrics {
25    /// Duration of overlay computation in seconds.
26    pub(crate) overlay_computation_duration_seconds: Histogram,
27    /// Number of requests satisfied by an existing overlay cache entry.
28    pub(crate) overlay_cache_reuses: Counter,
29    /// Number of overlay cache entries populated by computing an overlay.
30    pub(crate) overlay_cache_fills: Counter,
31    /// Time spent waiting for an in-progress overlay computation, in seconds.
32    pub(crate) overlay_wait_duration_seconds: Histogram,
33}
34
35pub(crate) trait OverlayCacheMetrics {
36    fn record_cache_reuse(&self);
37
38    fn record_cache_fill(&self);
39
40    fn record_wait_duration(&self, duration: Duration);
41}
42
43impl OverlayCacheMetrics for StateTrieOverlayMetrics {
44    fn record_cache_reuse(&self) {
45        self.overlay_cache_reuses.increment(1);
46    }
47
48    fn record_cache_fill(&self) {
49        self.overlay_cache_fills.increment(1);
50    }
51
52    fn record_wait_duration(&self, duration: Duration) {
53        self.overlay_wait_duration_seconds.record(duration.as_secs_f64());
54    }
55}
56
57impl OverlayCacheMetrics for ExecutionOverlayMetrics {
58    fn record_cache_reuse(&self) {
59        self.overlay_cache_reuses.increment(1);
60    }
61
62    fn record_cache_fill(&self) {
63        self.overlay_cache_fills.increment(1);
64    }
65
66    fn record_wait_duration(&self, duration: Duration) {
67        self.overlay_wait_duration_seconds.record(duration.as_secs_f64());
68    }
69}