Private
Public Access
1
0

perf logging, cap catchup loops

This commit is contained in:
2026-03-29 09:41:08 +02:00
parent de86ddbeef
commit b8e8533699
9 changed files with 158 additions and 35 deletions

View File

@@ -0,0 +1,30 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace OrekiWoofsBees.Common;
public static class DiagnosticsUtil
{
public static void StopAndLogTime<T>(
this Stopwatch stopwatch,
T instance,
double totalSecondsThreshold,
string? note = null,
[CallerMemberName] string? callerName = null) where T : IModEntity
{
stopwatch.Stop();
if (stopwatch.Elapsed.TotalSeconds >= totalSecondsThreshold)
instance.Mod?.Logger.Warning($"{typeof(T).Name}.{callerName} ({note}) took {stopwatch.Elapsed.TotalSeconds:F2}s");
}
public static void LogTime<T>(
this Stopwatch stopwatch,
T instance,
double totalSecondsThreshold,
string? note = null,
[CallerMemberName] string? callerName = null) where T : IModEntity
{
if (stopwatch.Elapsed.TotalSeconds >= totalSecondsThreshold)
instance.Mod?.Logger.Warning($"{typeof(T).Name}.{callerName} ({note}) took {stopwatch.Elapsed.TotalSeconds:F2}s");
}
}