Do you want to know where to improve performance? Do you need to compare performance before and after a change? Are you aware of the impact that a Unity version update has on your game? The Profile Analyzer will help you answer these sorts of questions.
While the standard Unity Profiler allows you to do single-frame analysis, the Profile Analyzer can aggregate and visualize profiling marker data captured from a set of Unity Profiler frames.
This page provides an in-depth introduction to adding the Profile Analyzer to your arsenal of Unity and native platform profiling tools.
The Profile Analyzer is one of the many features covered in the e-book Ultimate guide to profiling Unity games. This 70+ page guide brings together advanced knowledge and advice from external and in-house Unity experts on how to profile an application in Unity, manage its memory, and optimize its power consumption from start to finish.
Overview of the Profile Analyzer
The Profile Analyzer helps you identify where to focus your efforts. It provides you with a way to compare two Unity performance profiling captures side by side, and inspect the impacts of your changes.
The Profile Analyzer complements the single frame analysis already available in the Unity Profiler. It aggregates and visualizes frame and marker data from a range of Unity Profiler frames to help you see high-level, performance-over-time patterns over many frames.
Profile Analyzer conducts CPU performance analysis on multiple frames from the current Profiler session frames or from previously saved captures. The tool comes with statistics and visualizations to help you parse information stored in captures quickly. Its Comprehensive Filtering feature also lets you drill down into the sections that you’re interested in. You can use it to compare two data sets, or you can export raw data for analysis with other tools.
You can install the Profile Analyzer via Window > Package Manager.
These profiling tips can help you get started with the Profile Analyzer:
- Get a representative and repeatable capture.
- Close all other applications. You can use Profiler.logFile in your C# scripts to write out Profile data directly from the running game, which means you don’t need the Editor to be open. It writes out a .raw file that you can load into the Unity Profiler afterwards.
- Disable any CPU hardware performance scaling or boost features so you don’t get a change in your clock frequency, such as Intel SpeedStep or AMD Precision Boost.
The Profile Analyzer can help you answer optimization and performance questions that may come up during your project’s development lifecycle. For example, in a 300-frame gameplay capture or a 20-second loading sequence:
- What are the biggest CPU costs on the main and render threads?
- What is the mean/median/total cost of each of those markers?
Use the Profile Analyzer to delve deeper into performance characteristics of your code run across multiple frames or even different session captures for before and after analysis.
Further tips when comparing data with Profile Analyzer:
- Drill into user scripts (ignoring Unity Engine API levels) by selecting a depth level of 4 (depth levels display information on where the markers are in the Hierarchy). After filtering to this level and looking at the Profiler in Timeline mode, you can correlate the call stack depth to make a selection here – Monobehaviour scripts will appear in blue and are at the fourth level down. This is a quick way to see if your specific logic and gameplay scripts are taxing by themselves without any other “noise.”
- Filter data in the same way for other areas of the Unity engine, such as animators or engine physics, by using a depth stack level of 3.
- On the right side in the Frame Summary section, you’ll find the highlighted method’s performance range histogram. Hover over the Max Frame number (the exact frame in which max timing was found) to get a clickable link to view the frame selection in the Unity Profiler. Use this view to analyze other factors that potentially contribute to the high maximum frame time.
Reviewing performance for a specific function
If you want to see how calling a function impacts performance, use the Unity Profiler or Profiler.logFile method to capture your data. If you’re using the Unity Profiler, you can click the Pull Data button to load it into the Profile Analyzer. Otherwise, you can load a previously saved data capture from a file.
As soon as you do that, the analysis starts immediately, and the data populates the frame time graph. Notice the white and cyan bars in the graph. The white bars represent the frame durations, and the cyan bars represent the currently selected marker. This allows you to compare the selected marker’s contribution to total frame time.
You can search for markers using Filters. The Marker Details automatically update to reflect the subset that you’ve selected, and in the Count column you’ll see how many occurrences it has. The frame time graph highlights the marker. When you select a marker, the Marker Summary details panel also updates to show analysis statistics for that particular marker.
Finding representative frames
When analyzing performance, you want to make sure that the data you’re looking at is representative. If your data is noisy, it’s easy to ensure that you select an average frame by using the Frame Summary at the top right – just click on the Frame shown as the Median and the Profiler will display the relevant analysis. Alternatively, using the frame time graph, right-click and select Select Median Frame.
You can also limit your analysis to a selection of frames. All of the statistics you see will be updated to reflect the specific selection.
Rather than rely on a single data point from a single frame, you can analyze multiple data points by selecting a group of representative frames. If you right-click on the frame time graph and Order by Frame Duration, you can then select a set of frames around the median frame for a representative sample that smooths out some of the noise in your data.
The effect of changing a project setting
The Profile Analyzer can help determine the performance difference when applying a project-wide setting such as enabling Graphics Jobs. To use this feature, take a baseline capture and then take another capture after you make changes. Run your game, sample it with the Unity Profiler, bring that capture over into the Profile Analyzer, and then bring the second one in.
You can see the results of the two captures side by side in the Frame Summary section.
Are you GPU-bound?
To make sure your performance doesn’t have any bottlenecks, check the Gfx.WaitForPresentOnGfxThread marker on the Main Thread. Find it by typing Gfx.WaitForPresentOnGfxThread into the filter area. If the median value of that marker is non-zero, then the CPU is waiting on the GPU to finish its activity before it can continue.
You can look at that marker in the Frame Time Graph to see how much it contributes to frame time. If the CPU is waiting for the GPU, then you’re most likely GPU-bound. Confirm this scenario by looking at your render thread profile for the presence of Gfx.PresentFrame or <GraphicsAPIName>.WaitForLastPresent markers. Check out our Ultimate guide to profiling Unity games e-book for further help, or have a look at the GPU profiling tools to see where you could make some optimizations.
Data set management
You can manage your data from the top section of the Profile Analyzer window. From here you can open the Unity Profiler, and “Pull Data” from the Unity Profiler or load a previously saved file (any Unity version).
Once you’ve loaded your data, you’ll see it in the frame time graph. This is an interactive region where you can select a range of samples; all of the summary information in the Marker Details table will automatically update to reflect your selection. You can access advanced selection options by right-clicking the frame time graph.
Click the Save button to save your analysis data as a .pdata file. Note that there are two file format types – a Profile Analyzer save file (.pdata) and a Profiler save file (.data or .raw). We recommend saving both files in the same directory.
The Frame Summary (on the right side of the Profile Analyzer window) displays highlights on the frame time, including the minimum, maximum, and median, with buttons that let you jump to specific frames in the Profiler. This area also shows you the frame time distribution histogram and a box and whisker plot.
In this section, you’ll find the marker table of the marker data from the Profiler, including all stack depths. The Unity Profiler data for all the markers are aggregated to provide median and other frame times, which are also displayed in this table. It is possible to filter these details to specific stack depth “slices” too.
The Marker Summary area at the right contains aggregated information about the selected markers and their contribution to frame time. This information is also presented visually in a histogram and a box and whisker plot.
At the bottom of the summary, you’ll find the minimum and maximum times for individual marker instances within the aggregated data set.
You can type in a substring or a collection of substrings to focus your review to markers with a specific name. If the name contains spaces, make sure to put quotes around the substring.
You can exclude the markers you’re not interested in. For example, you can exclude markers based on the idle time in Jobs or the markers that are part of the Profiler itself.
You can also populate marker filters by right-clicking on a marker of interest in the table and adding it to the filter selection.
You can choose to see data for specific worker threads. To see all of them aggregated, check “All” at the top of the thread Select pop-up window.
We recommend looking at depth 3 because most of the Unity subsystems have high-level markers at that level. That way, you see the contribution of key subsystems like rendering, animation, and physics. (Depth 3 is appropriate for recent Unity releases. For older releases, you may want to switch to another depth.)
To filter by parent, right-click on the marker in the marker table and select Set as Parent Marker Filter.
By default, the Profile Analyzer shows you Total time for the markers, but you can change to Self time. Self time is useful if you want to drill down to details to see where your time is really spent.
The default units are milliseconds, but for smaller timings, you can switch to microseconds.
Top 10 markers on median frame
This part of the window shows the top 10 markers for the filters that you’ve selected. The best way to use this tool is to select the Main Thread and Total time for Analysis Type, including children at depth 3, so that you look at the Unity subsystems. This will show you the ratio of contribution for each of those key systems, such as rendering versus physics versus animation time. For further reporting and analysis, you can hover over the data bar to see the exact percentages and metrics.
Comparing data sets
At the top of the Profile Analyzer window, you can switch to the Compare tab to select two data sets for analysis. One data set is displayed in blue, and the other in orange. Or you can choose to compare two subregions of a single data set, for example, to compare your median frames against your outlier frames.
The Marker Comparison table visually represents the data in blue and orange, so you can quickly check which of your two data sets is running slower in certain areas.
If the marker is absent in one of the scans, you’ll see a dash in that column. This can happen if the marker has been renamed, for example if you’re using different Unity versions.
Remember that you can export the data from the Profile Analyzer for further custom processing in CSV file format. You can export the contents of the marker table, the frame time graph, comparison table, or a comparison of frame time graphs.
If you have questions about the Profile Analyzer, the Profiler, or how to use their specific features for your project, join the discussions on the forums.
By profiling and honing your game’s performance across a wide range of platforms and devices, you can better plan for success and significantly expand your player base.
As mentioned at the beginning of this article, the e-book Ultimate guide to profiling Unity games provides many more instructions on profiling your Unity projects.
You can also watch this session from Unite Copenhagen. It’s from 2019 but still provides great tips on the Profile Analyzer.
Finally, find all of Unity’s advanced guides and articles in the best practices hub.