pprof-rs icon indicating copy to clipboard operation
pprof-rs copied to clipboard

No flamegraph generated using Criterion

Open arun-akur8 opened this issue 1 year ago • 3 comments

I was trying to get the code in examples/criterion working in order to be able to generate a flamegraph in Criterion.

I have the following Cargo.toml file

[package]
name = "operation_tree"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8"

[dev-dependencies]
criterion = "0.5"
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }

[[bench]]
name = "my_benchmark"
harness = false

My benchmarking script is benches/my_benchmark.rs

extern crate operation_tree;
use criterion::{criterion_group, criterion_main, Criterion};
use pprof::{
    criterion::{Output, PProfProfiler},
    flamegraph::Options,
};
use rand::Rng;
fn criterion_benchmark(c: &mut Criterion) {
    let mut rng = rand::thread_rng();
    let x: Vec<f64> = (0..1000).map(|_x| rng.gen_range(0.0..10.0)).collect();
    c.bench_function("operation_tree", |b| b.iter(|| operation_tree::add_two(&x)));
}

//criterion_group!(benches, criterion_benchmark);
criterion_group! {
    name = benches;
    config = Criterion::default().with_profiler(PProfProfiler::new(100,Output::Flamegraph(Some(Options::default()))));
    targets = criterion_benchmark
}
criterion_main!(benches);

For the following src/lib.rs

pub fn add_two(x: &[f64]) -> Vec<f64> {
    let mut y = Vec::new();
    for i in 0..x.len() {
        y.push(x[i] * 2.0);
    }
    y
}

I ran cargo bench --bench my_benchmark and Criterion ran the benchmarks and I can see the results in target/criterion/operation_tree/ folder. However, there is no flamegraph generated. I am trying to get a minimum working example on this simple code. Is there any setting I am missing?

arun-akur8 avatar Oct 14 '24 11:10 arun-akur8

@arun-akur8 just a shot in the dark, but try running criterion with the --profile-time argument?

richardpringle avatar Nov 01 '24 15:11 richardpringle

I have the same problem currently, passing --profile-time or -- --profile-time both don't work

ozoromo avatar Apr 25 '25 14:04 ozoromo

Same.

loadingalias avatar Jul 04 '25 05:07 loadingalias