Profiling & flamegraphs
perf, eBPF tools (bcc/bpftrace), CPU vs off-CPU flamegraphs, continuous profiling. Reading a flamegraph live is a signature senior-SRE interview moment.
The mental model
A profiler with a flamegraph is a census, not a stopwatch. Instead of timing functions one by one, you interrupt the program ~99 times a second and ask a single question: "what is your full call stack right now?" Collect tens of thousands of these answers, merge identical stacks, and draw them: the x-axis is proportion of samples (not time order — a common misreading), the y-axis is stack depth, and the width of any frame is the fraction of samples in which that function was on the stack. Wide towers are where the time lives.
Why this exists: humans are reliably wrong about where programs spend time. Decades of profiling practice show that engineers' guesses about hot spots miss badly and expensively — you optimize the clever algorithm while 40% of cycles go to a JSON re-serialization someone added in a logging call. Without profiles, performance work is faith-based: you change code, benchmark, and attribute improvements to whatever you believe in. With profiles, a regression has a name and a line number.
The model has one crucial fork: on-CPU versus off-CPU. A CPU profile samples only threads that are running; a service that is slow because it is waiting — on locks, disk, the network, the scheduler — is invisible to it. The complementary technique, off-CPU analysis, measures time spent blocked and what the thread was blocked on. The senior-level reflex is choosing the right one from the symptom: high CPU + high latency → CPU flamegraph; low CPU + high latency → off-CPU analysis. Bringing a CPU profile to a lock-contention fight is the classic mid-level mistake, and interviewers probe it deliberately.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision