mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
refactoring stopwatch
This commit is contained in:
@@ -29,14 +29,14 @@ namespace Wox.Plugin.Program
|
|||||||
_settingsStorage = new PluginJsonStorage<Settings>();
|
_settingsStorage = new PluginJsonStorage<Settings>();
|
||||||
_settings = _settingsStorage.Load();
|
_settings = _settingsStorage.Load();
|
||||||
|
|
||||||
Stopwatch.Debug("Preload programs", () =>
|
Stopwatch.Normal("Preload programs", () =>
|
||||||
{
|
{
|
||||||
_cacheStorage = new BinaryStorage<ProgramIndexCache>();
|
_cacheStorage = new BinaryStorage<ProgramIndexCache>();
|
||||||
_cache = _cacheStorage.Load();
|
_cache = _cacheStorage.Load();
|
||||||
_win32s = _cache.Programs;
|
_win32s = _cache.Programs;
|
||||||
});
|
});
|
||||||
Log.Info($"Preload {_win32s.Length} programs from cache");
|
Log.Info($"Preload {_win32s.Length} programs from cache");
|
||||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
Stopwatch.Normal("Program Index", IndexPrograms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace Wox.Core.Plugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var metadata = pair.Metadata;
|
var metadata = pair.Metadata;
|
||||||
var milliseconds = Stopwatch.Normal($"Plugin.Query cost for {metadata.Name}", () =>
|
var milliseconds = Stopwatch.Debug($"Plugin.Query cost for {metadata.Name}", () =>
|
||||||
{
|
{
|
||||||
results = pair.Plugin.Query(query) ?? results;
|
results = pair.Plugin.Query(query) ?? results;
|
||||||
UpdatePluginMetadata(results, metadata, query);
|
UpdatePluginMetadata(results, metadata, query);
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
}
|
}
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Stopwatch.Debug("Preload images from cache", () =>
|
Stopwatch.Normal("Preload images from cache", () =>
|
||||||
{
|
{
|
||||||
_cache.TopUsedImages.AsParallel().Where(i => !ImageSources.ContainsKey(i.Key)).ForAll(i =>
|
_cache.TopUsedImages.AsParallel().Where(i => !ImageSources.ContainsKey(i.Key)).ForAll(i =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,13 +11,16 @@ namespace Wox.Infrastructure
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This stopwatch will appear only in Debug mode
|
/// This stopwatch will appear only in Debug mode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Debug(string name, Action action)
|
public static long Debug(string name, Action action)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
var stopWatch = new System.Diagnostics.Stopwatch();
|
||||||
Normal(name, action);
|
stopWatch.Start();
|
||||||
#else
|
|
||||||
action();
|
action();
|
||||||
#endif
|
stopWatch.Stop();
|
||||||
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||||
|
string info = $"{name} : {milliseconds}ms";
|
||||||
|
Log.Debug(info);
|
||||||
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long Normal(string name, Action action)
|
public static long Normal(string name, Action action)
|
||||||
@@ -28,7 +31,7 @@ namespace Wox.Infrastructure
|
|||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||||
string info = $"{name} : {milliseconds}ms";
|
string info = $"{name} : {milliseconds}ms";
|
||||||
Log.Debug(info);
|
Log.Info(info);
|
||||||
return milliseconds;
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user