Private
Public Access
1
0
Files
OrekiWoofsBeehives/OrekiWoofsBees.Common/DiagnosticsUtil.cs

30 lines
1.0 KiB
C#

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");
}
}