-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStopper.cs
More file actions
38 lines (32 loc) · 784 Bytes
/
Stopper.cs
File metadata and controls
38 lines (32 loc) · 784 Bytes
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
namespace Pluton.Core
{
using System;
using System.Diagnostics;
public class Stopper : CountedInstance, IDisposable
{
readonly string Type;
readonly string Method;
readonly long WarnTimeMS;
readonly Stopwatch stopper;
public Stopper(string type, string method, float warnSecs = 0.1f)
{
//if (!pluton.stopper) return;
Type = type;
Method = method;
WarnTimeMS = (long)(warnSecs * 1000);
stopper = Stopwatch.StartNew();
}
void IDisposable.Dispose()
{
//if (!pluton.stopper) return;
if (stopper.ElapsedMilliseconds > WarnTimeMS) {
Logger.LogWarning(String.Format("[{0}.{1}] Took: {2}s ({3}ms)",
Type,
Method,
stopper.Elapsed.Seconds,
stopper.ElapsedMilliseconds
));
}
}
}
}