-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move exec metrics into executor
- Loading branch information
Showing
11 changed files
with
94 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Executor metrics. | ||
//! | ||
//! Block processing related to syncing should take care to update the metrics by using e.g. | ||
//! [`ExecutorMetrics::metered`]. | ||
use std::time::Instant; | ||
|
||
use metrics::{Counter, Gauge}; | ||
use reth_execution_types::BlockExecutionInput; | ||
use reth_metrics::Metrics; | ||
use reth_primitives::BlockWithSenders; | ||
|
||
/// Executor metrics. | ||
// TODO(onbjerg): add sload/sstore, acc load/acc change, bytecode metrics | ||
#[derive(Metrics, Clone)] | ||
#[metrics(scope = "sync.execution")] | ||
pub struct ExecutorMetrics { | ||
/// The total amount of gas processed. | ||
pub gas_processed_total: Counter, | ||
/// The instantaneous amount of gas processed per second. | ||
pub gas_per_second: Gauge, | ||
} | ||
|
||
impl ExecutorMetrics { | ||
/// Execute the given block and update metrics for the execution. | ||
pub fn metered<F, R>(&self, input: BlockExecutionInput<'_, BlockWithSenders>, f: F) -> R | ||
where | ||
F: FnOnce(BlockExecutionInput<'_, BlockWithSenders>) -> R, | ||
{ | ||
let gas_used = input.block.gas_used; | ||
|
||
// Execute the block and record the elapsed time. | ||
let execute_start = Instant::now(); | ||
let output = f(input); | ||
let execution_duration = execute_start.elapsed().as_secs_f64(); | ||
|
||
// Update gas metrics. | ||
self.gas_processed_total.increment(gas_used); | ||
self.gas_per_second.set(gas_used as f64 / execution_duration); | ||
|
||
output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters