mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
705354a3d6
1. Throw exception for fatal/error log when debugging 2. Write to debug output for warn/debug/info log when debugging 3. part of #355
38 lines
938 B
C#
38 lines
938 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using Wox.Infrastructure.Logger;
|
|
|
|
namespace Wox.Infrastructure
|
|
{
|
|
public static class Stopwatch
|
|
{
|
|
/// <summary>
|
|
/// This stopwatch will appear only in Debug mode
|
|
/// </summary>
|
|
public static void Debug(string name, Action action)
|
|
{
|
|
#if DEBUG
|
|
Normal(name, action);
|
|
#else
|
|
action();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// This stopwatch will also appear only in Debug mode
|
|
/// </summary>
|
|
public static long Normal(string name, Action action)
|
|
{
|
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
|
stopWatch.Start();
|
|
action();
|
|
stopWatch.Stop();
|
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
|
string info = $"{name} : {milliseconds}ms";
|
|
Log.Debug(info);
|
|
return milliseconds;
|
|
}
|
|
|
|
}
|
|
}
|