When profiling heterogeneous production fleets, aggregate `stack_id` counts in kernel BPF maps and use DWARF `.eh_frame` tables for stripped binaries.
TL;DR30-second simplified summary▾
19 Hz prime sampling avoids harmonic aliasing, in-kernel stack_id maps cut transfer >1,000x, and DWARF .eh_frame maps unwind -O2 binaries without frame pointers.
P · Problem & Why `perf record` and In-Process Profilers Fail at Fleet Scale.
Traditional perf record streams every raw sample (regs + 8 KB stack copy) from kernel ring buffers to disk, burning I/O and CPU.
Worse, in-process language profilers (like Python cProfile or JVM TI) require per-language SDKs, miss native C/C++/Rust/kernel frames, and can add 3–15% overhead. Meanwhile, perf with frame-pointer unwinding breaks ([unknown]) on Linux binaries compiled with -fomit-frame-pointer (the historical default for GCC/Clang -O2).
Raw `perf record` Ring-Buffer Dump vs. eBPF In-Kernel Aggregation
- Copies 8 KB stack per sample
- Writes GBs to disk/ringbuf
- Broken stacks without RBP
- Aggregates stack_id in kernel
- Reads tiny summary every 10s
- Full stacks via .eh_frame (<1% CPU)
R · Representation: `perf_event` + `BPF_MAP_TYPE_STACK_TRACE`.
Every 52.6 ms (19 Hz per core), the Linux perf_event subsystem triggers an eBPF program on whatever thread is currently on-CPU.
The eBPF program calls bpf_get_stackid(ctx, &stack_map, BPF_F_USER_STACK) (or runs a custom DWARF unwinder), hashes the array of instruction pointers into a 32-bit stack_id, and increments counts[{pid, tgid, stack_id}] += 1 inside a BPF_MAP_TYPE_HASH.
19 Hz Timer -> eBPF Stack Unwind -> Kernel Map Increment -> 10s Poll
I · Invariant: Frame-Pointer vs. DWARF `.eh_frame` Unwinding.
With frame pointers (-fno-omit-frame-pointer), unwinding is a 3-line pointer chase: next_rip = *(rbp + 8); next_rbp = *(rbp).
Without frame pointers, compilers emit .eh_frame DWARF tables mapping each instruction address range [pc_start, pc_end] to a rule like CFA = RSP + 48; RIP = *(CFA - 8). User space parses .eh_frame once per binary, sorts the compact (pc_offset, cfa_offset, rbp_offset) rows into a BPF map, and the eBPF unwinder binary-searches it up to 128 frames deep using BPF tail calls.
Check Frame Pointer -> Fallback to DWARF .eh_frame Map -> JIT/Python Walker
M · Mechanics at Scale: Build-ID Symbolization & Map Rotation.
Raw stack traces only contain virtual memory addresses (0x7f4a2c1084). Translating them to process_order+0x24 requires reading /proc/<pid>/maps and the binary's ELF symbol table.
Every Linux ELF binary embeds a unique SHA-1/256 Build-ID in .note.gnu.build-id. Agents hash /proc/<pid>/maps once per binary, upload debug symbols once per Build-ID (deduplicated across 10,000 pods!), and use double-buffered eBPF maps (active_map vs draining_map) so resetting counters every 10s never drops in-flight samples.
Sample Into Map A -> Atomic Swap to Map B -> Read & Clear Map A
- Problem
- How to run continuous production profiling across all services at <1% CPU overhead.
- Naive Solution
- Run
perf record -gat 999 Hz or enable per-function tracing hooks. - Why It Fails
- High-frequency raw dumps burn 5–10% CPU and GBs of disk; tracing hooks skew micro-function latency.
- Alternatives
- In-process SDK profilers vs.
perf recordvs. 19 Hz eBPF in-kernel aggregation + Build-ID symbolization. - Engineering Decision
- Use 19 Hz eBPF
perf_eventsampling with in-kernel stack maps, DWARF.eh_framefallback, and Build-ID deduplicated symbolization. - Trade-Offs
- Requires Linux kernel >=5.4 (or >=5.8 for ringbuf/DWARF maps) and privileged
CAP_BPF/CAP_PERFMONDaemonSet permissions.
E · Edge Cases, Assumptions & When NOT to Use 19 Hz Sampling.
perf_event CPU sampling only fires on threads actively running on a CPU core—it is blind to Off-CPU time (mutex contention, disk fsync, or slow network epoll_wait).
When NOT to rely solely on 19 Hz CPU sampling: (1) If latency spikes are caused by lock contention or I/O waits, pair CPU sampling with eBPF sched_switch Off-CPU profiling; (2) If a stripped production binary had both .symtab and .eh_frame stripped and no debuginfo package was uploaded, user space can only render raw hex addresses.
On-CPU (perf_event) vs. Off-CPU (sched_switch) vs. Heap (uprobe malloc)
Your service p99 latency spikes to 800 ms, yet your 19 Hz eBPF CPU flame graph shows the service using only 5% CPU with no hot functions. What is happening and how do you diagnose it?
Practice: Make the trade-off yourself.
Why do continuous eBPF profilers sample at prime frequencies like 19 Hz or 49 Hz instead of 100 Hz or 1,000 Hz?