From 6ecb6cfd86a76917c0c5f3539d84e37c689f76f3 Mon Sep 17 00:00:00 2001 From: Andy Adshead Date: Sun, 17 Feb 2019 01:22:54 +0000 Subject: [PATCH] enable and disable flags button added better fix for race crash --- Ryujinx.Profiler/InternalProfile.cs | 10 ++--- Ryujinx.Profiler/Profile.cs | 6 +-- Ryujinx.Profiler/UI/ProfileWindow.cs | 55 ++++++++++++++++------- Ryujinx.Profiler/UI/ProfileWindowGraph.cs | 38 +++++++++------- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index df3f5a3c84..d817f32e48 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Ryujinx.Common; @@ -178,18 +179,15 @@ namespace Ryujinx.Profiler } } - public Dictionary GetProfilingData() + public List> GetProfilingData() { _preserve = PerformanceCounter.ElapsedTicks; - // Skip clearing queue if already clearing - if (Monitor.TryEnter(_timerQueueClearLock)) + lock (_timerQueueClearLock) { ClearTimerQueue(); - Monitor.Exit(_timerQueueClearLock); + return Timers.ToList(); } - - return Timers; } public TimingFlag[] GetTimingFlags() diff --git a/Ryujinx.Profiler/Profile.cs b/Ryujinx.Profiler/Profile.cs index 9b51076a31..950c220f15 100644 --- a/Ryujinx.Profiler/Profile.cs +++ b/Ryujinx.Profiler/Profile.cs @@ -107,14 +107,14 @@ namespace Ryujinx.Profiler #endif } - public static Dictionary GetProfilingData() + public static List> GetProfilingData() { #if USE_PROFILING if (!ProfilingEnabled()) - return new Dictionary(); + return new List>(); return _profileInstance.GetProfilingData(); #else - return new Dictionary(); + return new List>(); #endif } diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index 6990c982b5..407c80c2eb 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -27,10 +27,11 @@ namespace Ryujinx.Profiler.UI ChangeDisplay = 7, // Don't automatically draw after here - Step = 8, + ToggleFlags = 8, + Step = 9, // Update this when new buttons are added - Count = 9, + Count = 10, Autodraw = 8, } @@ -46,6 +47,7 @@ namespace Ryujinx.Profiler.UI private bool _viewportUpdated = true; private bool _redrawPending = true; private bool _displayGraph = true; + private bool _displayFlags = true; private bool _showInactive = true; private bool _paused = false; private bool _doStep = false; @@ -151,7 +153,6 @@ namespace Ryujinx.Profiler.UI _buttons[(int)ButtonIndex.InstantTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.InstantAscending())); _buttons[(int)ButtonIndex.AverageTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.AverageAscending())); _buttons[(int)ButtonIndex.TotalTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.TotalAscending())); - _buttons[(int)ButtonIndex.ChangeDisplay] = new ProfileButton(_fontService, () => _displayGraph = !_displayGraph); _buttons[(int)ButtonIndex.Step] = new ProfileButton(_fontService, () => _doStep = true); _buttons[(int)ButtonIndex.FilterBar] = new ProfileButton(_fontService, () => { @@ -171,6 +172,18 @@ namespace Ryujinx.Profiler.UI _paused = !_paused; }); + _buttons[(int)ButtonIndex.ToggleFlags] = new ProfileButton(_fontService, () => + { + _displayFlags = !_displayFlags; + _redrawPending = true; + }); + + _buttons[(int)ButtonIndex.ChangeDisplay] = new ProfileButton(_fontService, () => + { + _displayGraph = !_displayGraph; + _redrawPending = true; + }); + Visible = _visible; } #endregion @@ -242,18 +255,15 @@ namespace Ryujinx.Profiler.UI _updateTimer += e.Time; if (_doStep || ((Profile.UpdateRate > 0) && (!_paused && (_updateTimer > Profile.UpdateRate)))) { - _updateTimer = 0; - _captureTime = PerformanceCounter.ElapsedTicks; - _timingFlags = Profile.GetTimingFlags(); - _doStep = false; + _updateTimer = 0; + _captureTime = PerformanceCounter.ElapsedTicks; + _timingFlags = Profile.GetTimingFlags(); + _doStep = false; + _profileUpdated = true; - Dictionary data = Profile.GetProfilingData(); - if (data.Count > 0) - { - (_timingFlagsAverages, _timingFlagsLast) = Profile.GetTimingAveragesAndLast(); - _unsortedProfileData = data.ToList(); - _profileUpdated = true; - } + _unsortedProfileData = Profile.GetProfilingData(); + (_timingFlagsAverages, _timingFlagsLast) = Profile.GetTimingAveragesAndLast(); + } // Filtering @@ -593,7 +603,15 @@ namespace Ryujinx.Profiler.UI } // Change display - width = _buttons[(int)ButtonIndex.ChangeDisplay].UpdateSize($"View: {(_displayGraph ? "Graph" : "Bars")}", 25 + (int)widthStepButton, 5, 4, 16) + widthStepButton; + float widthChangeDisplay = _buttons[(int)ButtonIndex.ChangeDisplay].UpdateSize($"View: {(_displayGraph ? "Graph" : "Bars")}", 25 + (int)widthStepButton, 5, 4, 16) + widthStepButton; + + width = widthChangeDisplay; + + if (_displayGraph) + { + width += _buttons[(int) ButtonIndex.ToggleFlags].UpdateSize($"{(_displayFlags ? "Hide" : "Show")} Flags", 35 + (int)widthChangeDisplay, 5, 4, 16) + 10; + _buttons[(int)ButtonIndex.ToggleFlags].Draw(); + } // Filter bar _fontService.DrawText($"{(_regexEnabled ? "Regex " : "Filter")}: {_filterText}", 35 + width, 7, 16); @@ -634,6 +652,12 @@ namespace Ryujinx.Profiler.UI GL.Vertex2(widthStepButton + 20, FilterHeight); } + if (_displayGraph) + { + GL.Vertex2(widthChangeDisplay + 30, 0); + GL.Vertex2(widthChangeDisplay + 30, FilterHeight); + } + GL.Vertex2(width + 30, 0); GL.Vertex2(width + 30, FilterHeight); @@ -642,7 +666,6 @@ namespace Ryujinx.Profiler.UI GL.Vertex2(timingDataLeft, FilterHeight); GL.Vertex2(timingDataLeft, timingDataTop); - GL.Vertex2(timingWidth + timingDataLeft, FilterHeight); GL.Vertex2(timingWidth + timingDataLeft, timingDataTop); diff --git a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs index 4bb8f6e64b..9d34be977f 100644 --- a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs +++ b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs @@ -46,28 +46,32 @@ namespace Ryujinx.Profiler.UI graphPositionTicks = _captureTime - graphPositionTicks; - // Draw timing flags - TimingFlagType prevType = TimingFlagType.Count; - GL.Enable(EnableCap.ScissorTest); - GL.Enable(EnableCap.Blend); - GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); - GL.Begin(PrimitiveType.Lines); - foreach (TimingFlag timingFlag in _timingFlags) + // Draw timing flags + if (_displayFlags) { - if (prevType != timingFlag.FlagType) - { - prevType = timingFlag.FlagType; - GL.Color4(_timingFlagColours[(int)prevType]); - } + TimingFlagType prevType = TimingFlagType.Count; - int x = (int)(graphRight - ((graphPositionTicks - timingFlag.Timestamp) / timeWidthTicks) * width); - GL.Vertex2(x, 0); - GL.Vertex2(x, Height); + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + + GL.Begin(PrimitiveType.Lines); + foreach (TimingFlag timingFlag in _timingFlags) + { + if (prevType != timingFlag.FlagType) + { + prevType = timingFlag.FlagType; + GL.Color4(_timingFlagColours[(int)prevType]); + } + + int x = (int)(graphRight - ((graphPositionTicks - timingFlag.Timestamp) / timeWidthTicks) * width); + GL.Vertex2(x, 0); + GL.Vertex2(x, Height); + } + GL.End(); + GL.Disable(EnableCap.Blend); } - GL.End(); - GL.Disable(EnableCap.Blend); // Draw bars GL.Begin(PrimitiveType.Triangles);