Watching a live machine: perf, strace and flame graphs

: a running program on one side, the kernel on the other, and the doors between them. This lesson watches both sides of that line while the program is alive.
Brendan Gregg was looking at a MySQL database that used more processor time than it should. He had the usual tools. They gave him what he later called walls of text: page after page of lines, and no way to see which few lines mattered. So he built a new picture from the same data, and he released it in December 2011 as the flame graph. One page of coloured boxes now answers the question he could not answer from the text.
By the end of this lesson you will be able to take a slow running program, find where its time goes with a sampling profile and a flame graph, and find what it asks the kernel for with strace.
The history (optional)
Gregg’s own page on flame graphs says he invented them while working on a MySQL performance problem. Regular profilers and tracers had produced walls of text. He first traced every function call, but the cost of tracing was too high and the output too dense. He switched to taking samples on a timer, dropped time from the sideways axis, and sorted the samples so that matching boxes merged. He chose warm colours, and because the result looked like flames, the name stuck. The page says flame graphs were released in December 2011. He wrote the idea up as “The Flame Graph” in Communications of the ACM in May 2016. Nothing later in this lesson depends on this history.
Before you start. Processes, Threads & the Kernel gave you the process, the kernel, and the system call: the request a program makes when it needs the kernel to do something for it. Everything is a file descriptor gave you the small numbers (file descriptors) that a program passes to read and write. The tap on the shoulder showed the kernel interrupting a running program with a signal, and this lesson uses that same tap to take samples. From text to machine code: compilers, interpreters and the JIT showed how a line of code becomes steps, so you know that a call to a function is one step inside another function.