LinuxCommandLibrary

flamegraph

TLDR

Generate flame graph from perf data

$ perf script | stackcollapse-perf.pl | flamegraph.pl > [flame.svg]
copy
From dtrace output
$ stackcollapse.pl [out.dtrace] | flamegraph.pl > [flame.svg]
copy
Custom title
$ flamegraph.pl --title "[My App Profile]" [stacks.txt] > [flame.svg]
copy
Inverted (icicle) graph
$ flamegraph.pl --inverted [stacks.txt] > [flame.svg]
copy
Set width
$ flamegraph.pl --width [1200] [stacks.txt] > [flame.svg]
copy

SYNOPSIS

flamegraph.pl [options] [input]

DESCRIPTION

FlameGraph is a visualization tool for profiled stack traces, created by Brendan Gregg. It generates interactive SVG graphs where the x-axis shows the stack population and the y-axis shows stack depth.
Flame graphs quickly reveal which code paths consume the most resources. They work with any profiler output that can be converted to the collapsed stack format.

PARAMETERS

--title text

Title for the graph.
--width pixels
SVG width (default 1200).
--height pixels
Frame height (default 16).
--minwidth pixels
Minimum width to show.
--inverted
Generate icicle graph (top-down).
--reverse
Reverse stack order.
--colors palette
Color palette: hot, mem, io, java.
--hash
Color by function name hash.
--flamechart
Time-ordered flame chart.

WORKFLOW

$ # 1. Collect profile (Linux perf)
perf record -g ./myapp

# 2. Convert to text stacks
perf script > out.perf

# 3. Collapse stacks
stackcollapse-perf.pl out.perf > stacks.txt

# 4. Generate flame graph
flamegraph.pl stacks.txt > flame.svg
copy

CAVEATS

Requires Perl. Input must be in collapsed stack format. Large profiles may produce complex graphs. Colors are random unless --hash used. Interactive features require SVG-capable browser.

HISTORY

Flame graphs were invented by Brendan Gregg in 2011 while at Joyent for analyzing performance issues. The visualization technique has become standard for performance profiling across languages and platforms.

SEE ALSO

perf(1), dtrace(1), bpftrace(8)

Copied to clipboard