Fix threading conflict
Fixed instant count and time. Now accuratly represents the total time and count in the buffer
This commit is contained in:
parent
27d8435972
commit
ca0a87a0cf
2 changed files with 17 additions and 16 deletions
|
@ -60,11 +60,17 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
while (_cleanupRunning)
|
while (_cleanupRunning)
|
||||||
{
|
{
|
||||||
ClearTimerQueue();
|
// Ensure we only ever have 1 instance modifying timers or timerQueue
|
||||||
|
if (Monitor.TryEnter(_timerQueueClearLock))
|
||||||
foreach (var timer in Timers)
|
|
||||||
{
|
{
|
||||||
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
|
// No need to run too often
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue