mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
actually do profiler samples
This commit is contained in:
parent
d551944207
commit
40621c62b0
@ -1,7 +1,10 @@
|
|||||||
using HarmonyLib;
|
// #define ENABLE_PROFILER
|
||||||
|
|
||||||
|
using HarmonyLib;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
|
||||||
namespace NewHorizons.Patches;
|
namespace NewHorizons.Patches;
|
||||||
|
|
||||||
@ -31,8 +34,10 @@ public static class ProfilerPatch
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
public static void Prefix(out Stopwatch __state)
|
public static void Prefix(MethodBase __originalMethod, out Stopwatch __state)
|
||||||
{
|
{
|
||||||
|
Profiler.BeginSample($"{__originalMethod.DeclaringType.Name}.{__originalMethod.Name}");
|
||||||
|
|
||||||
__state = new Stopwatch();
|
__state = new Stopwatch();
|
||||||
__state.Start();
|
__state.Start();
|
||||||
}
|
}
|
||||||
@ -40,6 +45,8 @@ public static class ProfilerPatch
|
|||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void Postfix(MethodBase __originalMethod, Stopwatch __state)
|
public static void Postfix(MethodBase __originalMethod, Stopwatch __state)
|
||||||
{
|
{
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
__state.Stop();
|
__state.Stop();
|
||||||
Main.Instance.ModHelper.Console.WriteLine($"[profiler] method {__originalMethod.DeclaringType.Name}.{__originalMethod.Name} took {__state.Elapsed.TotalMilliseconds} ms");
|
Main.Instance.ModHelper.Console.WriteLine($"[profiler] method {__originalMethod.DeclaringType.Name}.{__originalMethod.Name} took {__state.Elapsed.TotalMilliseconds} ms");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user