2014-12-15 14:58:49 +00:00
|
|
|
|
using System;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2021-01-02 07:52:41 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure.Logger;
|
2014-12-15 14:58:49 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Infrastructure
|
2014-12-15 14:58:49 +00:00
|
|
|
|
{
|
2015-11-04 21:49:36 +00:00
|
|
|
|
public static class Stopwatch
|
2014-12-15 14:58:49 +00:00
|
|
|
|
{
|
2015-11-04 21:35:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This stopwatch will appear only in Debug mode
|
|
|
|
|
|
/// </summary>
|
2025-04-13 09:11:36 +00:00
|
|
|
|
public static long Debug(string className, string message, Action action, [CallerMemberName] string methodName = "")
|
2014-12-15 14:58:49 +00:00
|
|
|
|
{
|
2016-11-30 00:31:31 +00:00
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
|
|
|
|
stopWatch.Start();
|
2015-11-04 21:35:04 +00:00
|
|
|
|
action();
|
2016-11-30 00:31:31 +00:00
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Debug(className, $"{message} <{milliseconds}ms>", methodName);
|
2016-11-30 00:31:31 +00:00
|
|
|
|
return milliseconds;
|
2014-12-15 14:58:49 +00:00
|
|
|
|
}
|
2021-01-02 07:52:41 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This stopwatch will appear only in Debug mode
|
|
|
|
|
|
/// </summary>
|
2025-04-13 09:11:36 +00:00
|
|
|
|
public static async Task<long> DebugAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "")
|
2021-01-02 07:52:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
|
|
|
|
stopWatch.Start();
|
|
|
|
|
|
await action();
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Debug(className, $"{message} <{milliseconds}ms>", methodName);
|
2021-01-02 07:52:41 +00:00
|
|
|
|
return milliseconds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-13 09:11:36 +00:00
|
|
|
|
public static long Info(string className, string message, Action action, [CallerMemberName] string methodName = "")
|
2014-12-15 14:58:49 +00:00
|
|
|
|
{
|
2015-11-04 21:49:36 +00:00
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
2015-11-04 21:35:04 +00:00
|
|
|
|
stopWatch.Start();
|
|
|
|
|
|
action();
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Info(className, $"{message} <{milliseconds}ms>", methodName);
|
2015-11-04 21:35:04 +00:00
|
|
|
|
return milliseconds;
|
2014-12-15 14:58:49 +00:00
|
|
|
|
}
|
2021-01-02 07:52:41 +00:00
|
|
|
|
|
2025-04-13 09:11:36 +00:00
|
|
|
|
public static async Task<long> InfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "")
|
2021-01-02 07:52:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
|
|
|
|
stopWatch.Start();
|
|
|
|
|
|
await action();
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
2025-04-13 09:11:36 +00:00
|
|
|
|
Log.Info(className, $"{message} <{milliseconds}ms>", methodName);
|
2021-01-02 07:52:41 +00:00
|
|
|
|
return milliseconds;
|
|
|
|
|
|
}
|
2014-12-15 14:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|