Added Pacore
This commit is contained in:
42
Assets/Pacore/Runtime/DevTools/CodeProfiler.cs
Normal file
42
Assets/Pacore/Runtime/DevTools/CodeProfiler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
|
||||
namespace PashaBibko.Pacore.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Pacore/Runtime/DevTools/CodeProfiler.cs.meta
Normal file
11
Assets/Pacore/Runtime/DevTools/CodeProfiler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ede419ddf0f2c64f89935e3d36ebeb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user