Lesson 5 of 13 · 15m
Reading Flame Graphs
Width is samples, the x-axis is alphabetical, and on-CPU plus off-CPU graphs together answer where the time went.
Brendan Gregg built flame graphs at Joyent in 2013 to make sense of stack samples from a fleet full of MySQL instances, and the encoding has not changed because it works. Every box is a function. The y-axis is stack depth. The x-axis is alphabetical order — not time. The width of a box is how many samples it appeared in. Wider means more CPU. That is the whole grammar, and people still misread it as a timeline.
Reading one correctly
Read bottom-up: the widest base frames are the process, each row above is a call, and the top edge is what was running when sampled. The visual skill is hunting width — a wide plateau low in the graph is a common ancestor through which most samples flow; a wide box near the top edge is a leaf doing work itself. The colors are random decoration to separate boxes; they encode nothing.
The search field in flamegraph.pl output highlights matching frames and prints the share of samples they cover — the fastest route to "what fraction of CPU is libc malloc" without arithmetic.
On-CPU and off-CPU are different graphs
A CPU flame graph answers "what is the CPU doing." It says nothing about time spent blocked — a thread parked in futex_wait produces no samples. Off-CPU flame graphs invert the question: aggregate the kernel stacks of threads at the moment they deschedule, and the wide frames are where your latency went. Gregg's offcputime from the bcc toolkit collects exactly that. Real slowdowns need both views: on-CPU for where compute goes, off-CPU for where waiting goes.
Differential flame graphs are the third variant — two profiles folded together, colored red where the new one grew and blue where it shrank. For "the deploy made it slower," a red/blue graph beats eyeballing two SVGs.
Producing them
perf record -F 99 -a -g -- sleep 30
perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > cpu.svgstackcollapse-perf.pl folds samples into frame;frame;frame count lines and flamegraph.pl renders them; both ship in Gregg's FlameGraph repo. The same pipeline takes offcputime-bpfcc -f output for the off-CPU side. Firefox Profiler and speedscope both import the folded format if you want a better viewer than a static SVG.
The shapes that mean something
A wide plateau mid-graph is a shared ancestor — everything flowing through it costs what it costs. That is the difference between "optimize read_input" (a leaf to speed up) and "restructure handle_request" (a path to redesign). Tall thin towers are deep recursion or layered frameworks: rarely the bottleneck, often the readability problem. And width is a share of samples, never a cost — a frame covering 30% of a profile taken on an idle process is 30% of nothing. Icicle graphs invert the y-axis (root on top); some tools default to that orientation, so orient before reading. difffolded.pl in the same repo renders the differential: fold a baseline and a suspect profile, diff them, and the red frames are the regression.
Evidence
The canonical story is the origin itself: the first flame graphs surfaced a code path that had been misattributed as a CPU problem for weeks — a wide frame of cleanup work nobody knew existed, found in minutes. The format spread because a picture of ten thousand stacks beats ten thousand stacks.
The practice
- Wide beats tall: chase width on the top edge and wide plateaus below, not depth.
- Pair on-CPU and off-CPU graphs before concluding where time goes.
- Use search to quantify a suspect frame's share of samples.
- Never read the x-axis as time. It is alphabetical by design, and the colors mean nothing.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Minecraft Server Isn't Slow, It's Misconfigured
Can't keep up! is not a hardware message. It's the server telling you a tick took longer than 50ms, and almost every cause is a default nobody changed. Here's what actually moves MSPT, with the flags that are now wrong and the setting that isn't where every guide says it is.
Your Minecraft Server Wants Java 25, Not Java 26
Every six months the same thread appears and nobody maps the JVM engineering onto what a Minecraft server actually does. This does — version by version, with the flag most guides still tell you to set that will eventually stop your server from booting.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
How to Debug Minecraft Server Lag with Spark Profiler (2026 Guide)
Your server dropped to 12 TPS. You copied Aikar's flags. You upgraded Java. Nothing changed. That's because JVM flags don't fix plugin bugs. Here's how to find what's actually killing your tick budget.