Open a Unity profiler capture outside of the Editor

Unity 01/Apr/2023 Sat

TLDR

The Editor iteration profiler (EIP) has a built-in functionality for exporting data from the profiler in different formats (html, csv, json). Below I explain how it worked for me when I needed to inspect a profiler capture in chrome://tracing.

Recently, while working with a customer case, investigating a performance issue. I faced a kind of 'blocker' because they sent a profiler capture of +4GB size and it required +50GB of memory for opening in the editor. And, my computer is 32 GB only.

I cannot ensure my next hyphotesis is 100% correct, but here I go:

  1. The capture was 1 frame long that lasted more than 15 minutes.

  2. The profiler captures are not completely events based. Every tick, it records the data of the markers being excecuted.

  3. As far as I know, a marker has a lot of information. E.g., Name, Category, time, parent/children relationship, calls from/to, etc.

  4. When something like the above happens, there's a lot to unpack and to keep in memory for visualizing and interacting with the data.

So, when I tried to open the capture in my computer, it went out of memory, and I believe that something like the kernel killed the application taking all this memory. So, yes, I could remotely work in the computer of a colleague (and I tried, his machine was 64 GB; still, every click was +10 s waiting for the profiler to load the corresponding information) but how could I work with it in my machine?

Approximately two years ago, the Unity team released the editor iteration profiler which is intended to measure a repetitive task in the editor. For example, you want to profile every 'OnEnterPlayMode' action and validate what's (un)healthy for this task, so you toggle the EIP on and start 'iterating' (entering play mode, exiting play mode, making a change... and repeating the process). Finally, the collected data can be exported as HTML, Json and CSV.

The good news is that this package actually let you export every what ever is loaded in the profiler.

So, what did I do?

  1. Find a computer that can open the profiler capture.

  2. Install the EIP.

    • How? Download the zip package from here, and add it to the packages folder in the Unity project where you will be opening the capture.
  3. Open the profiler capture.

  4. Open the EIP window. Window > Analysis > Editor Iteration Profiler > Show Window.

  5. From the EIP window’s toolbar, select Export Profiler Data > Export Selected Frame.

  6. Choose the .json format and save it.

  7. From the browser, open perfetto or chrome://tracing.

  8. Open the json capture there.

Some notes:

  • Depending on the need, another export format could be more suitable. A detailed explanation of these are in https://github.com/Unity-Technologies/com.unity.editoriterationprofiler/blob/master/Documentation~/exporting-data.md.

  • In my case, the size of the exported data became way smaller (<1 MB) because it keeps less information.

  • I understood the chrome://tracing visualization can show different information from the Unity built-in profiler because it builds the information based on the times of every marker. When two markers are being excecuted at the same time, the UI says that the parent marker is the one starting earlier. In the words of Aras,

    There’s no need to indicate parent-child relationships between the events; the UI automatically figures that out based on event timings.

At some point, I'd like to be capable of opening an editor profiler capture without the need of creating a Unity project and opening the Unity editor.

Tags: