Flame graphs

Cloud Profiler displays profiling data by usingFlame Graphs. Unlike trees and graphs,flame graphs make efficient use of screen space by representing a large amountof information in a compact and readable format.

To introduce flame graphs, this page illustrates how to convert a treeinto 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 thefollowing diagram:

Creating a flame graph.

  1. Remove from the tree the arrows that indicate function calls.

  2. Replace each tree node with aframe.

    Frames are rectangular in shape and all frames have the same height.For the example on this page, the total CPU time used by the function namedin the frame determines the frame width.

    Key Point:In profiling, a functions'total CPU time is the CPU time used by the functionincluding the CPU time used by all functions it calls. A function'sself CPU time is the CPU time used by afunction excluding the CPU time used by the functions it calls.

    The pseudo code for each of the functions is described in the followingtable. The CPU intensive work performed during a function's executiondefines the self CPU time:

    Function pseudo codeself CPU time
    (seconds)
    total CPU time
    (seconds)
    func main():     foo1()     foo2()     // CPU intensive work     // for 2 seconds
    24 + 3 + 2 = 9
    func foo1():     bar()     // CPU intensive work     // for 1.5 seconds
    1.52.5 + 1.5 = 4
    func foo2():     bar()     // CPU intensive work     // for 0.5 seconds
    0.52.5 + 0.5 = 3
    func bar():     // CPU intensive work     // for 2.5 seconds
    2.52.5

  3. The next step is to remove thevertical space between the framesand left align frames while preserving call sequences.Optionally, you can define a color scheme and color the frames accordingto the definition. For example, you can color frames by their package,by total CPU time, by self CPU time, or by a different measure.

    After removing excess whitespace and coloring frames by the selfCPU time, the flame graph now appears as follows:

    Detailed image of the flame graph.

    Notice that the call stacks forfoo1 andfoo2have been preserved, even though the call stack starting withfoo2 isnow next to the frame forfoo1.

Summary

This simple example illustrates the following:

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.