From 7768a9c1d9a34c1314e538e5e2e25388eb1c7665 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 21:56:52 -0400 Subject: [PATCH 1/5] feat: expose framework timing --- Dalamud/Game/Framework.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index c801f85d4..baa8fa84b 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -92,6 +92,16 @@ namespace Dalamud.Game /// public FrameworkAddressResolver Address { get; } + /// + /// Gets the last time the Framework Update event was triggered. + /// + public DateTime LastUpdate { get; private set; } = DateTime.MinValue; + + /// + /// Gets the delta between the last Framework Update and the currently executing one. + /// + public TimeSpan UpdateDelta { get; private set; } = TimeSpan.Zero; + /// /// Gets or sets a value indicating whether to dispatch update events. /// @@ -173,6 +183,10 @@ namespace Dalamud.Game if (this.DispatchUpdateEvents) { + var now = DateTime.Now; + this.DeltaFrameworkUpdate = now - this.LastUpdate; + this.LastUpdate = now; + try { if (StatsEnabled && this.Update != null) From d7b2d92552b501747dea03deecb7bb02a33b8a7f Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 21:56:59 -0400 Subject: [PATCH 2/5] formatting --- Dalamud/Game/Framework.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index baa8fa84b..cee62be01 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -194,16 +194,23 @@ namespace Dalamud.Game // Stat Tracking for Framework Updates var invokeList = this.Update.GetInvocationList(); var notUpdated = StatsHistory.Keys.ToList(); + // Individually invoke OnUpdate handlers and time them. foreach (var d in invokeList) { statsStopwatch.Restart(); d.Method.Invoke(d.Target, new object[] { this }); statsStopwatch.Stop(); + var key = $"{d.Target}::{d.Method.Name}"; - if (notUpdated.Contains(key)) notUpdated.Remove(key); - if (!StatsHistory.ContainsKey(key)) StatsHistory.Add(key, new List()); + if (notUpdated.Contains(key)) + notUpdated.Remove(key); + + if (!StatsHistory.ContainsKey(key)) + StatsHistory.Add(key, new List()); + StatsHistory[key].Add(statsStopwatch.Elapsed.TotalMilliseconds); + if (StatsHistory[key].Count > 1000) { StatsHistory[key].RemoveRange(0, StatsHistory[key].Count - 1000); From f4cb935e414740b919d118f84c36a295fc79b61f Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 21:57:08 -0400 Subject: [PATCH 3/5] rename delta in DPI --- Dalamud/Plugin/DalamudPluginInterface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index 40894ea25..9de7ae45b 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -99,7 +99,7 @@ namespace Dalamud.Plugin /// /// Gets the timespan delta from when this plugin was loaded. /// - public TimeSpan DeltaLoadTime => DateTime.Now - this.LoadTime; + public TimeSpan LoadTimeDelta => DateTime.Now - this.LoadTime; /// /// Gets the directory Dalamud assets are stored in. From 8ed050e41ffdd1e6f5b6be74080b9a5a17e20736 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 22:18:17 -0400 Subject: [PATCH 4/5] Fix usage --- Dalamud/Game/Framework.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index cee62be01..6258b51c6 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -184,7 +184,7 @@ namespace Dalamud.Game if (this.DispatchUpdateEvents) { var now = DateTime.Now; - this.DeltaFrameworkUpdate = now - this.LastUpdate; + this.UpdateDelta = now - this.LastUpdate; this.LastUpdate = now; try From 01c0e214400e406eb320611b7ba31ea059d2fb5e Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 22:47:23 -0400 Subject: [PATCH 5/5] use stopwatch for more precise delta --- Dalamud/Game/Framework.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index 6258b51c6..2ba584ae1 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -25,6 +25,7 @@ namespace Dalamud.Game public sealed class Framework : IDisposable { private static Stopwatch statsStopwatch = new(); + private Stopwatch updateStopwatch = new(); private Hook updateHook; private Hook destroyHook; @@ -93,10 +94,15 @@ namespace Dalamud.Game public FrameworkAddressResolver Address { get; } /// - /// Gets the last time the Framework Update event was triggered. + /// Gets the last time that the Framework Update event was triggered. /// public DateTime LastUpdate { get; private set; } = DateTime.MinValue; + /// + /// Gets the last time in UTC that the Framework Update event was triggered. + /// + public DateTime LastUpdateUTC { get; private set; } = DateTime.MinValue; + /// /// Gets the delta between the last Framework Update and the currently executing one. /// @@ -137,6 +143,9 @@ namespace Dalamud.Game this.updateHook?.Dispose(); this.destroyHook?.Dispose(); this.realDestroyHook?.Dispose(); + + this.updateStopwatch.Reset(); + statsStopwatch.Reset(); } private void HookVTable() @@ -183,9 +192,12 @@ namespace Dalamud.Game if (this.DispatchUpdateEvents) { - var now = DateTime.Now; - this.UpdateDelta = now - this.LastUpdate; - this.LastUpdate = now; + this.updateStopwatch.Stop(); + this.UpdateDelta = TimeSpan.FromMilliseconds(this.updateStopwatch.ElapsedMilliseconds); + this.updateStopwatch.Restart(); + + this.LastUpdate = DateTime.Now; + this.LastUpdateUTC = DateTime.UtcNow; try {