-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathDebugTimer.cs
More file actions
44 lines (34 loc) · 1.11 KB
/
Copy pathDebugTimer.cs
File metadata and controls
44 lines (34 loc) · 1.11 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
39
40
41
42
43
44
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace UnityEditor.Search
{
internal struct DebugTimer : IDisposable
{
private bool m_Disposed;
private string m_Name;
private Stopwatch m_Timer;
private double m_MinTime;
public double timeMs => m_Timer.Elapsed.TotalMilliseconds;
public DebugTimer(string name, bool useTracker = false, double minTimeMs = 0)
{
m_Disposed = false;
m_Name = name;
m_Timer = Stopwatch.StartNew();
m_MinTime = minTimeMs;
}
public void Dispose()
{
if (m_Disposed)
return;
m_Disposed = true;
m_Timer.Stop();
if (!String.IsNullOrEmpty(m_Name) && timeMs >= m_MinTime)
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, $"{m_Name} took {timeMs:F2} ms", 0, 0, 0);
}
}
}