ScopedProfiler.cs
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using UnityEngine.Profiling;
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// An `IDisposable` [profiler](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.html)
/// object that will begin a profiler sample on instantiation and end the same when disposed.
/// <para>Example:
/// <code>
/// using (new ScopedProfiler("MySample"))
/// {
/// CodeToProfile();
/// }
/// </code>
/// </para>
/// </summary>
public struct ScopedProfiler : IDisposable
{
/// <summary>
/// Begins a new profiler sample. Same as [Profiler.BeginSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.BeginSample.html)
/// </summary>
/// <param name="name">A string to identify the sample in the Profiler window.</param>
public ScopedProfiler(string name) => Profiler.BeginSample(name);
/// <summary>
/// Begins a new profiler sample. Same as [Profiler.BeginSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.BeginSample.html)
/// </summary>
/// <param name="name">A string to identify the sample in the Profiler window.</param>
/// <param name="targetObject">An object that provides context to the sample.</param>
public ScopedProfiler(string name, UnityEngine.Object targetObject) => Profiler.BeginSample(name, targetObject);
/// <summary>
/// Ends the current profiling sample. Same as [Profiler.EndSample](https://docs.unity3d.com/ScriptReference/Profiling.Profiler.EndSample.html)
/// </summary>
public void Dispose() => Profiler.EndSample();
}
}