|
1 | | -use metrics::Histogram; |
| 1 | +use metrics::{Counter, Histogram}; |
2 | 2 | use metrics_derive::Metrics; |
3 | 3 | use std::{collections::HashMap, time::Instant}; |
4 | 4 | use strum::{EnumIter, IntoEnumIterator}; |
@@ -27,10 +27,21 @@ impl MetricsHandler { |
27 | 27 | } |
28 | 28 |
|
29 | 29 | /// The duration of the current block building task if any. |
30 | | - pub(crate) fn finish_block_building_recording(&mut self) { |
| 30 | + pub(crate) fn finish_block_building_recording(&mut self, gas_used: u64) { |
| 31 | + // Always increment the cumulative gas counter (similar to geth's commitGasCounter) |
| 32 | + self.block_building_meter.metric.commit_gas.increment(gas_used); |
| 33 | + |
31 | 34 | let duration = self.block_building_meter.start.take().map(|start| start.elapsed()); |
32 | 35 | if let Some(duration) = duration { |
33 | | - self.block_building_meter.metric.block_building_duration.record(duration.as_secs_f64()); |
| 36 | + let duration_secs = duration.as_secs_f64(); |
| 37 | + self.block_building_meter.metric.block_building_duration.record(duration_secs); |
| 38 | + self.block_building_meter.metric.gas_per_block.record(gas_used as f64); |
| 39 | + if duration_secs > 0.0 { |
| 40 | + self.block_building_meter |
| 41 | + .metric |
| 42 | + .gas_per_second |
| 43 | + .record(gas_used as f64 / duration_secs); |
| 44 | + } |
34 | 45 | } |
35 | 46 | } |
36 | 47 | } |
@@ -113,4 +124,10 @@ pub(crate) struct BlockBuildingMeter { |
113 | 124 | pub(crate) struct BlockBuildingMetric { |
114 | 125 | /// The duration of the block building task. |
115 | 126 | block_building_duration: Histogram, |
| 127 | + /// The gas used per block. |
| 128 | + pub(crate) gas_per_block: Histogram, |
| 129 | + /// The gas throughput in gas/second. |
| 130 | + pub(crate) gas_per_second: Histogram, |
| 131 | + /// The cumulative gas used across all committed blocks (similar to geth's miner/commit_gas). |
| 132 | + pub(crate) commit_gas: Counter, |
116 | 133 | } |
0 commit comments