tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.26k stars 94 forks source link

SIGTRAP With Criterion and Flamegraph Features #237

Open ShiromMakkad opened 7 months ago

ShiromMakkad commented 7 months ago

I found this crate from this article: https://www.jibbow.com/posts/criterion-flamegraphs/, which it seems you've implemented as the criterion feature flag. I've found a bug and tested it on both the example code from the article and the criterion feature flag and I'm getting the same issue.

Here's the error:

Benchmarking is_authorized/10: Profiling for 5.0000 serror: bench failed, to rerun pass `--bench is_authorized`

Caused by:
  process didn't exit successfully: `/Users/smakkad/local workplace/local_agent/cedar-local-agent/target/release/deps/is_authorized-0aa3e8a693af2a5a --profile-time 5 --bench` (signal: 5, SIGTRAP: trace/breakpoint trap)

And my code:

const NUM_POLICIES_ARR: [u32; 3] = [10, 100, 1000];

fn is_authorized_benchmark(c: &mut Criterion) {
    let mut bench_group = c.benchmark_group("is_authorized");
    for i in NUM_POLICIES_ARR.iter() {
        let authorizer: Authorizer<PolicySetProvider, EntityProvider> = construct_authorizer(*i);
        let request = construct_request();
        validate_request(&authorizer, &request);

        let input = (request, Entities::empty());
        bench_group.bench_with_input(BenchmarkId::from_parameter(i), &input, |b, i| {
            let (request, entities) = i;
            b.to_async(tokio::runtime::Runtime::new().unwrap())
                .iter(|| async { authorizer.is_authorized(request, entities).await.unwrap() })
        });
    }
}

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

I am running with --profile-time 5.

ShiromMakkad commented 7 months ago

I also get a sigtrap if the frequency is set too high even without criterion integration

ShiromMakkad commented 7 months ago

Here is an exact copy of the code: https://github.com/cedar-policy/cedar-local-agent/blob/main/benches/is_authorized.rs

tjade273 commented 5 months ago

I'm getting a SIGTRAP in similar circumstances, with every frequency value

tareknaser commented 4 months ago

Did you guys find a way around this?

ShiromMakkad commented 4 months ago

I use this: https://github.com/flamegraph-rs/flamegraph. It doesn't have a high sampling frequency though. Wasn't able to resolve that issue.

tareknaser commented 4 months ago

Did you set it up with criterion?

ShiromMakkad commented 4 months ago

There's a CLI arg that you can use to run a criterion benchmark. I used that.

tareknaser commented 4 months ago

yes got it. thanks!

flyingsilverfin commented 3 months ago

I'm also seeing this, particularly on ARM mac machines - a linux VM seems be run fine.

ShiromMakkad commented 2 months ago

I tested this on an M1 Mac pro, so that could be it.

systemsoverload commented 1 month ago

+1 same issue on M1 mac here

guergabo commented 2 weeks ago

+1 same issue on M1 mac here, but it only happens when I use Mutex.