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 with criterion and flamegraph feature #127

Open
xd009642 opened this issue May 15, 2022 · 4 comments
Open

No flamegraph generated with criterion and flamegraph feature #127

xd009642 opened this issue May 15, 2022 · 4 comments

Comments

@xd009642
Copy link

I tried to use pprof with criterion to generate a flamegraph and I'm not sure what I'm missing as it seems to match the example functionally but no SVG is generated. Below is the entire benchmark source but it can also be found here https://github.com/xd009642/yin/blob/pprof_test/benches/yin_benchmark.rs

Also not sure if there's some way to turn on some form of logging for pprof but it could be useful for something just to help diagnose if things like that are a user problem or a pprof problem. I didn't see any mentioned and tried a quick RUST_LOG change which didn' do anything but if anyone has any tips in that regard I'd be interested 👀

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use yin::Yin;

use pprof::criterion::{Output, PProfProfiler};

pub fn norm_sine_benchmark(c: &mut Criterion) {
    let sample = {
        use dasp::{signal, Signal};
        let mut signal = signal::rate(44100.0).const_hz(100.0).sine();
        let sample: Vec<f64> = (0..44100).map(|_| signal.next()).collect();
        sample
    };
    let yin = Yin::init(0.1, 40.0, 200.0, 1000);
    c.bench_function("1000 sr, 100.0 freq", |b| {
        b.iter(|| yin.estimate_freq(black_box(&sample)))
    });
}

criterion_group! {
    name = benches;
    config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
    targets = norm_sine_benchmark
}

criterion_main!(benches);
@maxcountryman
Copy link

I'm also having this same issue using version 0.9.

@maxcountryman
Copy link

I was able to address this by passing in a --profile-time. This will run the profile (and not do the normal Criterion analysis). Note that if you're using cargo bench then you'll need to invoke the command something like $ cargo bench --bench benchmark -- --profile-time 60. Refer to the Criterion FAQ for more details.

@jiacai2050
Copy link

@maxcountryman Do you know why add profile-time will solve this?

@waynexia
Copy link

@maxcountryman Do you know why add profile-time will solve this?

From criterion's document:

These functions will be called before and after each benchmark when running in --profile-time mode, and will not be called otherwise. This makes it easy to integrate in-process profiling into benchmarks when wanted, without having the profiling instrumentation affect regular benchmark measurements.

To my understanding, criterion is using this option as a switch for the external profiler.

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

4 participants