From 3e37cc7e0adc3a14a08539f4732142e8636c6996 Mon Sep 17 00:00:00 2001 From: Pasha Date: Sat, 24 Jan 2026 19:49:33 +0000 Subject: [PATCH] Added basic code profiler --- Assets/Pacore/Shared/DevTools.meta | 3 ++ Assets/Pacore/Shared/DevTools/CodeProfiler.cs | 42 +++++++++++++++++++ .../Shared/DevTools/CodeProfiler.cs.meta | 3 ++ 3 files changed, 48 insertions(+) create mode 100644 Assets/Pacore/Shared/DevTools.meta create mode 100644 Assets/Pacore/Shared/DevTools/CodeProfiler.cs create mode 100644 Assets/Pacore/Shared/DevTools/CodeProfiler.cs.meta 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