mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-26 20:13:01 +00:00
4038e63de1
* implement basic frame time stats * added game frame time * made performancestatictics class non-static * report average framerate instead of current framerate
87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Timers;
|
|
|
|
namespace Ryujinx.Core
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|