pprof with criterion for flamegraph
* pprof-rs with crition error
pprof-rs with crition error
* fix tmp path.
* add pprof with criterion for flamegraph
add pprof with criterion for flamegraph
MODIFY
Cargo.lock
Cargo.lock
@@ -329,6 +329,15 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
+[[package]]
+name = "arrayvec"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
+dependencies = [
+ "nodrop",
+]
+
[[package]]
name = "arrayvec"
version = "0.5.2"
@@ -667,6 +676,7 @@ dependencies = [
"futures-timer",
"network-api",
"parking_lot 0.11.2",
+ "pprof",
"proptest",
"rand 0.8.4",
"rand_core 0.6.3",
@@ -788,7 +798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
dependencies = [
"arrayref",
- "arrayvec",
+ "arrayvec 0.5.2",
"constant_time_eq",
]
@@ -1021,6 +1031,12 @@ dependencies = [
"petgraph",
]
+[[package]]
+name = "bytemuck"
+version = "1.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
+
[[package]]
name = "byteorder"
version = "0.5.3"
@@ -1458,6 +1474,15 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
+[[package]]
+name = "cpp_demangle"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea47428dc9d2237f3c6bc134472edfd63ebba0af932e783506dcfd66f10d18a"
+dependencies = [
+ "cfg-if 1.0.0",
+]
+
[[package]]
name = "cpufeatures"
version = "0.2.1"
@@ -2006,6 +2031,15 @@ dependencies = [
"structopt 0.3.25",
]
+[[package]]
+name = "debugid"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f91cf5a8c2f2097e2a32627123508635d47ce10563d999ec1a95addf08b502ba"
+dependencies = [
+ "uuid",
+]
+
[[package]]
name = "derivative"
version = "2.2.0"
@@ -3650,6 +3684,24 @@ dependencies = [
"unindent",
]
+[[package]]
+name = "inferno"
+version = "0.10.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bfa5bd9a10b38bf5f3c670f9d75c194adbecd2b1573f737668ab8599f41edc87"
+dependencies = [
+ "ahash 0.7.4",
+ "atty",
+ "indexmap",
+ "itoa",
+ "lazy_static",
+ "log 0.4.14",
+ "num-format",
+ "quick-xml",
+ "rgb",
+ "str_stack",
+]
+
[[package]]
name = "input_buffer"
version = "0.4.0"
@@ -4122,7 +4174,7 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374"
dependencies = [
- "arrayvec",
+ "arrayvec 0.5.2",
"bitflags",
"cfg-if 1.0.0",
"ryu",
@@ -4309,7 +4361,7 @@ version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50ed78489c87924235665a0ab345b298ee34dff0f7ad62c0ba6608b2144fb75e"
dependencies = [
- "arrayvec",
+ "arrayvec 0.5.2",
"asynchronous-codec 0.6.0",
"bytes 1.1.0",
"either",
@@ -5727,6 +5779,12 @@ dependencies = [
"hashbrown 0.8.2",
]
+[[package]]
+name = "nodrop"
+version = "0.1.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
+
[[package]]
name = "nohash-hasher"
version = "0.2.0"
@@ -5806,6 +5864,16 @@ dependencies = [
"syn 1.0.80",
]
+[[package]]
+name = "num-format"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bafe4179722c2894288ee77a9f044f02811c86af699344c498b0840c698a2465"
+dependencies = [
+ "arrayvec 0.4.12",
+ "itoa",
+]
+
[[package]]
name = "num-integer"
version = "0.1.44"
@@ -6017,7 +6085,7 @@ version = "1.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4b26b16c7687c3075982af47719e481815df30bc544f7a6690763a25ca16e9d"
dependencies = [
- "arrayvec",
+ "arrayvec 0.5.2",
"bitvec 0.17.4",
"byte-slice-cast",
"serde",
@@ -6409,6 +6477,25 @@ dependencies = [
"winapi 0.2.8",
]
+[[package]]
+name = "pprof"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c7600124d694d855283caf9f333befe2abce090833bb638009aeddd9e156dee"
+dependencies = [
+ "backtrace",
+ "criterion",
+ "inferno",
+ "lazy_static",
+ "libc",
+ "log 0.4.14",
+ "nix 0.20.0",
+ "parking_lot 0.11.2",
+ "symbolic-demangle",
+ "tempfile",
+ "thiserror",
+]
+
[[package]]
name = "ppv-lite86"
version = "0.2.10"
@@ -6421,7 +6508,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad9940b913ee56ddd94aec2d3cd179dd47068236f42a1a6415ccf9d880ce2a61"
dependencies = [
- "arrayvec",
+ "arrayvec 0.5.2",
"typed-arena",
]
@@ -7242,6 +7329,15 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "rgb"
+version = "0.8.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fddb3b23626145d1776addfc307e1a1851f60ef6ca64f376bcb889697144cf0"
+dependencies = [
+ "bytemuck",
+]
+
[[package]]
name = "ring"
version = "0.16.20"
@@ -10028,6 +10124,12 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a66ae6a6cd930c97707cb3f1b62aadb8ddddd2fefa9df539564b3bfaa15dd31f"
+[[package]]
+name = "str_stack"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb"
+
[[package]]
name = "stream-task"
version = "1.8.0-alpha"
@@ -10136,6 +10238,29 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "171758edb47aa306a78dfa4ab9aeb5167405bd4e3dc2b64e88f6a84bbe98bd63"
+[[package]]
+name = "symbolic-common"
+version = "8.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1c77c64c4a8138a8d26b6ab26b29fdbe4fae7f6537cf9bf30e51b282efa2361"
+dependencies = [
+ "debugid",
+ "memmap",
+ "stable_deref_trait",
+ "uuid",
+]
+
+[[package]]
+name = "symbolic-demangle"
+version = "8.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "027d1ff6cc3cf63e523c60dfeaca5fb54c3ed15ecd9418f70a76854d966c79fb"
+dependencies = [
+ "cpp_demangle",
+ "rustc-demangle",
+ "symbolic-common",
+]
+
[[package]]
name = "syn"
version = "0.11.11"
@@ -11356,6 +11481,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
+[[package]]
+name = "uuid"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
+
[[package]]
name = "value-bag"
version = "1.0.0-alpha.6"

MODIFY
benchmarks/Cargo.toml
benchmarks/Cargo.toml
@@ -34,6 +34,7 @@ starcoin-network-api = {path = "../network/api", package="network-api"}
executor-benchmark = {path = "../executor/benchmark", package="starcoin-executor-benchmark" }
futures = "0.3.12"
logger = {path = "../commons/logger",package="starcoin-logger"}
+pprof = { version = "0.4", features = ["flamegraph", "criterion"] }
[dev-dependencies]
# see https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options

MODIFY
benchmarks/README.md
benchmarks/README.md
@@ -11,3 +11,13 @@ cargo bench
```shell
cargo bench --bench bench_state_tree
```
+
+3. run a special benchmark with pprof
+```shell
+cargo bench --bench bench_state_tree -- --profile-time=10
+```
+Notice:
+run benchmark with pprof on macOS show this error, linux(ubuntu) run successful
+```shell
+error: process didn't exit successfully: `./bench_state_tree-3daab626ee8d6834 --profile-time=10 --bench` (signal: 11, SIGSEGV: invalid memory reference)
+```
\ No newline at end of file

MODIFY
benchmarks/benches/bench_chain.rs
benchmarks/benches/bench_chain.rs
use benchmarks::chain::ChainBencher;
#[allow(deprecated)]
use criterion::{criterion_group, criterion_main, Benchmark, Criterion};
+use pprof::criterion::{Output, PProfProfiler};
#[allow(deprecated)]
fn block_apply(c: &mut Criterion) {
@@ -38,5 +39,9 @@ fn query_block(c: &mut Criterion) {
}
}
-criterion_group!(starcoin_chain_benches, block_apply, query_block);
+criterion_group!(
+ name=starcoin_chain_benches;
+ config = Criterion::default()
+ .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
+ targets=block_apply,query_block);
criterion_main!(starcoin_chain_benches);

MODIFY
benchmarks/benches/bench_state_tree.rs
benchmarks/benches/bench_state_tree.rs
@@ -5,6 +5,7 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use crypto::hash::*;
use forkable_jellyfish_merkle::blob::Blob;
use forkable_jellyfish_merkle::HashValueKey;
+use pprof::criterion::{Output, PProfProfiler};
use rand::{rngs::StdRng, SeedableRng};
use starcoin_config::RocksdbConfig;
use starcoin_state_store_api::StateNodeStore;
@@ -98,7 +99,11 @@ fn bench_put_and_commit(c: &mut Criterion) {
group.finish();
}
-criterion_group!(benches, bench_get_with_proof, bench_put_and_commit);
+criterion_group!(
+ name=benches;
+ config = Criterion::default()
+ .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
+ targets=bench_get_with_proof, bench_put_and_commit);
criterion_main!(benches);
fn gen_kv_from_seed(seed: &[u8], num_keys: usize) -> HashMap<HashValueKey, Blob> {

MODIFY
benchmarks/benches/bench_storage.rs
benchmarks/benches/bench_storage.rs
use benchmarks::storage::StorageBencher;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use crypto::HashValue;
+use pprof::criterion::{Output, PProfProfiler};
use starcoin_accumulator::{accumulator_info::AccumulatorInfo, Accumulator, MerkleAccumulator};
use starcoin_config::RocksdbConfig;
use starcoin_storage::cache_storage::CacheStorage;
@@ -16,15 +17,11 @@ use std::sync::Arc;
//
fn storage_transaction(c: &mut Criterion) {
::logger::init_for_test();
+ let path = starcoin_config::temp_path();
c.bench_function("storage_transaction", |b| {
let storage = Storage::new(StorageInstance::new_cache_and_db_instance(
CacheStorage::new(None),
- DBStorage::new(
- starcoin_config::temp_path().as_ref(),
- RocksdbConfig::default(),
- None,
- )
- .unwrap(),
+ DBStorage::new(path.as_ref(), RocksdbConfig::default(), None).unwrap(),
))
.unwrap();
let bencher = StorageBencher::new(storage);
@@ -35,16 +32,12 @@ fn storage_transaction(c: &mut Criterion) {
/// accumulator benchmarks
fn accumulator_append(c: &mut Criterion) {
::logger::init_for_test();
+ let path = starcoin_config::temp_path();
c.bench_function("accumulator_append", |b| {
let storage = Arc::new(
Storage::new(StorageInstance::new_cache_and_db_instance(
CacheStorage::new(None),
- DBStorage::new(
- starcoin_config::temp_path().as_ref(),
- RocksdbConfig::default(),
- None,
- )
- .unwrap(),
+ DBStorage::new(path.as_ref(), RocksdbConfig::default(), None).unwrap(),
))
.unwrap(),
);
@@ -70,8 +63,9 @@ fn create_leaves(nums: std::ops::Range<usize>) -> Vec<HashValue> {
.collect()
}
criterion_group!(
- starcoin_storage_benches,
- storage_transaction,
- accumulator_append
+ name=starcoin_storage_benches;
+ config = Criterion::default()
+ .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
+ targets=storage_transaction, accumulator_append
);
criterion_main!(starcoin_storage_benches);

MODIFY
benchmarks/benches/bench_vm.rs
benchmarks/benches/bench_vm.rs
// SPDX-License-Identifier: Apache-2.0
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use executor_benchmark::run_benchmark;
+use pprof::criterion::{Output, PProfProfiler};
pub fn transaction_execution(c: &mut Criterion) {
::logger::init();
@@ -15,5 +16,9 @@ pub fn transaction_execution(c: &mut Criterion) {
}
}
-criterion_group!(starcoin_vm_benches, transaction_execution);
+criterion_group!(
+ name=starcoin_vm_benches;
+ config = Criterion::default()
+ .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
+ targets=transaction_execution);
criterion_main!(starcoin_vm_benches);

pprof with criterion for flamegraph (#2992)

* pprof-rs with crition error

pprof-rs with crition error

* fix tmp path.

* add pprof with criterion for flamegraph

add pprof with criterion for flamegraph

Co-authored-by: jolestar <jolestar@gmail.com>