CPU Profiler shows what functions consume what percent of CPU time. This information can provide you a better understanding of how your application is executed, and how exactly resources are allocated.
Once the analysis is finished, the profiler visualizes the output data in the reports.
GoLand features two pre-defined Async Profiler configurations: the CPU profiler and the memory allocation profiler that you can find in.
These configurations are adjusted to provide the most accurate results, that is why they don't require any modifications. However, if you still need to change the settings, refer to Async Profiler on GitHub for more information.
Select the profiler configuration
In the Settings/Preferences dialog Ctrl+Alt+S, select .
Select one of the pre-defined CPU or memory profiling configuration or create a new one by clicking .
Apply the changes and close the dialog.
Run CPU profiling
Open the _test.go file.
Near the function or method that you want to profile, click the Run Application icon in the gutter area and select Run <configuration_name> with 'CPU Profiler'.
Interpret the results
In the Profiler tool window, the collected data is presented on three tabs: Flame Graph, Call Tree, and Method List. The left-hand part lists application threads; by clicking on each thread you can go in more details.
The Flame Chart tab shows you function calls and the percentage of time for execution of each call. Each block represents a function in the stack (a stack frame). On the Y-axis, there is a stack depth going from bottom up. The X-axis shows the stack profile sorted from the most CPU-consuming functions to the least consuming ones.
When you read the flame graph, focus on the widest blocks. These blocks are the functions that are presented in the profile most.
Hover the mouse over any block to view the details:
The Call Tree tab represents information about a program’s call stacks that were sampled during profiling:
The method name
Percentage of total sample time (can be toggled to the parent call view)
The total sample count
The number of filtered calls
The optional number right after the percentage presents a filtered sequence of calls. Click it to expand this sequence. The filtering rules can be configured in the settings.
To configure and filter the Call Tree view, use the Presentation Settings button ().
The Methods List collects all methods in the profiled data and sorts them by cumulative sample time. Every item in this list has a Back Trace tree and a Merge Callees tree.
The Back Trace shows the hierarchy of callers. Use this view to trace which methods call the selected method. Merge Callees tries to summarize all methods that are called by the selected one.