From b460ffc16b050f0b9e318c04fa3f2e1269b27c9c Mon Sep 17 00:00:00 2001 From: BitsOfAByte <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 21 Jan 2023 02:47:07 +0000 Subject: [PATCH 1/2] Add totals to xlstats --- .../Internal/Windows/PluginStatWindow.cs | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs index e5e8b90e7..8e9b6928e 100644 --- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs @@ -6,6 +6,7 @@ using System.Reflection; using Dalamud.Game; using Dalamud.Hooking.Internal; +using Dalamud.Interface.Components; using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; @@ -68,6 +69,24 @@ internal class PluginStatWindow : Window } } + var loadedPlugins = pluginManager.InstalledPlugins.Where(plugin => plugin.State == PluginState.Loaded); + + var allLast = loadedPlugins + .DefaultIfEmpty() + .Where(plugin => plugin.DalamudInterface != null) + .Select(plugin => plugin.DalamudInterface.UiBuilder.LastDrawTime); + + var allAverage = loadedPlugins + .DefaultIfEmpty() + .Where(plugin => plugin.DalamudInterface != null) + .Select(plugin => plugin.DalamudInterface.UiBuilder.DrawTimeHistory.DefaultIfEmpty().Average()); + + ImGuiComponents.TextWithLabel("Total Last", $"{allLast.Aggregate(0d, (a, b) => a + b) / 10000f:F4}ms", "All last draw times added together"); + ImGui.SameLine(); + ImGuiComponents.TextWithLabel("Total Average", $"{allAverage.Aggregate(0d, (a, b) => a + b) / 10000f:F4}ms", "All average draw times added together"); + ImGui.SameLine(); + ImGuiComponents.TextWithLabel("Collective Average", $"{allAverage.Average() / 10000f:F4}ms", "Average of all average draw times"); + if (ImGui.BeginTable( "##PluginStatsDrawTimes", 4, @@ -86,8 +105,6 @@ internal class PluginStatWindow : Window ImGui.TableSetupColumn("Average"); ImGui.TableHeadersRow(); - var loadedPlugins = pluginManager.InstalledPlugins.Where(plugin => plugin.State == PluginState.Loaded); - var sortSpecs = ImGui.TableGetSortSpecs(); loadedPlugins = sortSpecs.Specs.ColumnIndex switch { @@ -149,6 +166,22 @@ internal class PluginStatWindow : Window Framework.StatsHistory.Clear(); } + var statsHistory = Framework.StatsHistory.ToArray(); + + var allLast = statsHistory + .DefaultIfEmpty() + .Select(x => x.Value.LastOrDefault()); + + var allAverage = statsHistory + .DefaultIfEmpty() + .Select(x => x.Value.DefaultIfEmpty().Average()); + + ImGuiComponents.TextWithLabel("Total Last", $"{allLast.Aggregate(0d, (a, b) => a + b):F4}ms", "All last update times added together"); + ImGui.SameLine(); + ImGuiComponents.TextWithLabel("Total Average", $"{allAverage.Aggregate(0d, (a, b) => a + b):F4}ms", "All average update times added together"); + ImGui.SameLine(); + ImGuiComponents.TextWithLabel("Collective Average", $"{allAverage.Average():F4}ms", "Average of all average update times"); + if (ImGui.BeginTable( "##PluginStatsFrameworkTimes", 4, @@ -167,8 +200,6 @@ internal class PluginStatWindow : Window ImGui.TableSetupColumn("Average", ImGuiTableColumnFlags.None, 50); ImGui.TableHeadersRow(); - var statsHistory = Framework.StatsHistory.ToArray(); - var sortSpecs = ImGui.TableGetSortSpecs(); statsHistory = sortSpecs.Specs.ColumnIndex switch { From a548f46fcb993c3f9accc756a1d6dc04ab89b44a Mon Sep 17 00:00:00 2001 From: BitsOfAByte <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 21 Jan 2023 03:42:34 +0000 Subject: [PATCH 2/2] Optimize LINQ for totals --- .../Internal/Windows/PluginStatWindow.cs | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs index 8e9b6928e..21b32a68a 100644 --- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs @@ -70,22 +70,14 @@ internal class PluginStatWindow : Window } var loadedPlugins = pluginManager.InstalledPlugins.Where(plugin => plugin.State == PluginState.Loaded); + var totalLast = loadedPlugins.Sum(plugin => plugin.DalamudInterface?.UiBuilder.LastDrawTime ?? 0); + var totalAverage = loadedPlugins.Sum(plugin => plugin.DalamudInterface?.UiBuilder.DrawTimeHistory.DefaultIfEmpty().Average() ?? 0); - var allLast = loadedPlugins - .DefaultIfEmpty() - .Where(plugin => plugin.DalamudInterface != null) - .Select(plugin => plugin.DalamudInterface.UiBuilder.LastDrawTime); - - var allAverage = loadedPlugins - .DefaultIfEmpty() - .Where(plugin => plugin.DalamudInterface != null) - .Select(plugin => plugin.DalamudInterface.UiBuilder.DrawTimeHistory.DefaultIfEmpty().Average()); - - ImGuiComponents.TextWithLabel("Total Last", $"{allLast.Aggregate(0d, (a, b) => a + b) / 10000f:F4}ms", "All last draw times added together"); + ImGuiComponents.TextWithLabel("Total Last", $"{totalLast / 10000f:F4}ms", "All last draw times added together"); ImGui.SameLine(); - ImGuiComponents.TextWithLabel("Total Average", $"{allAverage.Aggregate(0d, (a, b) => a + b) / 10000f:F4}ms", "All average draw times added together"); + ImGuiComponents.TextWithLabel("Total Average", $"{totalAverage / 10000f:F4}ms", "All average draw times added together"); ImGui.SameLine(); - ImGuiComponents.TextWithLabel("Collective Average", $"{allAverage.Average() / 10000f:F4}ms", "Average of all average draw times"); + ImGuiComponents.TextWithLabel("Collective Average", $"{(loadedPlugins.Any() ? totalAverage / loadedPlugins.Count() / 10000f : 0):F4}ms", "Average of all average draw times"); if (ImGui.BeginTable( "##PluginStatsDrawTimes", @@ -167,20 +159,14 @@ internal class PluginStatWindow : Window } var statsHistory = Framework.StatsHistory.ToArray(); + var totalLast = statsHistory.Sum(stats => stats.Value.LastOrDefault()); + var totalAverage = statsHistory.Sum(stats => stats.Value.Average()); - var allLast = statsHistory - .DefaultIfEmpty() - .Select(x => x.Value.LastOrDefault()); - - var allAverage = statsHistory - .DefaultIfEmpty() - .Select(x => x.Value.DefaultIfEmpty().Average()); - - ImGuiComponents.TextWithLabel("Total Last", $"{allLast.Aggregate(0d, (a, b) => a + b):F4}ms", "All last update times added together"); + ImGuiComponents.TextWithLabel("Total Last", $"{totalLast:F4}ms", "All last update times added together"); ImGui.SameLine(); - ImGuiComponents.TextWithLabel("Total Average", $"{allAverage.Aggregate(0d, (a, b) => a + b):F4}ms", "All average update times added together"); + ImGuiComponents.TextWithLabel("Total Average", $"{totalAverage:F4}ms", "All average update times added together"); ImGui.SameLine(); - ImGuiComponents.TextWithLabel("Collective Average", $"{allAverage.Average():F4}ms", "Average of all average update times"); + ImGuiComponents.TextWithLabel("Collective Average", $"{(statsHistory.Any() ? totalAverage / statsHistory.Length : 0):F4}ms", "Average of all average update times"); if (ImGui.BeginTable( "##PluginStatsFrameworkTimes",