I’m trying to debug a particularly high cost function, when profiling (Profile Editor) the function takes 2sec.
I need to get some deep profiling on the function because the time wasters are hidden, but when I turn the Deep Profiling on it doesn’t show a data point for the function, despite enclosing my function with Profile.BeginSample() or increasing the number of samples.
With Profiler.BeginSample at the start of your function and Profiler.EndSample at the end (inside the function of course) you should be able to see a entry under the able you did specify.
Just in case something messed up: http://docs.unity3d.com/ScriptReference/Profiler.BeginSample.html
Are you calling EndSample ? (are you sure it’s being called?)
Can you post a screenshot of the long (2s) frame ?
Does the profiler work in “Deep Profile” mode ? Does it capture a very long frame (with the function you mentioned?)
Once you capture the data you need, stop profiling. On the lower right side, there’s a search box. Enter the term you used when calling BeginSample. Scrub along to see whether you see that written somewhere.
If nothing comes up – do you get any warnings/errors in the console? (e.g: something that is coming up from the profiler?)
If all fails (which is weird and may be an issue with the editor?), you could resort to your own custom profiling (using something simple as a StopWatch class).
How complex is that method? if it’s really long and complex (hence - it’s hard to see where the long execution time is coming from), you can also consider splitting it into multiple smaller methods. Be sure to call Profiler.BeginSample/EndSample in each of these as well !
@liortal I do call EndSample and AFAIK it is being called (I’ll double check when I get back to the office).
The function doesn’t show up in the profiler at all in Deep Profiler mode, with or without BeginSample & EndSample (it does show up in normal mode but there are no useful details). I usually have my finger over the Record button when the function is running (it usually takes ~6s in Deep Profiling), when I stop the recording it shows all the samples before and after my function being called but no mention of the function I’m profiling.
The actual method is pretty simple in itself, but it does call a bunch of more complex functions. I don’t really want to use StopWatch because I want to know the cumulative time of the function that’s gumming up the works, and I’m not too keen to write an entire profiler myself
Usually when a frame takes too long you’d get this error:
Did you try increasing the profiler buffer size ?
According to the docs, the max size (per thread) is 8mb. You could try adding this to some of your early executing code:
I think that in general what you experienced is some limitation (some may call it a bug?) with the Unity profiler… it probably drops samples since its buffer get filled and it cannot show all the information for such long executing methods…