Jump to content

Draft:Flamegraph

From Wikipedia, the free encyclopedia

Flamegraphs

[edit]

Flamegraphs are a visualization tool, akin to line graphs and bar charts. They can be used to represent any hierarchical tree-like data, such as a file system. However, the primary purpose of a flamegraph is to visualize software performance. Created by Brendan Gregg[1], flamegraphs have become a popular tool for developers to figure out bottlenecks in a system in an intuitive manner.

An example of a flamegraph
An example of a flamegraph

Structure

[edit]

The primary type of flamegraph is a CPU flamegraph. Stack traces are collected by performing statistical profile sampling on a process. For instance, in Java, this is often accomplished using the Java Flight Recorder.

By collecting enough of these stack traces, a hierarchical tree structure can be built. The width of each node in the tree corresponds to the proportion of times that specific node appears relative to the total number of stack traces, providing an approximate estimate of CPU percentage consumption.

The flamegraph displays this tree as a series of stacked horizontal bars with varying widths, enabling an intuitive visualization of CPU usage across the entire system and all collected stack traces.

For example, consider building a flamegraph from these two stack traces:

  • Stack 1: Function A -> Function B -> Function C
  • Stack 2: Function A -> Function B -> Function D

These stack traces create a tree structure that could be represented as follows:

A (100% CPU)
└── B (100% of CPU)
    ├── C (50% of CPU)
    └── D (50% of CPU)

References

[edit]