diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index 9cb1eed65c..75f9581e54 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -60,11 +60,17 @@ namespace Ryujinx.Profiler { while (_cleanupRunning) { - ClearTimerQueue(); - - foreach (var timer in Timers) + // Ensure we only ever have 1 instance modifying timers or timerQueue + if (Monitor.TryEnter(_timerQueueClearLock)) { - timer.Value.Cleanup(PerformanceCounter.ElapsedTicks - _history, _preserve - _history, _preserve); + ClearTimerQueue(); + + foreach (var timer in Timers) + { + timer.Value.Cleanup(PerformanceCounter.ElapsedTicks - _history, _preserve - _history, _preserve); + } + + Monitor.Exit(_timerQueueClearLock); } // No need to run too often @@ -74,12 +80,6 @@ namespace Ryujinx.Profiler private void ClearTimerQueue() { - // Ensure we only ever have 1 instance running - if (!Monitor.TryEnter(_timerQueueClearLock)) - { - return; - } - while (_timerQueue.TryDequeue(out var item)) { if (!Timers.TryGetValue(item.Config, out var value)) @@ -97,7 +97,6 @@ namespace Ryujinx.Profiler value.End(item.Time); } } - Monitor.Exit(_timerQueueClearLock); } public void FlagTime(TimingFlagType flagType) @@ -150,13 +149,11 @@ namespace Ryujinx.Profiler public Dictionary GetProfilingData() { _preserve = PerformanceCounter.ElapsedTicks; - ClearTimerQueue(); - // Reset all instant counts - foreach (KeyValuePair timer in Timers) + // Make sure to clear queue + lock (_timerQueueClearLock) { - timer.Value.Instant = 0; - timer.Value.InstantCount = 0; + ClearTimerQueue(); } return Timers; diff --git a/Ryujinx.Profiler/TimingInfo.cs b/Ryujinx.Profiler/TimingInfo.cs index 4bf7d21296..23d6a5173f 100644 --- a/Ryujinx.Profiler/TimingInfo.cs +++ b/Ryujinx.Profiler/TimingInfo.cs @@ -130,6 +130,8 @@ namespace Ryujinx.Profiler if (_timestamps[i].EndTime < preserveStart) { toPreserveStart++; + InstantCount--; + Instant -= _timestamps[i].EndTime - _timestamps[i].BeginTime; } else if (_timestamps[i].EndTime < preserveEnd) { @@ -138,6 +140,8 @@ namespace Ryujinx.Profiler else if (_timestamps[i].EndTime < before) { toRemove++; + InstantCount--; + Instant -= _timestamps[i].EndTime - _timestamps[i].BeginTime; } else { diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index 8e8ff4ea10..38844aa3da 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -522,9 +522,14 @@ namespace Ryujinx.Profiler.UI foreach (var entry in _sortedProfileData) { float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++); - _fontService.DrawText($"{entry.Value.Instant / PerformanceCounter.TicksPerMillisecond:F3} ({entry.Value.InstantCount})", xOffset, y, LineHeight); - _fontService.DrawText($"{entry.Value.AverageTime / PerformanceCounter.TicksPerMillisecond:F3}", 150 + xOffset, y, LineHeight); - _fontService.DrawText($"{entry.Value.TotalTime / PerformanceCounter.TicksPerMillisecond:F3}", 260 + xOffset, y, LineHeight); + + float instant = (float)entry.Value.Instant / PerformanceCounter.TicksPerMillisecond; + _fontService.DrawText($"{((instant < 1) ? $"{instant * 1000:F3}us" : $"{instant:F3}ms")} ({entry.Value.InstantCount})", xOffset, y, LineHeight); + + float average = (float)entry.Value.AverageTime / PerformanceCounter.TicksPerMillisecond; + _fontService.DrawText((average < 1) ? $"{average * 1000:F3}us" : $"{average:F3}ms", 150 + xOffset, y, LineHeight); + + _fontService.DrawText($"{(float)entry.Value.TotalTime / PerformanceCounter.TicksPerMillisecond:F3}", 260 + xOffset, y, LineHeight); totalInstant += entry.Value.Instant; totalAverage += entry.Value.AverageTime; @@ -535,10 +540,10 @@ namespace Ryujinx.Profiler.UI float yHeight = Height - TitleFontHeight; - _fontService.DrawText("Instant (ms, count)", xOffset, yHeight, TitleFontHeight); + _fontService.DrawText("Instant (Count)", xOffset, yHeight, TitleFontHeight); _buttons[(int)ButtonIndex.InstantTitle].UpdateSize((int)xOffset, (int)yHeight, 0, 130, TitleFontHeight); - _fontService.DrawText("Average (ms)", 150 + xOffset, yHeight, TitleFontHeight); + _fontService.DrawText("Average", 150 + xOffset, yHeight, TitleFontHeight); _buttons[(int)ButtonIndex.AverageTitle].UpdateSize((int)(150 + xOffset), (int)yHeight, 0, 130, TitleFontHeight); _fontService.DrawText("Total (ms)", 260 + xOffset, yHeight, TitleFontHeight);