From 2ab9428aada9a34c873b84babd651b63f8bd2b56 Mon Sep 17 00:00:00 2001 From: Andy Adshead Date: Wed, 30 Jan 2019 00:33:55 +0000 Subject: [PATCH] Stop data running away when paused and frame updated --- Ryujinx.Profiler/InternalProfile.cs | 5 ++++- Ryujinx.Profiler/TimingInfo.cs | 23 +++++++++++++++++++---- Ryujinx.Profiler/UI/ProfileWindow.cs | 1 + Ryujinx.Profiler/UI/ProfileWindowGraph.cs | 5 +++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index d50fc3d702..e318e8a7cb 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -21,6 +21,7 @@ namespace Ryujinx.Profiler private readonly Thread _cleanupThread; private bool _cleanupRunning; private readonly long _history; + private long _preserve; // Timing flags private TimingFlag[] _timingFlags; @@ -53,7 +54,7 @@ namespace Ryujinx.Profiler { foreach (var timer in Timers) { - timer.Value.Cleanup(SW.ElapsedTicks - _history); + timer.Value.Cleanup(SW.ElapsedTicks - _history, _preserve - _history, _preserve); } // No need to run too often @@ -106,6 +107,8 @@ namespace Ryujinx.Profiler { Dictionary outDict = new Dictionary(); + _preserve = SW.ElapsedTicks; + // Forcibly get copy so user doesn't block profiling ProfileConfig[] configs = Timers.Keys.ToArray(); TimingInfo[] times = Timers.Values.ToArray(); diff --git a/Ryujinx.Profiler/TimingInfo.cs b/Ryujinx.Profiler/TimingInfo.cs index 4ed7535374..530dfd89c4 100644 --- a/Ryujinx.Profiler/TimingInfo.cs +++ b/Ryujinx.Profiler/TimingInfo.cs @@ -117,15 +117,25 @@ namespace Ryujinx.Profiler } // Remove any timestamps before given timestamp to free memory - public void Cleanup(long before) + public void Cleanup(long before, long preserveStart, long preserveEnd) { lock (_timestampListLock) { - int toRemove = 0; + int toRemove = 0; + int toPreserveStart = 0; + int toPreserveLen = 0; for (int i = 0; i < _timestamps.Count; i++) { - if (_timestamps[i].EndTime < before) + if (_timestamps[i].EndTime < preserveStart) + { + toPreserveStart++; + } + else if (_timestamps[i].EndTime < preserveEnd) + { + toPreserveLen++; + } + else if (_timestamps[i].EndTime < before) { toRemove++; } @@ -136,9 +146,14 @@ namespace Ryujinx.Profiler } } + if (toPreserveStart > 0) + { + _timestamps.RemoveRange(0, toPreserveStart); + } + if (toRemove > 0) { - _timestamps.RemoveRange(0, toRemove); + _timestamps.RemoveRange(toPreserveStart + toPreserveLen, toRemove); } } } diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index 8da558179e..8cbf8ea460 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -217,6 +217,7 @@ namespace Ryujinx.Profiler.UI _updateTimer = 0; _unsortedProfileData = Profile.GetProfilingData().ToList(); _captureTime = Profile.GetCurrentTime(); + _timingFlags = Profile.GetTimingFlags(); _profileUpdated = true; } diff --git a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs index 84fd2fc639..5aa873282d 100644 --- a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs +++ b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs @@ -6,6 +6,8 @@ namespace Ryujinx.Profiler.UI { public partial class ProfileWindow { + private TimingFlag[] _timingFlags; + private const float GraphMoveSpeed = 40000; private const float GraphZoomSpeed = 50; @@ -33,11 +35,10 @@ namespace Ryujinx.Profiler.UI } // Draw timing flags - TimingFlag[] timingFlags = Profile.GetTimingFlags(); GL.Enable(EnableCap.ScissorTest); GL.Color3(Color.Gray); GL.Begin(PrimitiveType.Lines); - foreach (TimingFlag timingFlag in timingFlags) + foreach (TimingFlag timingFlag in _timingFlags) { int x = (int)(xOffset + width - ((float)(_captureTime - (timingFlag.Timestamp + graphPositionTicks)) / timeWidthTicks) * width); GL.Vertex2(x, 0);