//! This is a simple Criterion Profiler implementation using pprof. //! //! It's mostly a direct copy from here: https://www.jibbow.com/posts/criterion-flamegraphs/ use std::{fs::File, os::raw::c_int, path::Path}; use criterion::profiler::Profiler; use pprof::ProfilerGuard; /// Small custom profiler that can be used with Criterion to create a flamegraph /// for benchmarks. Also see [the Criterion documentation on /// this][custom-profiler]. /// /// ## Example on how to enable the custom profiler: /// /// ``` /// mod perf; /// use perf::FlamegraphProfiler; /// /// fn fibonacci_profiled(criterion: &mut Criterion) { /// // Use the criterion struct as normal here. /// } /// /// fn custom() -> Criterion { /// Criterion::default().with_profiler(FlamegraphProfiler::new()) /// } /// /// criterion_group! { /// name = benches; /// config = custom(); /// targets = fibonacci_profiled /// } /// ``` /// /// The neat thing about this is that it will sample _only_ the benchmark, and /// not other stuff like the setup process. /// /// Further, it will only kick in if `--profile-time