diff --git a/Assets/Pacore/Shared/DevTools.meta b/Assets/Pacore/Shared/DevTools.meta new file mode 100644 index 0000000..07b09d4 --- /dev/null +++ b/Assets/Pacore/Shared/DevTools.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6d25875517d04a0191b0791fd30ac7bc +timeCreated: 1769281035 \ No newline at end of file diff --git a/Assets/Pacore/Shared/DevTools/CodeProfiler.cs b/Assets/Pacore/Shared/DevTools/CodeProfiler.cs new file mode 100644 index 0000000..02c4722 --- /dev/null +++ b/Assets/Pacore/Shared/DevTools/CodeProfiler.cs @@ -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> ProfilerSnippets { get; } = new(); + public static IReadOnlyDictionary> GetProfilerSnippets() => ProfilerSnippets; + + private static void AddProfileSnippet(string name, long ms) + { + if (!ProfilerSnippets.ContainsKey(name)) + { + ProfilerSnippets.Add(name, new List()); + } + + 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); + } + } + } +} \ No newline at end of file diff --git a/Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta b/Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta new file mode 100644 index 0000000..52e333f --- /dev/null +++ b/Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 66e399b92b6f481199da47d182d5f4cd +timeCreated: 1769281051 \ No newline at end of file