Flame graph sandwich view mode: what it is and how to use it
This post was originally published on pyroscope.io. Grafana Labs acquired Pyroscope in 2023.
What is sandwich view?
Sandwich view is a mode of viewing flame graphs popularized by Jamie Wong in the Speedscope project. Its function is relatively simple: The typical flame graph will break down resource utilization by function, but it can be difficult to see how much time is spent in the function itself versus how much time is spent in the functions it calls. Sandwich view solves this problem by splitting a flame graph into two sections:
- Callers: the functions that called the function in question (its “parents”)
- Callees: the functions that the function in question called (its “children”)
Finding performance issues with standard flame graph mode
A typical use case for leveraging flame graphs is to identify opportunities for optimization. With a typical flame graph the most common workflow is to identify a function node that has the largest width and then to look at the functions it calls to see if there are any low hanging fruit for optimization. For example, in the flame graph below, we can see that the rideshare/car.OrderCar
is the largest function in terms of width and thus a good place to start looking for opportunities for optimization.
EMBED
Finding performance issues with sandwich view flame graph mode
However, you’ll also notice that Time.Since()
shows up frequently towards the end of almost every path.
Sandwich view helps you focus in on functions like this to analyze your application and determine if it’s easier to optimize:
Time.Since()
: A node with a shorter width that gets called frequently across many code paths discovered with sandwich view.rideshare/car.OrderCar
: A node with a longer width, that gets called infrequently in a single code path discovered with standard flame graph view.
How to use sandwich view for your flame graphs
If you want to try it out simply go to your Pyroscope UI or upload a flame graph to flamegraph.com and select the “sandwich view” icon in the new flame graph toolbar:
Then you can select a function to see its callers and callees. We have many more view modes planned for the future, so stay tuned or let us know what you’d like to see!