diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index 4864232303..55f35d1585 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Profiler private Stopwatch SW; internal ConcurrentDictionary Timers; - private object sessionLock = new object(); + private readonly object sessionLock = new object(); private int sessionCounter = 0; public InternalProfile() diff --git a/Ryujinx.Profiler/Profile.cs b/Ryujinx.Profiler/Profile.cs index 7408b88c9b..336b5cb698 100644 --- a/Ryujinx.Profiler/Profile.cs +++ b/Ryujinx.Profiler/Profile.cs @@ -77,5 +77,10 @@ namespace Ryujinx.Profiler return new Dictionary(); return ProfileInstance.GetProfilingData(); } + + public static float GetUpdateRate() + { + return Settings.UpdateRate; + } } } diff --git a/Ryujinx.Profiler/Settings.cs b/Ryujinx.Profiler/Settings.cs index a023a21461..486cdd29bc 100644 --- a/Ryujinx.Profiler/Settings.cs +++ b/Ryujinx.Profiler/Settings.cs @@ -9,5 +9,6 @@ namespace Ryujinx.Profiler public bool Enabled = true; public bool FileDumpEnabled = false; public string DumpLocation = ""; + public float UpdateRate = 0.1f; } } diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index a3473b8ee9..7ec9094fdf 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -27,7 +27,7 @@ namespace Ryujinx private bool visible = true, initComplete = false; public bool visibleChanged; private FontService fontService; - private List> profileData; + private List> rawPofileData, profileData; private float scrollPos = 0; private float minScroll = 0, maxScroll = 0; @@ -36,8 +36,8 @@ namespace Ryujinx private IComparer> sortAction; private string FilterText = ""; - private double BackspaceDownTime = -1; - private bool BackspaceDown = false, prevBackspaceDown = false, regexEnabled = false; + private double BackspaceDownTime, UpdateTimer; + private bool BackspaceDown = false, prevBackspaceDown = false, regexEnabled = false, ProfileUpdated = false; public ProfileWindow() : base(400, 720) @@ -45,6 +45,10 @@ namespace Ryujinx Location = new Point(DisplayDevice.Default.Width - 400, (DisplayDevice.Default.Height - 720) / 2); Title = "Profiler"; sortAction = null; + BackspaceDownTime = 0; + + // Large number to force an update on first update + UpdateTimer = 0xFFFF; } #region Public Methods @@ -137,32 +141,47 @@ namespace Ryujinx } prevBackspaceDown = BackspaceDown; - // Filtering - profileData = Profile.GetProfilingData().ToList(); - if (sortAction != null) + // Get timing data if enough time has passed + UpdateTimer += e.Time; + if (UpdateTimer > Profile.GetUpdateRate()) { - profileData.Sort(sortAction); + UpdateTimer %= Profile.GetUpdateRate(); + rawPofileData = Profile.GetProfilingData().ToList(); + ProfileUpdated = true; } - - if (regexEnabled) + + // Filtering + if (ProfileUpdated) { - try + profileData = rawPofileData; + + if (sortAction != null) { - Regex filterRegex = new Regex(FilterText, RegexOptions.IgnoreCase); - if (FilterText != "") + profileData.Sort(sortAction); + } + + if (regexEnabled) + { + try { - profileData = profileData.Where((pair => filterRegex.IsMatch(pair.Key.Search))).ToList(); + Regex filterRegex = new Regex(FilterText, RegexOptions.IgnoreCase); + if (FilterText != "") + { + profileData = profileData.Where((pair => filterRegex.IsMatch(pair.Key.Search))).ToList(); + } + } + catch (ArgumentException argException) + { + // Skip filtering for invalid regex } } - catch (ArgumentException argException) + else { - // Skip filtering for invalid regex + // Regular filtering + profileData = profileData.Where((pair => pair.Key.Search.ToLower().Contains(FilterText.ToLower()))).ToList(); } - } - else - { - // Regular filtering - profileData = profileData.Where((pair => pair.Key.Search.ToLower().Contains(FilterText.ToLower()))).ToList(); + + ProfileUpdated = false; } } #endregion @@ -421,13 +440,14 @@ namespace Ryujinx protected override void OnKeyPress(KeyPressEventArgs e) { FilterText += e.KeyChar; + ProfileUpdated = true; } protected override void OnKeyDown(KeyboardKeyEventArgs e) { if (e.Key == Key.BackSpace) { - BackspaceDown = true; + ProfileUpdated = BackspaceDown = true; return; } base.OnKeyUp(e); diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index 629d65493a..e76be6d0d0 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -72,6 +72,7 @@ namespace Ryujinx Enabled = Convert.ToBoolean(parser.Value("Profiling_Enabled")), FileDumpEnabled = profilePath != "", DumpLocation = profilePath, + UpdateRate = 1.0f / Convert.ToInt32(parser.Value("Profiling_Update_Rate")), }); SystemLanguage SetLanguage = Enum.Parse(parser.Value("System_Language")); diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index 2e15aac4d9..18e0ae7d58 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -28,6 +28,9 @@ Profiling_Enabled = true #Set profile file dump location, if blank file dumping disabled. (e.g. `ProfileDump.csv`) Profile_Dump_Path = ProfileDump.csv +#Update rate for profiler UI, in hertz +Profiling_Update_Rate = 4 + #System Language list: https://gist.github.com/HorrorTroll/b6e4a88d774c3c9b3bdf54d79a7ca43b #Change System Language System_Language = AmericanEnglish