Skip to content

Lesson 5 of 13 · 15m

Profiling in Production at 99 Hz

Frame pointers versus DWARF unwinding, why 99 not 100 Hz, flame graph mechanics, and the off-CPU axis.

A sampling profiler is a timer interrupt that walks the stack. At 99 Hz, a hundred times per second minus one, the CPU stops what it's doing, records the instruction pointer and the call chain, and resumes. Aggregate a few million of those interruptions and you get a statistically honest picture of where cycles actually went — not where the code comments claimed they would go.

The frequency is not a typo. Brendan Gregg's standing advice is to sample at 99 Hz rather than 100 Hz so the probe doesn't land in lockstep with 10 ms timers and per-second housekeeping — a fixed-frequency sampler synchronized with periodic work measures that work and misses everything else. perf record -F 99 -g --call-graph dwarf is the canonical incantation on Linux.

Frame pointers vs. DWARF

Walking the stack is the hard part, and there are two ways to do it. Frame pointers are cheap: every function keeps a pointer to its caller's frame in rbp on x86_64, so unwinding is pointer-chasing. The problem is that gcc and clang default to -fomit-frame-pointer at -O1 and above — that register gets recycled for real work, which buys roughly 1–3% more performance and makes stack walks impossible without another source of truth.

That other source is DWARF .eh_frame unwind metadata, which ships in your binaries anyway. --call-graph dwarf unwinds through it with no recompilation, at the price of more CPU per sample and a 64 KB per-stack copy that truncates deep stacks. The distros have started re-litigating this: Fedora and Ubuntu have pushed to re-enable frame pointers system-wide because profiling a fleet you can't unwind is a fleet you can't debug, and Python 3.12 (October 2023) added sys.activate_stack_trampoline("perf") so perf can see Python frames at all.

JVMs are their own country. async-profiler uses AsyncGetCallTrace — a HotSpot internal API — to unwind Java frames without frame pointers and without requiring -XX:+PreserveFramePointer. The documented caveat is safepoint bias: samples tend to land where the JVM already polls for safepoints, which skews the profile toward allocation-heavy code. Know the bias; it's still the most practical JVM profiler in production.

Flame graphs: width is time

A flame graph's x-axis is sample population, sorted alphabetically, not a timeline. Read the plateaus — the wide tops — for hot leaf frames, and read width ratios between frames for how much time children consume relative to parents. A tall stack is cosmetic. A wide plateau is your bug. flamegraph.pl --negate renders differential flame graphs so a regression diff between Tuesday and Wednesday's profiles colors itself instead of being eyeballed.

On-CPU is half the story

Sampling perf events measures code that is running. Code that is blocked — on locks, on I/O, on a scheduler runqueue — never appears. Off-CPU profiling hooks scheduler sleep/switch events instead; Gregg's off-CPU flame graph work (circa 2015) is the standard method for "the request was slow but nothing was hot." If your flame graph shows a fast system and users still complain, you sampled the wrong axis.

Production shape

Google published the template in 2010: "Google-Wide Profiling: A Continuous Profiling Infrastructure for Data Centers" (Ren et al., IEEE Micro). The modern versions — Parca's agent, Grafana's Pyroscope (acquired by Grafana Labs in March 2024) — are the same design: eBPF or perf-based sampling on every node, a few percent CPU worst case, profiles centralized so you can diff one process or the whole fleet.

Practice

  • Sample at 99 Hz; aggregate centrally; keep profiles long enough to compare deploys.
  • Prefer frame pointers at build time (-fno-omit-frame-pointer) where the 1–3% cost is acceptable; DWARF where it isn't.
  • Run an off-CPU pass when latency complaints outlive hot CPU frames.
  • Expect single-digit-percent overhead; a profiler that costs more than your margin wasn't configured, it was enabled.

Profiling in production isn't reckless; it's the only place the workload is honest.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.