reth_bench/bench/
mod.rs

1//! `reth benchmark` command. Collection of various benchmarking routines.
2
3use clap::{Parser, Subcommand};
4use reth_cli_runner::CliContext;
5use reth_node_core::args::LogArgs;
6use reth_tracing::FileWorkerGuard;
7
8mod context;
9mod new_payload_fcu;
10mod new_payload_only;
11mod output;
12
13/// `reth bench` command
14#[derive(Debug, Parser)]
15pub struct BenchmarkCommand {
16    #[command(subcommand)]
17    command: Subcommands,
18
19    #[command(flatten)]
20    logs: LogArgs,
21}
22
23/// `reth benchmark` subcommands
24#[derive(Subcommand, Debug)]
25pub enum Subcommands {
26    /// Benchmark which calls `newPayload`, then `forkchoiceUpdated`.
27    NewPayloadFcu(new_payload_fcu::Command),
28
29    /// Benchmark which only calls subsequent `newPayload` calls.
30    NewPayloadOnly(new_payload_only::Command),
31}
32
33impl BenchmarkCommand {
34    /// Execute `benchmark` command
35    pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
36        // Initialize tracing
37        let _guard = self.init_tracing()?;
38
39        match self.command {
40            Subcommands::NewPayloadFcu(command) => command.execute(ctx).await,
41            Subcommands::NewPayloadOnly(command) => command.execute(ctx).await,
42        }
43    }
44
45    /// Initializes tracing with the configured options.
46    ///
47    /// If file logging is enabled, this function returns a guard that must be kept alive to ensure
48    /// that all logs are flushed to disk.
49    pub fn init_tracing(&self) -> eyre::Result<Option<FileWorkerGuard>> {
50        let guard = self.logs.init_tracing()?;
51        Ok(guard)
52    }
53}