diff --git a/Cargo.lock b/Cargo.lock index e612bf8ab..5d1f529ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4320,6 +4320,7 @@ dependencies = [ "parity-scale-codec", "paste", "postcard", + "pprof", "proptest", "proptest-derive", "rand 0.8.5", @@ -4552,6 +4553,7 @@ dependencies = [ "libc", "lifetimed-bytes", "parking_lot 0.12.1", + "pprof", "rand 0.8.5", "rand_xorshift", "reth-mdbx-sys", @@ -4696,6 +4698,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "plain_hasher", + "pprof", "proptest", "proptest-derive", "rand 0.8.5", @@ -4756,6 +4759,7 @@ dependencies = [ "ethereum-types", "ethnum", "hex-literal", + "pprof", "rand 0.8.5", "reth-rlp", "reth-rlp-derive", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 23ca188ec..beea3fefb 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -80,6 +80,7 @@ proptest-derive = "0.3" # https://github.com/paradigmxyz/reth/pull/177#discussion_r1021172198 secp256k1 = "0.24.2" criterion = "0.4.0" +pprof = { version = "0.11", features = ["flamegraph", "frame-pointer", "criterion"] } [features] default = [] diff --git a/crates/primitives/benches/recover_ecdsa_crit.rs b/crates/primitives/benches/recover_ecdsa_crit.rs index 9d3d2fb54..7706b68a6 100644 --- a/crates/primitives/benches/recover_ecdsa_crit.rs +++ b/crates/primitives/benches/recover_ecdsa_crit.rs @@ -1,5 +1,6 @@ use criterion::{criterion_group, criterion_main, Criterion}; use hex_literal::hex; +use pprof::criterion::{Output, PProfProfiler}; use reth_primitives::TransactionSigned; use reth_rlp::Decodable; @@ -16,5 +17,9 @@ pub fn criterion_benchmark(c: &mut Criterion) { }); } -criterion_group!(benches, criterion_benchmark); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = criterion_benchmark +} criterion_main!(benches); diff --git a/crates/rlp/Cargo.toml b/crates/rlp/Cargo.toml index ad261346b..c35546605 100644 --- a/crates/rlp/Cargo.toml +++ b/crates/rlp/Cargo.toml @@ -33,6 +33,7 @@ rand = "0.8" secp256k1 = { version = "0.24", features = [ "rand-std", ] } +pprof = { version = "0.11", features = ["flamegraph", "frame-pointer", "criterion"] } [features] alloc = [] diff --git a/crates/rlp/benches/bench.rs b/crates/rlp/benches/bench.rs index 57a596192..abb70c7eb 100644 --- a/crates/rlp/benches/bench.rs +++ b/crates/rlp/benches/bench.rs @@ -12,6 +12,7 @@ use bytes::BytesMut; use criterion::{criterion_group, criterion_main, Criterion}; use ethnum::*; use hex_literal::hex; +use pprof::criterion::{Output, PProfProfiler}; use reth_rlp::*; fn bench_encode(c: &mut Criterion) { @@ -65,5 +66,9 @@ fn bench_decode(c: &mut Criterion) { }); } -criterion_group!(benches, bench_encode, bench_decode); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = bench_encode, bench_decode +} criterion_main!(benches); diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index a0ab52562..69f8dbd45 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -52,6 +52,7 @@ reth-interfaces = { path = "../../interfaces", features = ["bench"] } tempfile = "3.3.0" test-fuzz = "3.0.4" +pprof = { version = "0.11", features = ["flamegraph", "frame-pointer", "criterion"] } criterion = "0.4.0" iai = "0.1.1" tokio = { version = "1.21.2", features = ["full"] } diff --git a/crates/storage/db/benches/criterion.rs b/crates/storage/db/benches/criterion.rs index 0a814cd06..9e6947f38 100644 --- a/crates/storage/db/benches/criterion.rs +++ b/crates/storage/db/benches/criterion.rs @@ -3,10 +3,15 @@ use criterion::{ black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; +use pprof::criterion::{Output, PProfProfiler}; use reth_db::cursor::{DbDupCursorRO, DbDupCursorRW}; use std::time::Instant; -criterion_group!(benches, db, serialization); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = db, serialization +} criterion_main!(benches); pub fn db(c: &mut Criterion) { diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index 746cbd2f2..cad28e49f 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -3,6 +3,7 @@ use criterion::{ black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; +use pprof::criterion::{Output, PProfProfiler}; use proptest::{ arbitrary::Arbitrary, prelude::{any_with, ProptestConfig}, @@ -16,7 +17,11 @@ use reth_db::{ use std::{collections::HashSet, time::Instant}; use test_fuzz::runtime::num_traits::Zero; -criterion_group!(benches, hash_keys); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = hash_keys +} criterion_main!(benches); /// It benchmarks the insertion of rows into a table where `Keys` are hashes. diff --git a/crates/storage/libmdbx-rs/Cargo.toml b/crates/storage/libmdbx-rs/Cargo.toml index 9a35d2f7c..a081f0f5f 100644 --- a/crates/storage/libmdbx-rs/Cargo.toml +++ b/crates/storage/libmdbx-rs/Cargo.toml @@ -24,6 +24,7 @@ ffi = { package = "reth-mdbx-sys", path = "./mdbx-sys" } lifetimed-bytes = { version = "0.1", optional = true } [dev-dependencies] +pprof = { version = "0.11", features = ["flamegraph", "frame-pointer", "criterion"] } criterion = "0.4" rand = "0.8" rand_xorshift = "0.3" diff --git a/crates/storage/libmdbx-rs/benches/cursor.rs b/crates/storage/libmdbx-rs/benches/cursor.rs index 74d975b9c..0a6a72b7b 100644 --- a/crates/storage/libmdbx-rs/benches/cursor.rs +++ b/crates/storage/libmdbx-rs/benches/cursor.rs @@ -2,6 +2,7 @@ mod utils; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use ffi::*; +use pprof::criterion::{Output, PProfProfiler}; use reth_libmdbx::*; use std::ptr; use utils::*; @@ -101,5 +102,9 @@ fn bench_get_seq_raw(c: &mut Criterion) { }); } -criterion_group!(benches, bench_get_seq_iter, bench_get_seq_cursor, bench_get_seq_raw); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = bench_get_seq_iter, bench_get_seq_cursor, bench_get_seq_raw +} criterion_main!(benches); diff --git a/crates/storage/libmdbx-rs/benches/transaction.rs b/crates/storage/libmdbx-rs/benches/transaction.rs index bff69a3e0..27f27839f 100644 --- a/crates/storage/libmdbx-rs/benches/transaction.rs +++ b/crates/storage/libmdbx-rs/benches/transaction.rs @@ -115,5 +115,9 @@ fn bench_put_rand_raw(c: &mut Criterion) { }); } -criterion_group!(benches, bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw); +criterion_group! { + name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw +} criterion_main!(benches);