Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No flamegraph generated using Criterion #254

Open
arun-akur8 opened this issue Oct 14, 2024 · 0 comments
Open

No flamegraph generated using Criterion #254

arun-akur8 opened this issue Oct 14, 2024 · 0 comments

Comments

@arun-akur8
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant