Skip to content

Commit 4f1e486

Browse files
authored
feat(engine): execution wait, pre, post metrics (#20166)
1 parent 05307d0 commit 4f1e486

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

crates/engine/tree/src/tree/metrics.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl EngineApiMetrics {
6363
pub(crate) fn execute_metered<E, DB>(
6464
&self,
6565
executor: E,
66-
transactions: impl Iterator<Item = Result<impl ExecutableTx<E>, BlockExecutionError>>,
66+
mut transactions: impl Iterator<Item = Result<impl ExecutableTx<E>, BlockExecutionError>>,
6767
state_hook: Box<dyn OnStateHook>,
6868
) -> Result<(BlockExecutionOutput<E::Receipt>, Vec<Address>), BlockExecutionError>
6969
where
@@ -79,27 +79,42 @@ impl EngineApiMetrics {
7979
let mut executor = executor.with_state_hook(Some(Box::new(wrapper)));
8080

8181
let f = || {
82+
let start = Instant::now();
8283
debug_span!(target: "engine::tree", "pre execution")
8384
.entered()
8485
.in_scope(|| executor.apply_pre_execution_changes())?;
86+
self.executor.pre_execution_histogram.record(start.elapsed());
87+
8588
let exec_span = debug_span!(target: "engine::tree", "execution").entered();
86-
for tx in transactions {
89+
loop {
90+
let start = Instant::now();
91+
let Some(tx) = transactions.next() else { break };
92+
self.executor.transaction_wait_histogram.record(start.elapsed());
93+
8794
let tx = tx?;
95+
senders.push(*tx.signer());
96+
8897
let span =
8998
debug_span!(target: "engine::tree", "execute tx", tx_hash=?tx.tx().tx_hash());
9099
let enter = span.entered();
91100
trace!(target: "engine::tree", "Executing transaction");
92-
senders.push(*tx.signer());
101+
let start = Instant::now();
93102
let gas_used = executor.execute_transaction(tx)?;
103+
self.executor.transaction_execution_histogram.record(start.elapsed());
94104

95105
// record the tx gas used
96106
enter.record("gas_used", gas_used);
97107
}
98108
drop(exec_span);
99-
debug_span!(target: "engine::tree", "finish")
109+
110+
let start = Instant::now();
111+
let result = debug_span!(target: "engine::tree", "finish")
100112
.entered()
101113
.in_scope(|| executor.finish())
102-
.map(|(evm, result)| (evm.into_db(), result))
114+
.map(|(evm, result)| (evm.into_db(), result));
115+
self.executor.post_execution_histogram.record(start.elapsed());
116+
117+
result
103118
};
104119

105120
// Use metered to execute and track timing/gas metrics

crates/evm/evm/src/metrics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ pub struct ExecutorMetrics {
1717
/// The Histogram for amount of gas used.
1818
pub gas_used_histogram: Histogram,
1919

20+
/// The Histogram for amount of time taken to execute the pre-execution changes.
21+
pub pre_execution_histogram: Histogram,
22+
/// The Histogram for amount of time taken to wait for one transaction to be available.
23+
pub transaction_wait_histogram: Histogram,
24+
/// The Histogram for amount of time taken to execute one transaction.
25+
pub transaction_execution_histogram: Histogram,
26+
/// The Histogram for amount of time taken to execute the post-execution changes.
27+
pub post_execution_histogram: Histogram,
2028
/// The Histogram for amount of time taken to execute blocks.
2129
pub execution_histogram: Histogram,
2230
/// The total amount of time it took to execute the latest block.

0 commit comments

Comments
 (0)