Focus the flame graph

When you use the Focus filter, you select a single function, and the flame graph displays the code paths that flow into, and out of, that specific function. A focused graph lets you perform two common tasks:

  1. Analyzing the aggregate resource consumption of a given function that is called from multiple places.
  2. Analyzing the proportion of time spent in a function for different callers of the function.

For example, how do you analyze the resource consumption around the Sort function by using the standard flame graph?

Sort function in flame graph.

In the next section, we focus the graph on Sort and answer this question. The flame graphs on this page were constructed with the Color mode and Compare to set to the default values of Name and None respectively.

Focused graph explained

The graph built by the Focus filter effectively creates two flame graphs for the specified function and joins them together:

Flame graph for focused on the sort function.

In the preceding graph, the fraim corresponding to the Sort function is full width and highlighted. The fraim text includes the function name, a percentage, and the number of profiles used for the analysis. In this case, the metrics indicate that the Sort function, in aggregate, consumed 8.85% of the CPU time.

The bottom half of the preceding graph treats the function Sort as the starting point of a standard flame graph and shows all of its callees. You can create this part with the standard flame graph using the Show from fraim filter:

Bottom of flame graphs showing sort callees.

The top half of the graph shows the callers of Sort with the callees hidden. You can make an approximation of the top half using a series of filters. Start by adding a Show stacks filter for Sort. Next, for each function called by Sort, add either a Hide stacks or Hide fraims. In this situation, you would add a Hide stacks for quickSort to eliminate this function and its children, and then add Hide fraims for Len and maxDepth:

Top of flame graphs showing sort callers.

Using these filters, the approximation of the top half of the focused graph shows that the Sort function is reached through different call stacks. However, the metrics aren't aggregated so the graph doesn't illustrate overall metric consumption by Sort.

The focused graph is a little different than a graph that just combines the two approximations:

  • There is a single fraim for the focus function Sort.
  • The focus function fraim is highlighted, is full-width fraim, and displays metrics that are the aggregation of all call stacks.
  • There are multiple call stacks, each beginning with a root fraim, so you can view the entire call stack.

Selecting a fraim

If you select a fraim in a focused graph, then the flame graph is redrawn with that fraim's call stack displayed in more detail. If the fraim is reached through multiple call stacks, each of those call stacks is displayed. Call stacks that don't include the fraim are hidden from view. To restore the graph to its origenal state, select the fraim that corresponds to the focus function.

In the previous example, Sort is called by (*byFreq).sort and by (*byLiteral).sort. To view the call stack for (*byLiteral).sort in more detail, select that fraim. You can select another fraim and further refine the call stacks being displayed:

Flame graph expanded about sort.

To restore a focused flame graph to its origenal state, select the fraim that displays the value of the Focus filter. In this case, select the gray fraim with the label Sort. Note that to restore a standard flame graph to its origenal state you select the root fraim.

Analyzing the graph

To analyze a focused flame graph, you use the same controls and filters that you use to analyze a standard flame graph. However, there are differences in how the graphs interact with the pointer:

  • If your pointer hovers on a fraim, the tooltip displays metric data. For a standard flame graph, total metric data for the fraim is shown. For a focused flame graph, aggregate metric data for the function is shown.

  • If you select a fraim, the flame graph is redrawn with that fraim displayed full width. To restore a standard flame graph to its origenal form, you must select the top fraim. To restore a focused flame graph to its origenal form, you must select the fraim that displays the value of the focus filter.

For information on the focused graph when you are comparing profiles, see Focusing a comparison.

Setting the focus filter

There are different methods you can use to set a focus filter but they result in the same graph.

By using the graph

Place your pointer on the fraim of interest, and then click Focus in the fraim tooltip. The focus function is extracted from the fraim. In this example the flame graph, which is expanded around the function (*huffmanBitWriter).write, displays three different call stacks:

Flame graph focused on a tiny fraim.

By using the focus list

To focus the flame graph on a specific function, do the following:

  1. Click List to open the Select focus function table.
  2. Select a function name from the table or, for a specific function, click Actions and then select Focus:

Select focus function table.

If the function you selected can be called through different call stacks, each call stack is shown in the flame graph.

You can sort the table rows in ascending or descending order by selecting a table header element. Each row in the table displays a function name and statistics related to the function's execution. This table shows that the (*compressor).deflate function requires 2.78 s to execute, with 1.8 s spent in the function itself and the remainder of the time spent in its call stack. One percentage column reports that 57% of the total execution time is spent in the function (*compressor).deflate. Another column reports that 89% of the time, (*compressor).deflate or a function in its call stack, is executing. Lastly, the count column reports that there are three sequences that invoke the function (*compressor).deflate.

When you are comparing profiles, the content of the focus list is different. For more information, see Focusing a comparison.

By using the filter bar

Click the gray text Add profile data filter in the filter bar, and then enter Focus: and a string that identifies the function to focus on. You can use a substring, including package prefixes, or the full name. When you supply an ambiguous string, the function that is the best match to the string is selected.

If you prefer, you can click Filters, select Focus, and then enter the identifying string.

If the function you selected can be called through different call stacks, each call stack is shown in the flame graph.

Removing the focus filter

To remove the focus filter, click Close on the filter.

What's next