Skip to main content
← CONCEPTS / DEVOPS & INFRASTRUCTURE
An end-to-end domain learning journey

eBPF Continuous Profiling &
DWARF Stack Unwinding.

eBPF attaches a 19 Hz perf_event timer hook in the Linux kernel, walks frame pointers or DWARF .eh_frame tables to compute a stack_id, and increments counters in kernel maps for <1% overhead continuous profiling.
Start the journey5 sections· Last modified Nov 28, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

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.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
CPU Profiling & Flame Graphs
Know how sampled call stacks aggregate into flame graphs where bar width equals CPU time share.
eBPF Kernel Maps
Understand that eBPF programs run safely inside the Linux kernel via verified bytecode and share counters with user space via BPF hash maps.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

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).

Profiling Overhead

Raw `perf record` Ring-Buffer Dump vs. eBPF In-Kernel Aggregation

Before · perf record (Raw Stream)
  • Copies 8 KB stack per sample
  • Writes GBs to disk/ringbuf
  • Broken stacks without RBP
After · eBPF 19 Hz + DWARF Maps
  • Aggregates stack_id in kernel
  • Reads tiny summary every 10s
  • Full stacks via .eh_frame (<1% CPU)
02
L4 · FUNDAMENTALS

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.

Kernel-to-Userspace Flow

19 Hz Timer -> eBPF Stack Unwind -> Kernel Map Increment -> 10s Poll

CPU (19 Hz)eBPF UnwinderBPF Stack/CountMapsUser-Space Agent1. perf_event NMI/timer interrupt2. Walk RBP / .eh_frame ->stack_id++3. Poll & swap maps every 10s4. Symbolize RIPs via Build-ID ELF
03
L5 · APPLIED DESIGN

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.

Hybrid Unwinder

Check Frame Pointer -> Fallback to DWARF .eh_frame Map -> JIT/Python Walker

Sampled RIP + RSPingressFrame Pointer (RBP)computeDWARF .eh_frameTablestorageELF Build-IDSymbolizercontrolfast path if RBPbinary search ifomittedresolve func + line
04
L5 · APPLIED DESIGN

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.

Double-Buffered BPF Maps

Sample Into Map A -> Atomic Swap to Map B -> Read & Clear Map A

10s tickzero sample drop10s tickMap A Active (10s)Atomic Global PtrSwapMap B Active +Drain A
Engineering Decision Framework
Problem
How to run continuous production profiling across all services at <1% CPU overhead.
Naive Solution
Run perf record -g at 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 record vs. 19 Hz eBPF in-kernel aggregation + Build-ID symbolization.
Engineering Decision
Use 19 Hz eBPF perf_event sampling with in-kernel stack maps, DWARF .eh_frame fallback, and Build-ID deduplicated symbolization.
Trade-Offs
Requires Linux kernel >=5.4 (or >=5.8 for ringbuf/DWARF maps) and privileged CAP_BPF/CAP_PERFMON DaemonSet permissions.
05
L6 · SCALE & TRADE-OFFS

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.

Profiler Signal Coverage

On-CPU (perf_event) vs. Off-CPU (sched_switch) vs. Heap (uprobe malloc)

On-CPU (19 Hz)Hot Loops & SpinlocksOff-CPU (sched_switch)Mutex & I/O BlockingAlloc (uprobe malloc)Heap Leaks & GC Churn
Decision Exercise · Make the Call

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 · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why do continuous eBPF profilers sample at prime frequencies like 19 Hz or 49 Hz instead of 100 Hz or 1,000 Hz?

Recommended Learning Flow