Merge branch 'profiling' into actually_profiling

This commit is contained in:
Andy Adshead 2019-02-01 23:35:57 +00:00
commit 0bd1b3bdd9
3 changed files with 27 additions and 21 deletions

View file

@ -59,6 +59,9 @@ namespace Ryujinx.Profiler
private void CleanupLoop() private void CleanupLoop()
{ {
while (_cleanupRunning) while (_cleanupRunning)
{
// Ensure we only ever have 1 instance modifying timers or timerQueue
if (Monitor.TryEnter(_timerQueueClearLock))
{ {
ClearTimerQueue(); ClearTimerQueue();
@ -67,6 +70,9 @@ namespace Ryujinx.Profiler
timer.Value.Cleanup(PerformanceCounter.ElapsedTicks - _history, _preserve - _history, _preserve); timer.Value.Cleanup(PerformanceCounter.ElapsedTicks - _history, _preserve - _history, _preserve);
} }
Monitor.Exit(_timerQueueClearLock);
}
// No need to run too often // No need to run too often
Thread.Sleep(5); Thread.Sleep(5);
} }
@ -74,12 +80,6 @@ namespace Ryujinx.Profiler
private void ClearTimerQueue() private void ClearTimerQueue()
{ {
// Ensure we only ever have 1 instance running
if (!Monitor.TryEnter(_timerQueueClearLock))
{
return;
}
while (_timerQueue.TryDequeue(out var item)) while (_timerQueue.TryDequeue(out var item))
{ {
if (!Timers.TryGetValue(item.Config, out var value)) if (!Timers.TryGetValue(item.Config, out var value))
@ -97,7 +97,6 @@ namespace Ryujinx.Profiler
value.End(item.Time); value.End(item.Time);
} }
} }
Monitor.Exit(_timerQueueClearLock);
} }
public void FlagTime(TimingFlagType flagType) public void FlagTime(TimingFlagType flagType)
@ -150,13 +149,11 @@ namespace Ryujinx.Profiler
public Dictionary<ProfileConfig, TimingInfo> GetProfilingData() public Dictionary<ProfileConfig, TimingInfo> GetProfilingData()
{ {
_preserve = PerformanceCounter.ElapsedTicks; _preserve = PerformanceCounter.ElapsedTicks;
ClearTimerQueue();
// Reset all instant counts // Make sure to clear queue
foreach (KeyValuePair<ProfileConfig, TimingInfo> timer in Timers) lock (_timerQueueClearLock)
{ {
timer.Value.Instant = 0; ClearTimerQueue();
timer.Value.InstantCount = 0;
} }
return Timers; return Timers;

View file

@ -130,6 +130,8 @@ namespace Ryujinx.Profiler
if (_timestamps[i].EndTime < preserveStart) if (_timestamps[i].EndTime < preserveStart)
{ {
toPreserveStart++; toPreserveStart++;
InstantCount--;
Instant -= _timestamps[i].EndTime - _timestamps[i].BeginTime;
} }
else if (_timestamps[i].EndTime < preserveEnd) else if (_timestamps[i].EndTime < preserveEnd)
{ {
@ -138,6 +140,8 @@ namespace Ryujinx.Profiler
else if (_timestamps[i].EndTime < before) else if (_timestamps[i].EndTime < before)
{ {
toRemove++; toRemove++;
InstantCount--;
Instant -= _timestamps[i].EndTime - _timestamps[i].BeginTime;
} }
else else
{ {

View file

@ -522,9 +522,14 @@ namespace Ryujinx.Profiler.UI
foreach (var entry in _sortedProfileData) foreach (var entry in _sortedProfileData)
{ {
float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++); 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); float instant = (float)entry.Value.Instant / PerformanceCounter.TicksPerMillisecond;
_fontService.DrawText($"{entry.Value.TotalTime / PerformanceCounter.TicksPerMillisecond:F3}", 260 + xOffset, y, LineHeight); _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; totalInstant += entry.Value.Instant;
totalAverage += entry.Value.AverageTime; totalAverage += entry.Value.AverageTime;
@ -535,10 +540,10 @@ namespace Ryujinx.Profiler.UI
float yHeight = Height - TitleFontHeight; 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); _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); _buttons[(int)ButtonIndex.AverageTitle].UpdateSize((int)(150 + xOffset), (int)yHeight, 0, 130, TitleFontHeight);
_fontService.DrawText("Total (ms)", 260 + xOffset, yHeight, TitleFontHeight); _fontService.DrawText("Total (ms)", 260 + xOffset, yHeight, TitleFontHeight);