Skip to content
Latchkey

FlameGraph: Turn perf Samples into an SVG

The FlameGraph scripts collapse stack samples from perf (or other profilers) into a folded format and render them as an interactive SVG flame graph.

A flame graph makes a profile readable at a glance: wide frames are where time goes. The FlameGraph Perl scripts turn perf output into that SVG.

What it does

The pipeline is: perf script exports raw samples, stackcollapse-perf.pl folds identical stacks into single lines with counts, and flamegraph.pl renders the folded data as an SVG where width is proportional to sampled time.

Common usage

Terminal
perf record -F 99 -g -- ./my-program
perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > flame.svg
# CPU flame graph title and color
perf script | ./stackcollapse-perf.pl \
  | ./flamegraph.pl --title "CPU" --colors hot > flame.svg

Options

Tool / FlagWhat it does
stackcollapse-perf.plFold perf script output into per-stack counts
flamegraph.plRender folded stacks as an SVG
--title <text>Set the flame graph title
--colors <scheme>Color palette (hot, mem, io, java, ...)
--width <px>Output image width

In CI

Generate flame.svg from perf.data and upload it as an artifact so reviewers can open it in a browser. Ensure the profiled binary keeps symbols (unstripped, or with debuginfo) or the graph shows raw addresses.

Common errors in CI

Frames labeled as hex addresses or "[unknown]" mean missing symbols; build with -fno-omit-frame-pointer and keep debug info, or record with --call-graph dwarf. An empty SVG means perf script produced nothing, usually because perf record captured no samples (paranoid settings or an early exit). "perf script: command not found" means the perf tools package is incomplete.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →