skills/flamegraphs/SKILL.md
Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.
npx skillsauth add awfixers-stuff/opencode-config flamegraphsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through the pipeline from profiler data to SVG flamegraph, and teach interpretation of flamegraphs to drive concrete optimisation decisions.
git clone https://github.com/brendangregg/FlameGraph
# No install needed; scripts are in the repo
export PATH=$PATH:/path/to/FlameGraph
# Step 1: record
perf record -F 999 -g -o perf.data ./prog
# Step 2: generate script output
perf script -i perf.data > out.perf
# Step 3: collapse stacks
stackcollapse-perf.pl out.perf > out.folded
# Step 4: generate SVG
flamegraph.pl out.folded > flamegraph.svg
# Step 5: view
xdg-open flamegraph.svg # Linux
open flamegraph.svg # macOS
One-liner:
perf record -F 999 -g ./prog && perf script | stackcollapse-perf.pl | flamegraph.pl > fg.svg
# Collect two profiles
perf record -g -o before.data ./prog_old
perf record -g -o after.data ./prog_new
# Collapse
perf script -i before.data | stackcollapse-perf.pl > before.folded
perf script -i after.data | stackcollapse-perf.pl > after.folded
# Diff (red = regressed, blue = improved)
difffolded.pl before.folded after.folded | flamegraph.pl > diff.svg
valgrind --tool=callgrind --callgrind-out-file=cg.out ./prog
stackcollapse-callgrind.pl cg.out | flamegraph.pl > fg.svg
# Go pprof
go tool pprof -raw -output=prof.txt prog
stackcollapse-go.pl prof.txt | flamegraph.pl > fg.svg
# DTrace
dtrace -x ustackframes=100 -n 'profile-99 /execname=="prog"/ { @[ustack()] = count(); }' \
-o out.stacks sleep 10
stackcollapse.pl out.stacks | flamegraph.pl > fg.svg
# Java (async-profiler)
async-profiler -d 30 -f out.collapsed PID
flamegraph.pl out.collapsed > fg.svg
A flamegraph is a call-stack visualisation:
What to look for:
| Pattern | Meaning | Action | |---------|---------|--------| | Wide frame near bottom | Function itself is hot | Optimise that function | | Wide frame with tall narrow towers | Calling many different callees | Hot dispatch; reduce call overhead | | Very tall stack with wide base | Deep recursion | Check recursion depth; consider iterative approach | | Plateau at the top | Leaf function with no callees | This leaf is the actual hotspot | | Many narrow identical stacks | Many threads doing the same work | Consider parallelism or batching |
Identifying the actionable hotspot:
Differential flamegraph:
flamegraph.pl --title "My App" \
--subtitle "Release build, workload X" \
--width 1600 \
--height 16 \
--minwidth 0.5 \
--colors java \
out.folded > fg.svg
| Option | Effect |
|--------|--------|
| --title | SVG title |
| --width | Width in pixels |
| --height | Frame height in pixels |
| --minwidth | Omit frames < N% (reduces clutter) |
| --colors | Palette: hot (default), mem, io, java, js, perl, red, green, blue |
| --inverted | Icicle chart (roots at top) |
| --reverse | Reverse stacks |
| --cp | Consistent palette (same frame = same color across SVGs) |
For tool installation, stackcollapse scripts, and palette options, see references/tools.md.
skills/profilers/linux-perf to collect perf dataskills/profilers/valgrind to collect Callgrind dataskills/compilers/clang for LLVM PGO from sampling profilesdevelopment
Use when starting dev servers, watchers, tilt, or any process expected to outlive the conversation. Provides zmx session management patterns for long-lived processes.
development
Zig testing skill for writing and running tests. Use when using zig build test, writing comptime tests, using test filters, working with test allocators to detect leaks, or using Zig's built-in fuzz testing (0.14+). Activates on queries about Zig tests, zig test, zig build test, comptime testing, test allocators, Zig fuzz testing, or detecting memory leaks in Zig tests.
development
Zig debugging skill. Use when debugging Zig programs with GDB or LLDB, interpreting Zig runtime panics, using std.debug.print for tracing, configuring debug builds, or debugging Zig programs in VS Code. Activates on queries about debugging Zig, Zig panics, zig gdb, zig lldb, std.debug.print, Zig stack traces, or Zig error return traces.
tools
Zig cross-compilation skill. Use when cross-compiling Zig programs to different targets, using Zig's built-in cross-compilation for embedded, WASM, Windows, ARM, or using zig cc to cross-compile C code without a system cross-toolchain. Activates on queries about Zig cross-compilation, zig target triples, zig cc cross-compile, Zig embedded targets, or Zig WASM.