diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index 16e3777f78..b120c4f280 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -21,9 +21,6 @@ namespace Wox.Plugin.CMD public List Query(Query query) { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - List results = new List(); List pushedResults = new List(); if (query.Search == ">") @@ -80,8 +77,6 @@ namespace Wox.Plugin.CMD catch (Exception) { } } - stopwatch.Stop(); - DebugHelper.WriteLine("CMD:" + stopwatch.ElapsedMilliseconds + "ms"); return results; } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index fabc450f2a..af31c7a70e 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -21,7 +22,7 @@ namespace Wox.Core.Plugin { public const string ActionKeywordWildcardSign = "*"; private static List pluginMetadatas; - private static List> instantSearches; + private static List> instantSearches; public static String DebuggerMode { get; private set; } @@ -86,15 +87,17 @@ namespace Wox.Core.Plugin PluginPair pair = pluginPair; ThreadPool.QueueUserWorkItem(o => { - using (new Timeit(string.Format("Init {0}", pair.Metadata.Name))) + Stopwatch sw = new Stopwatch(); + sw.Start(); + pair.Plugin.Init(new PluginInitContext() { - pair.Plugin.Init(new PluginInitContext() - { - CurrentPluginMetadata = pair.Metadata, - Proxy = HttpProxy.Instance, - API = API - }); - } + CurrentPluginMetadata = pair.Metadata, + Proxy = HttpProxy.Instance, + API = API + }); + sw.Stop(); + DebugHelper.WriteLine(string.Format("Plugin init:{0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds)); + pair.InitTime = sw.ElapsedMilliseconds; }); } @@ -129,7 +132,7 @@ namespace Wox.Core.Plugin { if (string.IsNullOrEmpty(query.RawQuery)) return false; var strings = query.RawQuery.Split(' '); - if(strings.Length == 1) return false; + if (strings.Length == 1) return false; var actionKeyword = strings[0].Trim(); if (string.IsNullOrEmpty(actionKeyword)) return false; @@ -163,11 +166,24 @@ namespace Wox.Core.Plugin { try { + Stopwatch sw = new Stopwatch(); + sw.Start(); List results = pair.Plugin.Query(query) ?? new List(); results.ForEach(o => { o.PluginID = pair.Metadata.ID; }); + sw.Stop(); + DebugHelper.WriteLine(string.Format("Plugin query: {0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds)); + pair.QueryCount += 1; + if (pair.QueryCount == 1) + { + pair.AvgQueryTime = sw.ElapsedMilliseconds; + } + else + { + pair.AvgQueryTime = (pair.AvgQueryTime + sw.ElapsedMilliseconds) / 2; + } API.PushResults(query, pair.Metadata, results); } catch (System.Exception e) @@ -176,7 +192,7 @@ namespace Wox.Core.Plugin } } - private static List> LoadInstantSearches() + private static List> LoadInstantSearches() { if (instantSearches != null) return instantSearches; @@ -196,7 +212,7 @@ namespace Wox.Core.Plugin foreach (Type type in types) { - instantSearches.Add(new KeyValuePair(metadata,Activator.CreateInstance(type) as IInstantSearch)); + instantSearches.Add(new KeyValuePair(metadata, Activator.CreateInstance(type) as IInstantSearch)); } } catch (System.Exception e) diff --git a/Wox.Plugin/PluginPair.cs b/Wox.Plugin/PluginPair.cs index b3053c0571..03aa657ce2 100644 --- a/Wox.Plugin/PluginPair.cs +++ b/Wox.Plugin/PluginPair.cs @@ -10,6 +10,12 @@ namespace Wox.Plugin public IPlugin Plugin { get; set; } public PluginMetadata Metadata { get; set; } + internal long InitTime { get; set; } + + internal long AvgQueryTime { get; set; } + + internal int QueryCount { get; set; } + public override string ToString() { return Metadata.Name; diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml index 54ad62c9a4..de368e59c5 100644 --- a/Wox/Languages/en.xaml +++ b/Wox/Languages/en.xaml @@ -22,6 +22,8 @@ Action keyword Plugin Directory Author + Init time: {0}ms + Query time: {0}ms Theme diff --git a/Wox/Languages/zh-cn.xaml b/Wox/Languages/zh-cn.xaml index 39688d68f7..131e333bee 100644 --- a/Wox/Languages/zh-cn.xaml +++ b/Wox/Languages/zh-cn.xaml @@ -22,7 +22,9 @@ 触发关键字 插件目录 作者 - + 加载耗时:{0}ms + 查询耗时:{0}ms + 主题 浏览更多主题 diff --git a/Wox/Languages/zh-tw.xaml b/Wox/Languages/zh-tw.xaml index 694cd3175a..e788226e77 100644 --- a/Wox/Languages/zh-tw.xaml +++ b/Wox/Languages/zh-tw.xaml @@ -22,7 +22,9 @@ 觸發關鍵字 插件目錄 作者 - + 加載耗時:{0}ms + 查詢耗時:{0}ms + 主題 瀏覽更多主題 diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 99f0237d29..c44b71cc2d 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -95,10 +95,12 @@ - + + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index b607281b01..8a33b19a35 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -477,6 +477,10 @@ namespace Wox provider = pair.Plugin as ISettingProvider; pluginAuthor.Visibility = Visibility.Visible; pluginActionKeyword.Visibility = Visibility.Visible; + pluginInitTime.Text = + string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime); + pluginQueryTime.Text = + string.Format(InternationalizationManager.Instance.GetTranslation("plugin_query_time"), pair.AvgQueryTime); pluginActionKeywordTitle.Visibility = Visibility.Visible; tbOpenPluginDirecoty.Visibility = Visibility.Visible; pluginTitle.Text = pair.Metadata.Name;