Chapter 27. Getting started with flamegraphs
Chapter 27. Getting started with flamegraphs As a system administrator, you can use flamegraphs to create visualizations of system performance data recorded with the perf tool. As a software developer, you can use flamegraphs to create visualizations of application performance data recorded with the perf tool. Sampling stack traces is a common technique for profiling CPU performance with the perf tool. Unfortunately, the results of profiling stack traces with perf can be extremely verbose and labor-intensive to analyze. flamegraphs are visualizations created from data recorded with perf to make identifying hot code-paths faster and easier. 27.1. Installing flamegraphs To begin using flamegraphs , install the required package. Procedure Install the flamegraphs package: 27.2. Creating flamegraphs over the entire system This procedure describes how to visualize performance data recorded over an entire system using flamegraphs . Prerequisites flamegraphs are installed as described in installing flamegraphs . The perf tool is installed as described in installing perf . Procedure Record the data and create the visualization: This command samples and records performance data over the entire system for 60 seconds, as stipulated by use of the sleep command, and then constructs the visualization which will be stored in the current active directory as flamegraph.html . The command samples call-graph data by default and takes the same arguments as the perf tool, in this particular case: -a Stipulates to record data over the entire system. -F To set the sampling frequency per second. Verification For analysis, view the generated visualization: This command opens the visualization in the default browser: 27.3. Creating flamegraphs over specific processes You can use flamegraphs to visualize performance data recorded over specific running processes. Prerequisites flamegraphs are installed as described in installing flamegraphs . The perf tool is installed as described in installing perf . Procedure Record the data and create the visualization: This command samples and records performance data of the processes with the process ID's ID1 and ID2 for 60 seconds, as stipulated by use of the sleep command, and then constructs the visualization which will be stored in the current active directory as flamegraph.html . The command samples call-graph data by default and takes the same arguments as the perf tool, in this particular case: -a Stipulates to record data over the entire system. -F To set the sampling frequency per second. -p To stipulate specific process ID's to sample and record data over. Verification For analysis, view the generated visualization: This command opens the visualization in the default browser: 27.4. Interpreting flamegraphs Each box in the flamegraph represents a different function in the stack. The y-axis shows the depth of the stack with the topmost box in each stack being the function that was actually on-CPU and everything below it being ancestry. The x-axis displays the population of the sampled call-graph data. The children of a stack in a given row are displayed based on the number of samples taken of each respective function in descending order along the x-axis; the x-axis does not represent the passing of time. The wider an individual box is, the more frequent it was on-CPU or part of an on-CPU ancestry at the time the data was being sampled. Procedure To reveal the names of functions which may have not been displayed previously and further investigate the data click on a box within the flamegraph to zoom into the stack at that given location: To return to the default view of the flamegraph, click Reset Zoom . Important Boxes representing user-space functions may be labeled as Unknown in flamegraphs because the binary of the function is stripped. The debuginfo package of the executable must be installed or, if the executable is a locally developed application, the application must be compiled with debugging information. Use the -g option in GCC, to display the function names or symbols in such a situation. Additional resources Why perf displays some function names as raw functions addresses Enabling debugging with debugging information
yum install js-d3-flame-graph perf script flamegraph -a -F 99 sleep 60 xdg-open flamegraph.html perf script flamegraph -a -F 99 -p ID1,ID2 sleep 60 xdg-open flamegraph.html