/ src / Ryujinx.Common / PerformanceCounter.cs
PerformanceCounter.cs
 1  using System.Diagnostics;
 2  
 3  namespace Ryujinx.Common
 4  {
 5      public static class PerformanceCounter
 6      {
 7          private static readonly double _ticksToNs;
 8  
 9          /// <summary>
10          /// Represents the number of ticks in 1 day.
11          /// </summary>
12          public static long TicksPerDay { get; }
13  
14          /// <summary>
15          /// Represents the number of ticks in 1 hour.
16          /// </summary>
17          public static long TicksPerHour { get; }
18  
19          /// <summary>
20          /// Represents the number of ticks in 1 minute.
21          /// </summary>
22          public static long TicksPerMinute { get; }
23  
24          /// <summary>
25          /// Represents the number of ticks in 1 second.
26          /// </summary>
27          public static long TicksPerSecond { get; }
28  
29          /// <summary>
30          /// Represents the number of ticks in 1 millisecond.
31          /// </summary>
32          public static long TicksPerMillisecond { get; }
33  
34          /// <summary>
35          /// Gets the number of ticks elapsed since the system started.
36          /// </summary>
37          public static long ElapsedTicks
38          {
39              get
40              {
41                  return Stopwatch.GetTimestamp();
42              }
43          }
44  
45          /// <summary>
46          /// Gets the number of milliseconds elapsed since the system started.
47          /// </summary>
48          public static long ElapsedMilliseconds
49          {
50              get
51              {
52                  long timestamp = Stopwatch.GetTimestamp();
53  
54                  return timestamp / TicksPerMillisecond;
55              }
56          }
57  
58          /// <summary>
59          /// Gets the number of nanoseconds elapsed since the system started.
60          /// </summary>
61          public static long ElapsedNanoseconds
62          {
63              get
64              {
65                  long timestamp = Stopwatch.GetTimestamp();
66  
67                  return (long)(timestamp * _ticksToNs);
68              }
69          }
70  
71          static PerformanceCounter()
72          {
73              TicksPerMillisecond = Stopwatch.Frequency / 1000;
74              TicksPerSecond = Stopwatch.Frequency;
75              TicksPerMinute = TicksPerSecond * 60;
76              TicksPerHour = TicksPerMinute * 60;
77              TicksPerDay = TicksPerHour * 24;
78  
79              _ticksToNs = 1000000000.0 / Stopwatch.Frequency;
80          }
81      }
82  }