Hi,
I’m doing deep profiling in my game but for some reason, some samples are shown and open in the Profiler as if the code was with recursion. The methods are not called in recursion so I don’t understand what is happening.
Anyone has ideas for what is happening?
Thanks in advance.
Are you calling BeginSample (Unity - Scripting API: Profiling.Profiler.BeginSample) but forgetting to call end sample?
I’m always closing a Begin Sample with an End Sample.
I’ve notice that we cannot put samples inside other samples like this:
BeginSample("S1");
.....
BeginSample("S2");
....
EndSample(); // End S2
BeginSample("S3");
....
EndSample(); // End S3
....
EndSample(); // End 1
because that seems to cause that recursive profiling problem. Is this right?
I removed all the samples that were coded like this and I’m closing all the started samples.
Can’t understand what the problem is.
Found it.
I was closing all the samples, but in practice not so much… lol
I had some condition checks with returns in the middle of some samples that were causing the code to return leaving some samples opened due to the Profiler.EndSample() call not being executed…
Thanks for you answer anyway.
PS: There are some frames with thousands of GC.Alloc calls, how can I track were this calls are coming from?
If you check the DeepProfilingMissingSample image, you can check in the left snapshot that inside the GraphicCanvas.LateUpdate() sample that are more samples that I created were I can check what is happening but in the right snapshot where there are 13.6mb allocked taking 153.92 ms that dropdown menu disappears not letting me check were all this GC allocs are coming from…
Hi,
There are 2 ways you can track GC allocations:
- Enable “Managed Allocations” in “Allocation Callstack” dropdown list
- Use “Deep Profiler” to see the call hierarchy.
In the first case you can see callstack when you click on a GC.Alloc sample in Timeline View or when you select an item in Hierarchy View and have detailed view open.
2 Likes
also, to avoid accidentally returning out of a method that is enclosed with a sample, and therefor not calling .End() on it, from 2018.3 on you can use ProfilerMarker with .Auto in a using statement.
2 Likes
Hi, thanks for the tips. I’ll try that for sure.