Is there a way to retrieve results from the profiler via script (e.g. Camera.Render/Drawing = X ms)

While coding a new Unity plugin for the Asset Store, I found myself in the position when it would be necessary to retrieve results from the profiler via script. Like, for instance, get in a string that “Camera.Render/Drawing = 2.41 ms”.

Is there a way to achieve something like that? In the manuals, I didn’t find any information whatsoever on that, besides the very simple functions of the Profiler class (like the not very useful saving of FPS to an external log file).

You could probably achieve something like that using a fair amount of hacking.

The profiler is implemented in native code, with a few different classes (some are internal, some public) that retrieve the data from the profiler.

On top of that, you have the Profiler window which is also implemented in managed code (C#) using IMGUI (e.g: OnGUI).

So, basically, you would have to figure out how the data is retrieved from the profiler and displayed in the profiler window, and try to get whatever data you’re looking for.

Not very simple but i think it is possible.

You should use a c# decompiler (you can use MonoDevelop for that actually, but there are better ones).

Classes you should peek into are probably anything from UnityEditor.dll with the word “Profiler” in it at the bare minimum.

Good luck :slight_smile:

p.s: a better option of course would’ve been some sort of API that exposes this information to us developers.

I would recommend to take a look at ILSpy.
http://ilspy.net/
With that tool you can look inside the unity editor dll to figure out what going on.

Not sure about the legal aspects, but some of the classes are public, so i assume you’re free to use them…