-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProfile.cs
More file actions
55 lines (45 loc) · 1.22 KB
/
Profile.cs
File metadata and controls
55 lines (45 loc) · 1.22 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
45
46
47
48
49
50
51
52
53
54
55
using System.Diagnostics;
using LabApi.Features.Console;
using SER.Code.Extensions;
using SER.Code.ScriptSystem;
namespace SER.Code.Helpers;
public class Profile
{
public readonly Script Script;
public string? Type { get; }
private readonly Stopwatch _time = new();
protected readonly List<Profile> Children = [];
public Profile(Profile parent, string type) : this(parent.Script)
{
parent.Children.Add(this);
Type = type;
}
public Profile(Profile parent, Type type) : this(parent.Script)
{
parent.Children.Add(this);
Type = type.FullName;
}
public Profile(Script scr)
{
_time.Start();
Script = scr;
}
public Profile Stop()
{
_time.Stop();
return this;
}
public void LogResults()
{
if (_time.IsRunning) _time.Stop();
Logger.Info(
$"This profile took {_time.ElapsedMilliseconds}ms to run."
+ Children.Select(c => $"\n\t> {c.GetFormattedResult()}").JoinStrings("")
);
}
protected string GetFormattedResult()
{
if (Type is null) return string.Empty;
return $"{Type}: {_time.ElapsedMilliseconds}ms";
}
}