10using System.Collections.Generic;
19 public static class LeapProfiling {
22 private static Dictionary<string, CustomSampler> _samplers =
new Dictionary<string, CustomSampler>();
27 private static Queue<string> _samplersToCreate =
new Queue<string>();
30 private static int _samplersToCreateCount = 0;
32 public static void Update() {
34 if (_samplersToCreateCount > 0) {
36 lock (_samplersToCreate) {
38 var newDictionary =
new Dictionary<string, CustomSampler>(_samplers);
41 while (_samplersToCreate.Count > 0) {
42 string blockName = _samplersToCreate.Dequeue();
44 newDictionary[blockName] = CustomSampler.Create(blockName);
48 _samplersToCreateCount = 0;
53 _samplers = newDictionary;
58 public static void BeginProfilingForThread(BeginProfilingForThreadArgs eventData) {
59#if UNITY_2017_3_OR_NEWER
61 Profiler.BeginThreadProfiling(
"LeapCSharp", eventData.threadName);
66 lock (_samplersToCreate) {
67 foreach (var blockName
in eventData.blockNames) {
68 _samplersToCreate.Enqueue(blockName);
71 Interlocked.Add(ref _samplersToCreateCount, eventData.blockNames.Length);
74 Debug.LogWarning(
"Thread Profiling is unavailable in versions of Unity below 2017.3");
78 public static void EndProfilingForThread(EndProfilingForThreadArgs eventData) {
79#if UNITY_2017_3_OR_NEWER
80 Profiler.EndThreadProfiling();
82 Debug.LogWarning(
"Thread Profiling is unavailable in versions of Unity below 2017.3");
86 public static void BeginProfilingBlock(BeginProfilingBlockArgs eventData) {
95 CustomSampler sampler;
96 if (_samplers.TryGetValue(eventData.blockName, out sampler)) {
101 public static void EndProfilingBlock(EndProfilingBlockArgs eventData) {
102 CustomSampler sampler;
103 if (_samplers.TryGetValue(eventData.blockName, out sampler)) {