perf logging, cap catchup loops
This commit is contained in:
30
OrekiWoofsBees.Common/DiagnosticsUtil.cs
Normal file
30
OrekiWoofsBees.Common/DiagnosticsUtil.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user