2014-12-15 14:58:49 +00:00
|
|
|
|
using System;
|
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>
|
2017-01-24 00:24:20 +00:00
|
|
|
|
public static long Debug(string message, Action action)
|
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;
|
2017-01-24 00:24:20 +00:00
|
|
|
|
string info = $"{message} <{milliseconds}ms>";
|
|
|
|
|
|
Log.Debug(info);
|
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>
|
|
|
|
|
|
public static async Task<long> DebugAsync(string message, Func<Task> action)
|
|
|
|
|
|
{
|
|
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
|
|
|
|
stopWatch.Start();
|
|
|
|
|
|
await action();
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
|
|
|
|
|
string info = $"{message} <{milliseconds}ms>";
|
|
|
|
|
|
Log.Debug(info);
|
|
|
|
|
|
return milliseconds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-24 00:24:20 +00:00
|
|
|
|
public static long Normal(string message, Action action)
|
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;
|
2017-01-24 00:24:20 +00:00
|
|
|
|
string info = $"{message} <{milliseconds}ms>";
|
|
|
|
|
|
Log.Info(info);
|
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
|
|
|
|
|
|
|
|
|
|
public static async Task<long> NormalAsync(string message, Func<Task> action)
|
|
|
|
|
|
{
|
|
|
|
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
|
|
|
|
stopWatch.Start();
|
|
|
|
|
|
await action();
|
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
|
|
|
|
|
string info = $"{message} <{milliseconds}ms>";
|
|
|
|
|
|
Log.Info(info);
|
|
|
|
|
|
return milliseconds;
|
|
|
|
|
|
}
|
2014-12-15 14:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|