Added basic code profiler

This commit is contained in:
2026-01-24 19:49:33 +00:00
parent b6cfd020ba
commit 3e37cc7e0a
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d25875517d04a0191b0791fd30ac7bc
timeCreated: 1769281035

View 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);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66e399b92b6f481199da47d182d5f4cd
timeCreated: 1769281051