Chapter 18. 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.
18.1. Installing flamegraphs Copy linkLink copied to clipboard!
You must install the required packages to start using flamegraphs.
Procedure
Install the flamegraphs package:
# dnf install js-d3-flame-graph
18.2. Creating flamegraphs over the entire system Copy linkLink copied to clipboard!
You can visualize performance data recorded over an entire system by using flamegraphs.
Prerequisites
-
flamegraphsare installed as described in Installing flamegraphs. -
The
perftool is installed as described in Installing perf.
Procedure
Record the data and create the visualization.
# perf script flamegraph -a -F 99 sleep 60This command samples and records performance data over the entire system for 60 seconds, as stipulated by use of the
sleepcommand, and then constructs the visualization which is stored in the current active directory asflamegraph.html. The command samples call-graph data by default and takes the same arguments as theperftool, 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:
# xdg-open flamegraph.htmlThis command opens the visualization in the default browser:
18.3. Creating flamegraphs over specific processes Copy linkLink copied to clipboard!
You can use flamegraphs to visualize performance data recorded over specific running processes.
Prerequisites
-
flamegraphsare installed as described in Installing flamegraphs. -
The
perftool is installed as described in Installing perf.
Procedure
Record the data and create the visualization.
# perf script flamegraph -a -F 99 -p ID1,ID2 sleep 60This command samples and records performance data of the processes with the process ID’s
ID1andID2for60seconds, as stipulated by use of thesleepcommand, and then constructs the visualization which will be stored in the current active directory asflamegraph.html. The command samples call-graph data by default and takes the same arguments as theperftool, 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:
# xdg-open flamegraph.htmlThis command opens the visualization in the default browser:
18.4. Analyzing stack traces and function hotspots in flamegraphs Copy linkLink copied to clipboard!
Each box in the flamegraph represents a different function in the stack. The y-axis shows the stack depth. The top box in each stack represents the function that was on-CPU and the remaining boxes represent ancestry. The x-axis displays the population of the sampled call-graph data.
The x-axis sorts functions by sample count, not time. Children appear in descending order of their total samples. Box width represents frequency on-CPU. Wider boxes indicate functions or ancestors captured in more samples.
Procedure
To reveal the names of functions which may have not been displayed previously and further investigate the data, click the 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.
ImportantBoxes representing user-space functions may be labeled as
Unknownin flamegraphs because the binary of the function is stripped. Install thedebuginfopackage or compile your local application with debugging information enabled. Use the-goption in GCC, to display the function names or symbols in such a situation.