From 08feab1a566c662db2950be227e90d31a34a15e1 Mon Sep 17 00:00:00 2001 From: Park Smith <161195644+sdfii@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:20:52 +0100 Subject: [PATCH] feat: log throughput in execution stage (#9253) Co-authored-by: Matthias Seitz --- .../src/constants/gas_units.rs | 12 +++++----- crates/stages/stages/src/stages/execution.rs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/crates/primitives-traits/src/constants/gas_units.rs b/crates/primitives-traits/src/constants/gas_units.rs index 0495a1755e..11caab5139 100644 --- a/crates/primitives-traits/src/constants/gas_units.rs +++ b/crates/primitives-traits/src/constants/gas_units.rs @@ -18,11 +18,11 @@ pub const GIGAGAS: u64 = MEGAGAS * 1_000; pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String { let gas_per_second = gas as f64 / execution_duration.as_secs_f64(); if gas_per_second < MEGAGAS as f64 { - format!("{:.} Kgas/second", gas_per_second / KILOGAS as f64) + format!("{:.2} Kgas/second", gas_per_second / KILOGAS as f64) } else if gas_per_second < GIGAGAS as f64 { - format!("{:.} Mgas/second", gas_per_second / MEGAGAS as f64) + format!("{:.2} Mgas/second", gas_per_second / MEGAGAS as f64) } else { - format!("{:.} Ggas/second", gas_per_second / GIGAGAS as f64) + format!("{:.2} Ggas/second", gas_per_second / GIGAGAS as f64) } } @@ -67,14 +67,14 @@ mod tests { let duration = Duration::from_secs(1); let gas = 100_000; let throughput = format_gas_throughput(gas, duration); - assert_eq!(throughput, "100 Kgas/second"); + assert_eq!(throughput, "100.00 Kgas/second"); let gas = 100_000_000; let throughput = format_gas_throughput(gas, duration); - assert_eq!(throughput, "100 Mgas/second"); + assert_eq!(throughput, "100.00 Mgas/second"); let gas = 100_000_000_000; let throughput = format_gas_throughput(gas, duration); - assert_eq!(throughput, "100 Ggas/second"); + assert_eq!(throughput, "100.00 Ggas/second"); } } diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index a2ee50a606..d3dcdd1bb2 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -233,6 +233,13 @@ where let mut fetch_block_duration = Duration::default(); let mut execution_duration = Duration::default(); + + let mut last_block = start_block; + let mut last_execution_duration = Duration::default(); + let mut last_cumulative_gas = 0; + let mut last_log_instant = Instant::now(); + let log_duration = Duration::from_secs(10); + debug!(target: "sync::stages::execution", start = start_block, end = max_block, "Executing range"); // Execute block range @@ -271,6 +278,22 @@ where })?; execution_duration += execute_start.elapsed(); + // Log execution throughput + if last_log_instant.elapsed() >= log_duration { + info!( + target: "sync::stages::execution", + start = last_block, + end = block_number, + throughput = format_gas_throughput(cumulative_gas - last_cumulative_gas, execution_duration - last_execution_duration), + "Executed block range" + ); + + last_block = block_number + 1; + last_execution_duration = execution_duration; + last_cumulative_gas = cumulative_gas; + last_log_instant = Instant::now(); + } + // Gas metrics if let Some(metrics_tx) = &mut self.metrics_tx { let _ =