| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include "Common/CommonTypes.h" |
| 7 |
|
| 8 |
namespace Common |
| 9 |
{ |
| 10 |
class Timer |
| 11 |
{ |
| 12 |
public: |
| 13 |
static u64 NowUs(); |
| 14 |
static u64 NowMs(); |
| 15 |
|
| 16 |
void Start(); |
| 17 |
|
| 18 |
|
| 19 |
void StartWithOffset(u64 offset); |
| 20 |
void Stop(); |
| 21 |
u64 ElapsedMs() const; |
| 22 |
|
| 23 |
|
| 24 |
static u64 GetLocalTimeSinceJan1970(); |
| 25 |
|
| 26 |
static void IncreaseResolution(); |
| 27 |
static void RestoreResolution(); |
| 28 |
|
| 29 |
private: |
| 30 |
u64 m_start_ms{0}; |
| 31 |
u64 m_end_ms{0}; |
| 32 |
bool m_running{false}; |
| 33 |
}; |
| 34 |
|
| 35 |
class PrecisionTimer |
| 36 |
{ |
| 37 |
public: |
| 38 |
PrecisionTimer(); |
| 39 |
~PrecisionTimer(); |
| 40 |
|
| 41 |
PrecisionTimer(const PrecisionTimer&) = delete; |
| 42 |
PrecisionTimer& operator=(const PrecisionTimer&) = delete; |
| 43 |
|
| 44 |
void SleepUntil(Clock::time_point); |
| 45 |
|
| 46 |
private: |
| 47 |
#ifdef _WIN32 |
| 48 |
|
| 49 |
void* m_timer_handle; |
| 50 |
#endif |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
class SteadyAwakeClock |
| 56 |
{ |
| 57 |
public: |
| 58 |
using rep = s64; |
| 59 |
using period = std::nano; |
| 60 |
using duration = std::chrono::duration<rep, period>; |
| 61 |
using time_point = std::chrono::time_point<SteadyAwakeClock>; |
| 62 |
|
| 63 |
static constexpr bool is_steady = true; |
| 64 |
|
| 65 |
static time_point now(); |
| 66 |
}; |
| 67 |
|
| 68 |
} |