Added basic code profiler
This commit is contained in:
3
Assets/Pacore/Shared/DevTools.meta
Normal file
3
Assets/Pacore/Shared/DevTools.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d25875517d04a0191b0791fd30ac7bc
|
||||
timeCreated: 1769281035
|
||||
42
Assets/Pacore/Shared/DevTools/CodeProfiler.cs
Normal file
42
Assets/Pacore/Shared/DevTools/CodeProfiler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
|
||||
namespace PashaBibko.Pacore.Shared.DevTools
|
||||
{
|
||||
public static class CodeProfiler
|
||||
{
|
||||
private static Dictionary<string, List<long>> ProfilerSnippets { get; } = new();
|
||||
public static IReadOnlyDictionary<string, List<long>> GetProfilerSnippets() => ProfilerSnippets;
|
||||
|
||||
private static void AddProfileSnippet(string name, long ms)
|
||||
{
|
||||
if (!ProfilerSnippets.ContainsKey(name))
|
||||
{
|
||||
ProfilerSnippets.Add(name, new List<long>());
|
||||
}
|
||||
|
||||
ProfilerSnippets[name].Add(ms);
|
||||
}
|
||||
|
||||
public static ProfilerSnippetHandle Start(string name) => new(name);
|
||||
|
||||
public class ProfilerSnippetHandle : IDisposable
|
||||
{
|
||||
private Stopwatch Stopwatch { get; }
|
||||
private string SnippetName { get; }
|
||||
|
||||
public ProfilerSnippetHandle(string name)
|
||||
{
|
||||
Stopwatch = Stopwatch.StartNew();
|
||||
SnippetName = name;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Stopwatch.Stop();
|
||||
AddProfileSnippet(SnippetName, Stopwatch.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta
Normal file
3
Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66e399b92b6f481199da47d182d5f4cd
|
||||
timeCreated: 1769281051
|
||||
Reference in New Issue
Block a user