liveBook · Manning

Flame graph

As explained in Latency

FlameGraph profiling is a visualization-based profiling technique that represents hierarchical sampled execution costs as nested horizontal bars.

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

How Latency covers it

How deep it goes
Explains proportional stack-trace visualization and a profiling workflow, without detailing flame-graph rendering internals.
Examples
Uses recursive Fibonacci, memoization, iteration, Criterion measurements, and a generated performance flame graph.
What it assumes
Assumes Rust code and introduces benchmarking and profiling through Criterion rather than requiring prior flame-graph knowledge.
What you can do after
Diagnose costly execution paths by profiling Rust benchmarks with Criterion and pprof.
How it connects
Connects flame graphs with Criterion benchmarking, CPU profiling, stack traces, and performance optimization.

Also explained in

Compare how 2 books explain flame graph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.