For quite a while I provide performance overviews for every Unity beta release (see here ).
I would like to extend this test by saving Unity profiling data too, that I can then analyze in the new Profile Analyzer .
What I’m trying to do is to start and stop recording of profiling data from within the build, then save this data as a file. The test currently collects data during specific time periods only, basically separate data for every level.
I would like to run this without the need to have an Unity editor open.
I want to implement it that way, because the test collects performance data of currently 60 different levels in total. I don’t want to do this manually, thus I want to continue to keep it automated. I would also like to keep the option to be able to send the performance-test-build to testers, thus the requirement for no-editor.
My question is:
How can I start/stop profiling via scripting from within a build?
How can I save the recorded data as a file with a specific file path?
Profiler.enabled was also useful when profiling interactively in the editor:
[UnityEditor.MenuItem("Tools/Roll Many")]
static void Menu_RollMany()
{
// Unfortunately, this doesn't start recording in Profiler.
Profiler.enabled = true;
Profiler.BeginSample("Roll 10,000 - dicebag");
for (int i = 0; i < 10000; ++i)
{
dicebag();
}
Profiler.EndSample();
Profiler.BeginSample("Roll 10,000 - Simplified");
for (int i = 0; i < 10000; ++i)
{
Simplified();
}
Profiler.EndSample();
Profiler.enabled = false;
}
I open Profiler, Clear, start recording, click my Tools/Roll Many menu item (recording pauses but doesn’t stop), stop recording, and my data is the last frame.
Not sure I get your point but just FYI: in the editor, you might have to also set ProfilerDriver.enabled and ProfilerDriver.profileEditor (if what you are measuring isn’t part of the playmode player).
Hi!
I was observing an issue in a tool we did to do performance reports. We weren’t getting frames after Profiler.enabled was set to true when entering in Play mode.
In order to record information in Play mode in Editor you have to enable both the Profiler and the ProfilerDriver.
The behaviour of this feature is tricky, because if you have the profiler tab present, Profiler.enabled = true is enough to start recording some data.