Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 140 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ indexmap = { version = "2.11.4" }

rocksdb = { version="0.24.0", default-features = false, features = ["bindgen-runtime"] }

pprof = { version = "0.15", features = ["cpp", "protobuf-codec"] }

[patch.crates-io]
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", tag = "patch-0.30.0-sp1-5.0.0" }

Expand Down
1 change: 1 addition & 0 deletions crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tokio = { workspace = true, features = ["time", "rt"] }
tokio-util.workspace = true

ethrex-metrics = { path = "./metrics", default-features = false }
pprof.workspace = true

[dev-dependencies]
serde_json.workspace = true
Expand Down
16 changes: 15 additions & 1 deletion crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use ethrex_vm::backends::levm::db::DatabaseLogger;
use ethrex_vm::{BlockExecutionResult, DynVmDatabase, Evm, EvmError};
use mempool::Mempool;
use payload::PayloadOrTask;
use pprof::protos::Message;
use rustc_hash::FxHashMap;
use std::collections::hash_map::Entry;
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -833,6 +834,12 @@ impl Blockchain {
}

pub fn add_block_pipeline(&self, block: Block) -> Result<(), ChainError> {
use std::io::Write;

let guard = pprof::ProfilerGuardBuilder::default()
.frequency(99997)
.build()
.unwrap();
let (res, account_updates_list, merkle_queue_length, instants) =
self.execute_block_pipeline(&block)?;

Expand Down Expand Up @@ -863,9 +870,16 @@ impl Blockchain {
instants,
);
}
if let Ok(report) = guard.report().build() {
let mut file = std::fs::File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();

let mut content = Vec::new();
profile.write_to_vec(&mut content).unwrap();
file.write_all(&content).unwrap();
}
result
}

#[allow(clippy::too_many_arguments)]
fn print_add_block_logs(
gas_used: u64,
Expand Down
Loading