
The CPU Usage area
This area shows data for all CPU Usage and statistics. It is perhaps the most complex and useful since it covers a large number of Unity subsystems, such as MonoBehaviour components, cameras, some rendering and physics processes, the user interface (including the Editor's interface, if we're running through the Editor), audio processing, the Profiler itself, and more.
There are three different modes for displaying CPU Usage data in Breakdown View:
- Hierarchy mode
- Raw Hierarchy mode
- Timeline mode
Let's take a look at each of these modes individually:
- Hierarchy mode reveals most callstack invocations, while grouping similar data elements and global Unity function calls together for convenience. For instance, rendering delimiters, such as BeginGUI() and EndGUI() calls, are combined together in this mode. Hierarchy mode is helpful as an initial first step for determining which function calls take the most CPU time to execute.
- Raw Hierarchy mode is similar to Hierarchy mode, except it will separate global Unity function calls into separate entries rather than their being combined into one bulk entry. This will tend to make Breakdown View more difficult to read, but may be helpful if we're trying to count how many times a particular global method is invoked, or for determining whether one of these calls is costing more CPU/memory than anticipated. For example, each BeginGUI() and EndGUI() call will be separated into different entries, making it clearer how many times each is being called compared to the Hierarchy mode.
Perhaps the most useful mode for the CPU Usage area is the Timeline mode option (not to be confused with the main Timeline View). This mode organizes CPU Usage during the current frame in line with how the callstack expanded and contracted during processing.
- Timeline mode organizes Breakdown View vertically into different sections that represent different threads at runtime, such as Main Thread, Render Thread, and various background job threads called the Unity Job System, used for loading activities such as scenes and other assets. The horizontal axis represents time, so wider blocks are consuming more CPU time than narrower blocks. The horizontal size also represents relative time, making it easy to compare how much time one function call took compared to another. The vertical axis represents the callstack, so deeper chains represent more calls in the callstack at that time.
Under Timeline mode, blocks at the top of Breakdown View are functions (or, technically, callbacks) called by the Unity Engine at runtime (such as Start(), Awake(), or Update() ), whereas blocks beneath them are functions that those functions had called into, which can include functions on other components or regular C# objects.
The Timeline mode offers a very clean and organized way to determine which particular method in the callstack consumes the most time and how that processing time measures up against other methods being called during the same frame. This allows us to gauge the method that is the biggest cause of performance problems with minimal effort.
For example, let's assume that we are looking at a performance problem in the following screenshot. We can tell, with a quick glance, that there are three methods that are causing a problem, and they each consume similar amounts of processing time, due to their similar widths:

In the previous screenshot, we have exceeded our 16.667 ms budget with calls to three different MonoBehaviour components. The good news is that we have three possible methods through which we can find performance improvements, which means lots of opportunities to find code that can be improved. The bad news is that increasing the performance of one method will only improve about one-third of the total processing for that frame. Hence, all three methods may need to be examined and optimized in order get back under budget.
In general, the CPU Usage area will be most useful for detecting issues that can be solved by solutions that will be explored in Chapter 2, Scripting Strategies.