inferno

A Rust implementation of Brendan Gregg's flamegraph stack trace visualiser — generates interactive SVG flamegraphs faster than the original Perl scripts.

inferno is a Rust port of Brendan Gregg's flamegraph Perl scripts. It produces the same interactive SVG flamegraph output as the originals, but significantly faster — making it practical to regenerate flamegraphs in tight profiling loops. It is also the engine behind the popular cargo-flamegraph tool.

Features

  • Drop-in replacement — produces output compatible with the original Perl flamegraph.pl; all the same SVG interactivity (zoom, search, tooltip) is preserved
  • Faster — typically 10–20× faster than the Perl originals on large stack trace inputs
  • inferno-collapse-* — a suite of collapsers that transform raw profiler output (perf, DTrace, sample, VTune, and more) into the folded stack format that inferno-flamegraph consumes
  • inferno-diff-folded — generate a differential flamegraph comparing two profiles side-by-side, colouring frames red (regression) or blue (improvement)
  • inferno-flamechart — produce a flamechart (time-ordered, not sorted) for latency analysis
  • Consistent colour palettes — built-in palettes for Rust, Java, JavaScript, Perl, Python, and more; language is auto-detected from function names
  • Configurable — title, subtitle, colours, image dimensions, and more are all tunable via flags

Installation

cargo install inferno
# Debian / Fedora
# Pre-built Linux binaries are available on the
# [releases page](https://github.com/jonhoo/inferno/releases).

This installs all binaries: inferno-flamegraph, inferno-collapse-perf, inferno-collapse-dtrace, inferno-collapse-sample, inferno-diff-folded, and inferno-flamechart.

Usage

Basic workflow (Linux perf)

# 1. Record a profile with perf
perf record -F 997 -g -- ./my-program
perf script > out.perf

# 2. Collapse the stacks into folded format
inferno-collapse-perf out.perf > stacks.folded

# 3. Generate the flamegraph SVG
inferno-flamegraph stacks.folded > flamegraph.svg

# Open it
xdg-open flamegraph.svg

Basic workflow (macOS DTrace / sample)

# Using DTrace
sudo dtrace -x ustackframes=100 -n \
  'profile-997 /execname == "my-program"/ { @[ustack()] = count(); }' \
  -o out.dtrace

inferno-collapse-dtrace out.dtrace \
  | inferno-flamegraph > flamegraph.svg

# Using the macOS `sample` command
sample my-program 30 -f out.sample
inferno-collapse-sample out.sample \
  | inferno-flamegraph > flamegraph.svg

One-liner with pipes

perf record -g -- ./my-program && \
  perf script \
  | inferno-collapse-perf \
  | inferno-flamegraph > flamegraph.svg

Differential flamegraph

Compare two profiles to visualise regressions and improvements between e.g. a before and after optimisation:

# Profile before and after a change
perf script -i before.perf | inferno-collapse-perf > before.folded
perf script -i after.perf  | inferno-collapse-perf > after.folded

# Generate a diff flamegraph
# Red = slower in "after", Blue = faster in "after"
inferno-diff-folded before.folded after.folded \
  | inferno-flamegraph > diff.svg

Flame chart (time-ordered)

Unlike a flamegraph (which sorts and merges identical stacks), a flame chart preserves time order — useful for spotting latency spikes:

perf script | inferno-collapse-perf --with-time \
  | inferno-flamechart > flamechart.svg

Options

# Set a custom title
inferno-flamegraph --title "My Program — Release Build" stacks.folded > out.svg

# Choose a colour palette
inferno-flamegraph --colors rust stacks.folded > out.svg
inferno-flamegraph --colors java stacks.folded > out.svg
inferno-flamegraph --colors js   stacks.folded > out.svg

# Reverse the flamegraph (icicle graph — root at top)
inferno-flamegraph --inverted stacks.folded > out.svg

# Set minimum frame width (filter out tiny frames)
inferno-flamegraph --min-width 0.5 stacks.folded > out.svg

# Annotate with notes about the profiling context
inferno-flamegraph \
  --title "cargo build --release" \
  --subtitle "perf @ 997Hz, 30s, Intel i9-13900K" \
  stacks.folded > out.svg

Tips

  • Always profile release builds — debug builds are not optimised and will give you a misleading picture. Add debug = true under [profile.release] in Cargo.toml to retain symbol names.
  • Frame pointers — on modern Linux with glibc and a recent kernel, add -C force-frame-pointers=yes to RUSTFLAGS for more accurate call stacks without the overhead of DWARF unwinding.
  • Narrow down hot paths — use the SVG's built-in search (Ctrl+F) to highlight all frames matching a function name across the entire graph.
  • Combine with perf's --call-graph — use perf record -g --call-graph dwarf for the most accurate stacks, at the cost of larger trace files.