34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace OrekiWoofsBees.Common;
|
|
|
|
public static class DiagnosticsUtil
|
|
{
|
|
public static bool 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");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
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");
|
|
}
|
|
} |