2018-03-10 02:12:57 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-03-06 20:18:49 +00:00
|
|
|
|
using System.Timers;
|
|
|
|
|
|
2018-06-11 00:46:42 +00:00
|
|
|
|
namespace Ryujinx.HLE
|
2018-03-06 20:18:49 +00:00
|
|
|
|
{
|
|
|
|
|
public class PerformanceStatistics
|
|
|
|
|
{
|
|
|
|
|
Stopwatch ExecutionTime = new Stopwatch();
|
|
|
|
|
Timer ResetTimer = new Timer(1000);
|
|
|
|
|
|
|
|
|
|
long CurrentGameFrameEnded;
|
|
|
|
|
long CurrentSystemFrameEnded;
|
|
|
|
|
long CurrentSystemFrameStart;
|
|
|
|
|
long LastGameFrameEnded;
|
|
|
|
|
long LastSystemFrameEnded;
|
|
|
|
|
|
|
|
|
|
double AccumulatedGameFrameTime;
|
|
|
|
|
double AccumulatedSystemFrameTime;
|
|
|
|
|
double CurrentGameFrameTime;
|
|
|
|
|
double CurrentSystemFrameTime;
|
|
|
|
|
double PreviousGameFrameTime;
|
|
|
|
|
double PreviousSystemFrameTime;
|
|
|
|
|
public double GameFrameRate { get; private set; }
|
|
|
|
|
public double SystemFrameRate { get; private set; }
|
|
|
|
|
public long SystemFramesRendered;
|
|
|
|
|
public long GameFramesRendered;
|
|
|
|
|
public long ElapsedMilliseconds => ExecutionTime.ElapsedMilliseconds;
|
|
|
|
|
public long ElapsedMicroseconds => (long)
|
|
|
|
|
(((double)ExecutionTime.ElapsedTicks / Stopwatch.Frequency) * 1000000);
|
|
|
|
|
public long ElapsedNanoseconds => (long)
|
|
|
|
|
(((double)ExecutionTime.ElapsedTicks / Stopwatch.Frequency) * 1000000000);
|
|
|
|
|
|
|
|
|
|
public PerformanceStatistics()
|
|
|
|
|
{
|
|
|
|
|
ExecutionTime.Start();
|
|
|
|
|
ResetTimer.Elapsed += ResetTimerElapsed;
|
|
|
|
|
ResetTimer.AutoReset = true;
|
|
|
|
|
ResetTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetTimerElapsed(object sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ResetStatistics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartSystemFrame()
|
|
|
|
|
{
|
|
|
|
|
PreviousSystemFrameTime = CurrentSystemFrameTime;
|
|
|
|
|
LastSystemFrameEnded = CurrentSystemFrameEnded;
|
|
|
|
|
CurrentSystemFrameStart = ElapsedMicroseconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EndSystemFrame()
|
|
|
|
|
{
|
|
|
|
|
CurrentSystemFrameEnded = ElapsedMicroseconds;
|
|
|
|
|
CurrentSystemFrameTime = CurrentSystemFrameEnded - CurrentSystemFrameStart;
|
|
|
|
|
AccumulatedSystemFrameTime += CurrentSystemFrameTime;
|
|
|
|
|
SystemFramesRendered++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RecordGameFrameTime()
|
|
|
|
|
{
|
|
|
|
|
CurrentGameFrameEnded = ElapsedMicroseconds;
|
|
|
|
|
CurrentGameFrameTime = CurrentGameFrameEnded - LastGameFrameEnded;
|
|
|
|
|
PreviousGameFrameTime = CurrentGameFrameTime;
|
|
|
|
|
LastGameFrameEnded = CurrentGameFrameEnded;
|
|
|
|
|
AccumulatedGameFrameTime += CurrentGameFrameTime;
|
|
|
|
|
GameFramesRendered++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetStatistics()
|
|
|
|
|
{
|
|
|
|
|
GameFrameRate = 1000 / ((AccumulatedGameFrameTime / GameFramesRendered) / 1000);
|
|
|
|
|
GameFrameRate = double.IsNaN(GameFrameRate) ? 0 : GameFrameRate;
|
|
|
|
|
SystemFrameRate = 1000 / ((AccumulatedSystemFrameTime / SystemFramesRendered) / 1000);
|
|
|
|
|
SystemFrameRate = double.IsNaN(SystemFrameRate) ? 0 : SystemFrameRate;
|
|
|
|
|
|
|
|
|
|
GameFramesRendered = 0;
|
|
|
|
|
SystemFramesRendered = 0;
|
|
|
|
|
AccumulatedGameFrameTime = 0;
|
|
|
|
|
AccumulatedSystemFrameTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|