Symptoms:
- Not all user code is shown in the Profiler, and Deep Profiling slows down my application.
Cause:
The built-in Profiler is not profiling all method calls. Also, Deep Profiling causes a large overhead that will significantly slow down your application execution. It may not even be possible to perform the profiling activity (Unity can run out of memory).
Resolution:
Profiler Sample is a block of code that starts with
Profiler.BeginSample()
and ends withProfiler.EndSample()
calls. Just like this:using UnityEngine; using UnityEngine.Profiling; public class NeedsProfiling : MonoBehaviour { void Update() { Profiler.BeginSample("My Sample"); Debug.Log("This code is being profiled"); Profiler.EndSample(); } }
You would put it before, and after the chunk of code you want to be profiled. Profiler Sample will record the execution time for you and is displayed in the Profiler window without using Deep Profiling.

Of course, you can add as many Profiler Samples as you want. Don’t worry about adding too many samples. These calls have zero overhead when they are deployed in a non-development build.
More Information