Skip to content

Commit d1d295a

Browse files
committed
add throughtput metrics
1 parent fa73081 commit d1d295a

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

crates/chain-orchestrator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<
307307
.as_mut()
308308
.expect("signer must be present")
309309
.sign_block(block.clone())?;
310-
self.metric_handler.finish_block_building_recording();
310+
self.metric_handler.finish_block_building_recording(block.header.gas_used);
311311
return Ok(Some(ChainOrchestratorEvent::BlockSequenced(block)));
312312
}
313313
}

crates/chain-orchestrator/src/metrics.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use metrics::Histogram;
1+
use metrics::{Counter, Histogram};
22
use metrics_derive::Metrics;
33
use std::{collections::HashMap, time::Instant};
44
use strum::{EnumIter, IntoEnumIterator};
@@ -27,10 +27,21 @@ impl MetricsHandler {
2727
}
2828

2929
/// 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+
3134
let duration = self.block_building_meter.start.take().map(|start| start.elapsed());
3235
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+
}
3445
}
3546
}
3647
}
@@ -113,4 +124,10 @@ pub(crate) struct BlockBuildingMeter {
113124
pub(crate) struct BlockBuildingMetric {
114125
/// The duration of the block building task.
115126
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,
116133
}

0 commit comments

Comments
 (0)