-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProfilerSample.cs
49 lines (40 loc) · 1.32 KB
/
ProfilerSample.cs
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
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
public class ProfilerSample
{ // by SunboyL
public static bool EnableProfilerSample = true;
public static bool EnableFormatStringOutput = true;// 是否允许BeginSample的代码段名字使用格式化字符串(格式化字符串本身会带来内存开销)
public static void BeginSample(string name)
{
#if ENABLE_PROFILER
if (EnableProfilerSample)
{
Profiler.BeginSample(name);
}
#endif
}
public static void BeginSample(string formatName, params object[] args)
{
#if ENABLE_PROFILER
if (EnableProfilerSample)
{
// 必要时很有用,但string.Format本身会产生GC Alloc,需要慎用
if (EnableFormatStringOutput)
Profiler.BeginSample(string.Format(formatName, args));
else
Profiler.BeginSample(formatName);
}
#endif
}
public static void EndSample()
{
#if ENABLE_PROFILER
if (EnableProfilerSample)
{
Profiler.EndSample();
}
#endif
}
}