2019-10-12 23:02:07 -07:00
|
|
|
|
using System.Diagnostics;
|
2018-10-28 15:31:13 -07:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common
|
|
|
|
|
{
|
|
|
|
|
public static class PerformanceCounter
|
|
|
|
|
{
|
2019-10-12 23:02:07 -07:00
|
|
|
|
private static double _ticksToNs;
|
|
|
|
|
|
2018-10-28 15:31:13 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the number of ticks in 1 day.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long TicksPerDay { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the number of ticks in 1 hour.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long TicksPerHour { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the number of ticks in 1 minute.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long TicksPerMinute { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the number of ticks in 1 second.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long TicksPerSecond { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the number of ticks in 1 millisecond.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long TicksPerMillisecond { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-09 14:20:05 -08:00
|
|
|
|
/// Gets the number of ticks elapsed since the system started.
|
2018-10-28 15:31:13 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static long ElapsedTicks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Stopwatch.GetTimestamp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the number of milliseconds elapsed since the system started.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long ElapsedMilliseconds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
long timestamp = Stopwatch.GetTimestamp();
|
|
|
|
|
|
|
|
|
|
return timestamp / TicksPerMillisecond;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the number of nanoseconds elapsed since the system started.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static long ElapsedNanoseconds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
long timestamp = Stopwatch.GetTimestamp();
|
|
|
|
|
|
|
|
|
|
return (long)(timestamp * _ticksToNs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 15:31:13 -07:00
|
|
|
|
static PerformanceCounter()
|
|
|
|
|
{
|
|
|
|
|
TicksPerMillisecond = Stopwatch.Frequency / 1000;
|
|
|
|
|
TicksPerSecond = Stopwatch.Frequency;
|
|
|
|
|
TicksPerMinute = TicksPerSecond * 60;
|
|
|
|
|
TicksPerHour = TicksPerMinute * 60;
|
|
|
|
|
TicksPerDay = TicksPerHour * 24;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2020-12-09 14:20:05 -08:00
|
|
|
|
_ticksToNs = 1000000000.0 / Stopwatch.Frequency;
|
2018-10-28 15:31:13 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|