A flame graph visualizes sampled stack traces as nested horizontal bars, with each function’s width proportional to its share of runtime. It exposes frequently used code paths so performance work can target the largest costs. section 7.7
A practical profiling workflow combines benchmarking with CPU profiling:
- Benchmark representative code with Criterion to obtain statistically reliable runtime measurements. section 7.7
- Configure pprof through Criterion to emit a flame graph, then run the benchmark with a profiling duration. section 7.7
- Inspect proportional function costs and prioritize changes that eliminate work on dominant execution paths. section 7.7
Fibonacci benchmark
A recursive Fibonacci implementation provides a measurable workload: its flame graph shows how runtime is distributed across recursive calls. Comparing recursive, memoized, and iterative implementations connects visible hotspots with progressively lower benchmark times. section 7.7
Listing 7.4 Fibonacci microbenchmark with CPU profiling
use pprof::criterion::{Output, PProfProfiler};
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench
}
criterion_main!(benches);
Inspect the Criterion configuration that attaches pprof’s flame-graph output to the benchmark. section 7.7

