Stackdriver Profiler displays profiling data by using Flame Graphs. Unlike trees and graphs, flame graphs make efficient use of screen space by representing a large amount of information in a compact and readable format.
To introduce flame graphs, this page illustrates how to convert a tree into a flame graph and summarizes key features of flame graphs.
Creating a flame graph
To create a flame graph from a tree, complete the steps illustrated in the following diagram:
Remove from the tree the arrows that indicate function calls.
Replace each tree node with a frame.
Frames are rectangular in shape and all frames have the same height. For the example on this page, the total CPU usage of the function named in the frame determines the frame width.
The pseudo code for each of the functions is described in the following table. The CPU intensive work performed during a function's execution defines the self CPU usage:
Function pseudo code self CPU usage
total CPU usage
func main(): foo1() foo2() // CPU intensive work // for 2 seconds
2 4 + 3 + 2 = 9
func foo1(): bar() // CPU intensive work // for 1.5 seconds
1.5 2.5 + 1.5 = 4
func foo2(): bar() // CPU intensive work // for 0.5 seconds
0.5 2.5 + 0.5 = 3
func bar(): // CPU intensive work // for 2.5 seconds
The next step is to remove the vertical space between the frames and left align frames while preserving call sequences. Optionally, you can define a color scheme and color the frames according to the definition. For example, you can color frames by their package, by total CPU usage, by self CPU usage, or by a different measure.
After removing excess white space and coloring frames by the self CPU usage, the flame graph now appears as follows:
Notice that the call stacks for
foo2have been preserved, even though the call stack starting with
foo2is now adjacent to the frame for
This simple example illustrates the following:
- Flame graphs are a compact representation of a tree and you can recreate a call stack by tracing frames from the top downwards.
- Frames name a function and the frame width is the relative measure
of that function's total CPU usage.
In this example, because the total CPU usage of
foo2is one third of the total CPU usage of
main, the frame for
foo2is one third the width of the frame for
- The width of the empty space below a frame is the relative measure of
the self CPU usage for the function named in the frame.
For example, below the frame
foo1, 1.5 units are empty and 2.5 units are occupied by
bar. Therefore the self CPU usage of
foo1is 37.5% of its total CPU usage, or 1.5s.
As you follow a call stack, the width of the frames decrease because the total CPU usage of a callee can never be more than the total CPU usage of the caller. This behavior is what causes the flame shape.
In the example,
barand the total CPU of
foo1is defined to be the total CPU of
barplus the self CPU of
foo1. Therefore, the total CPU of
barcannot be more than the total CPU of
- For information on the supported operating environments, languages, and performance impact of Stackdriver Profiler, go to About Stackdriver Profiler.
- For an introduction to profiling, go to Profiling concepts.
- For details on the Stackdriver Profiler interface, go to Using the Stackdriver Profiler interface.
- To get started, try the Stackdriver Profiler Quickstart.