Focusing the graph

When you use the Focus filter, you select a single function and the flame graph displays all of 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, note that frame corresponding to the Sort function is full width and highlighted. The frame 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 frame 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 frames. In this situation, you would add a Hide stacks for quickSort to eliminate this function and its children, and then add Hide frames 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 frame for the focus function Sort.
  • The focus function frame is highlighted, is full-width frame, and displays metrics that are the aggregation of all call stacks.
  • There are multiple call stacks, each beginning with a root frame, so you can view the entire call stack.

Effect of clicking on a frame

When you click a frame in a focused graph, the flame graph is redrawn with that frame's call stack displayed in more detail. If the frame is reached through multiple call stacks, each of those call stacks are displayed. Call stacks that don't include the frame are hidden from view. To restore the graph to its original state, click the frame 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, click that frame. You can click another frame and further refine the call stacks being displayed:

Flame graph expanded about sort.

To restore a focused flame graph to its original state, click the frame that displays the value of the Focus filter. In this case, click the gray frame with the label Sort.

Analyzing the graph

The focused flame graph supports the same interactions as the standard flame graph, with the exception of how the flame graph changes when you click a frame and how to restore it to the original state. For information on the behavior for a standard flame graph, go to Click on frame.

For information on the focused graph when you are comparing profiles, go to 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 frame of interest, and then click Focus in the frame tooltip. The focus function is extracted from the frame. 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 frame.

By using the focus list

To focus the flame graph on a specific function, click List , and then select a row from the Select focus function table:

Select focus function table.

With this approach, you specify a function to focus on. 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 1.46s to execute, with 971ms spent in the function itself and the remainder of the time spent in its call stack. The percentages columns report that 62% of the total execution time is spent in the function (*compressor).deflate, and that 93% of the time, this function, or a function in its call stack, is executing. Lastly, the count column reports that there are 2 sequences that invoke the function (*compressor).deflate.

When you are comparing profiles, the content of the focus list is different. For more information, go to 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. If you supply an ambiguous string, the function that best matches 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 chip.

What's next

To learn how to compare two profiles, see Comparing profiles.

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Stackdriver Profiler
Нужна помощь? Обратитесь в службу поддержки.