Reading Flame Graphs
Flame graphs are a visualization tool for profiling software. They provide a graphical representation of your program’s execution, making it easier to understand the runtime complexities involved. Let’s start with an example:
- The root caller is the
app
function. app
calls theinit
,handleRequest
andterminate
functions.handleRequest
calls bothauthenticateUser
andprocessData
.processData
callsfoo
which in turn callsbar
.
Aggregated function calls
Functions calls are aggregated, so if a function is called multiple times, the time spent in all calls is aggregated into a single block. Thus, the following code:
foo
function is called twice and the bar
function is called 4
times, but the time spent is aggregated into a single block for each function.
Self-costs
In the previous example, we could see the global cost of each function call quite clearly. However, it can be tricky to find out how much time was spent within the function itself.
- (implicit) self-costs: the time spent in the function itself is the whole width of the rectangle since it doesn’t call any other functions.
- self-costs: the self-cost here is visible as the space not occupied by the children of the block.
Self-costs in interpreted languagesIn Python or Node.js, the self-cost is the time spent in the function itself,
but also the time spent by the interpreter. This means that a function will
always have a self-cost, even if the function does nothing.
main
being
much bigger than before:

Viewing Flame Graphs
On the pull request page, you can access the flame graphs of a benchmark by expanding it.
Example of flame graphs on a pull request page
- Base: flame graph of the benchmark base run
- Head: flame graph of the benchmark run from the latest commit of the pull request
- Diff: difference between the head and the base flame graphs
FFI SupportIf you’re using
Foreign Function Interface,
typically calling C/C++/Rust code from Python or Node.js, make sure to generate
debug symbols for the foreign functions so that you can see them in the flame
graph.
Pre-requisites
- Node.js: Node 16 or higher, and the following minimum versions of the integrations
- Python: Python 3.12 or higher and
pytest-codspeed>=2.0.0
- Rust: Trace generation is enabled by default with any version of the integration library
- C++: Trace generation is enabled by default with any version of the integration library