Lesson 26: perf, Flamegraphs & Capstone — TCP Echo Server
perf is the standard profiling tool on Linux: it measures CPU cycles, cache misses, branch mispredictions, and system calls. Flamegraphs convert its output into an intuitive visualisation. In the capstone section we build a multi-threaded TCP echo server in C++ that combines all course concepts.
perf is like a doctor listening to the program's heartbeat: it samples what the CPU is doing every few microseconds and shows you where time is wasted.
- perf stat
- perf mode that runs a program and reports basic performance metrics: cycles, instructions, cache-misses, branch-misses, context-switches. A quick diagnostic tool.
- perf record
- perf mode that samples the program's call stack and saves to perf.data. Used afterwards with perf report or flamegraph.
- flamegraph
- CPU profile visualisation: X axis = CPU time (width = cost), Y axis = call stack depth. Each rectangle = a function. Wide peaks = hotspots.
- IPC (Instructions Per Cycle)
- CPU efficiency metric: how many instructions execute per clock cycle on average. IPC < 1 signals pipeline stalls (memory bound). IPC ≈ 3-4 for well-optimised code.
- capstone project
- A project that integrates several topics taught in the course. In this lesson: multi-threaded C++ TCP echo server using sockets, threads, mutexes, and epoll.