From 94d9d138d9b8547dc63a705014a5f5b874472613 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 19 Nov 2014 19:57:12 +0100 Subject: Common: Add a built-in profiler --- Source/Core/Common/Timer.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Source/Core/Common/Timer.cpp') diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index 1ba750ae99..025fddeba6 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -32,6 +32,29 @@ u32 Timer::GetTimeMs() #endif } +#ifdef _WIN32 +double GetFreq() +{ + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return 1000000.0 / double(freq.QuadPart); +} +#endif + +u64 Timer::GetTimeUs() +{ +#ifdef _WIN32 + LARGE_INTEGER time; + static double freq = GetFreq(); + QueryPerformanceCounter(&time); + return u64(double(time.QuadPart) * freq); +#else + struct timeval t; + (void)gettimeofday(&t, nullptr); + return ((u64)(t.tv_sec * 1000000 + t.tv_usec)); +#endif +} + // -------------------------------------------- // Initiate, Start, Stop, and Update the time // -------------------------------------------- -- cgit v1.2.3