3.2 Profiling with the Unity profiler
The Unity profiler provides detailed per-frame performance data in a series of charts to help you find the bottlenecks in your game.
If you click in a chart, you see a vertical slice and this selects a single
frame. You can read information from this frame in the display panel at the bottom of
the screen. If you click on a different chart without modifying the frame selection, the
panel shows data from the profiler you have selected.
The following figure shows the Unity profiler:
Figure 3-1 Unity profiler
The Unity profiler provides the following functions:
- CPU Usage profiler
- The CPU Usage profiler chart shows a breakdown of CPU utilization,
highlighting different components, such as rendering, scripts, or physics. If
you select a frame on the chart, the panel displays the functions that most
contributed to that particular frame, in time taken, number of calls or memory
- Concentrate on the functions that spend more time executing or allocate too
NoteIn a multi-processor system, the values are averaged.
- Rendering profiler
- The Rendering profiler chart shows the number of draw calls,
triangles, and vertices rendered in your scene. Selecting a frame on the chart
displays more information about batching, textures, and memory consumption.
- Look at the number of draw calls, triangles, and vertices that
your scene renders. These are the most important numbers in mobile
- Memory profiler
- The Memory profiler chart displays the amount of memory allocated and the
amount of resources used by the game, such as meshes or materials. Selecting a
frame on the chart displays the memory consumption of your assets, the graphics
and audio subsystems, or of profiler data itself.
- Memory is limited on mobile platforms, so you must monitor the requirements
of your game during its lifetime and check the number of resources in use. Some
techniques, if applied incorrectly, can cause a large number of new objects to
be created. For example, a texture atlas applied incorrectly can lead to the
creation of a large number of new material objects.
- The Add Profiler function
- Add Profiler is an option on the
drop-down menu in the top left corner of the profiler window. It enables you to
add more charts to the profiler window, for example, CPU usage, rendering, or
- The Profiler.BeginSample() and Profiler.EndSample() methods
- The Unity profiler enables you to use the
Profiler.EndSample() methods. You can mark a region in your
script, attach a custom label to it, and this region appears in the profiler
hierarchy as a separate entry. Doing this enables you to obtain information
about a specific piece of code without the compute and memory overhead of the
Deep Profile option.
- The following figure shows a profiled section:
Figure 3-2 Profiled section