using System.Diagnostics; using System.Runtime.CompilerServices; namespace OrekiWoofsBees.Common; public static class DiagnosticsUtil { public static void StopAndLogTime( 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( 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"); } }