diff --git a/src/common/Profiler.cpp b/src/common/Profiler.cpp index a606cfa..142f0ee 100644 --- a/src/common/Profiler.cpp +++ b/src/common/Profiler.cpp @@ -50,7 +50,7 @@ Profiler::m_worstCalls; static Mutex profileMutex; void -Profiler::add(const char *id, float ms) +Profiler::add(const char *id, double ms) { profileMutex.lock(); @@ -95,7 +95,7 @@ Profiler::getReport() #endif report += buffer; - typedef std::multimap TimeRMap; + typedef std::multimap TimeRMap; typedef std::multimap IntRMap; TimeRMap totmap, avgmap, worstmap; IntRMap ncallmap; @@ -186,11 +186,7 @@ Profiler::Profiler(const char* c) : m_c(c), m_ended(false) { -#ifdef PROFILE_CLOCKS - m_start = clock(); -#else - (void)gettimeofday(&m_start, 0); -#endif + m_start = std::chrono::steady_clock::now(); } Profiler::~Profiler() @@ -201,25 +197,9 @@ Profiler::~Profiler() void Profiler::end() { -#ifdef PROFILE_CLOCKS - clock_t end = clock(); - clock_t elapsed = end - m_start; - float ms = float((double(elapsed) / double(CLOCKS_PER_SEC)) * 1000.0); -#else - struct timeval tv; - (void)gettimeofday(&tv, 0); - - tv.tv_sec -= m_start.tv_sec; - if (tv.tv_usec < m_start.tv_usec) { - tv.tv_usec += 1000000; - tv.tv_sec -= 1; - } - tv.tv_usec -= m_start.tv_usec; - float ms = float((double(tv.tv_sec) + (double(tv.tv_usec) / 1000000.0)) * 1000.0); -#endif - - add(m_c, ms); - + auto finish = std::chrono::steady_clock::now(); + std::chrono::duration ms = finish - m_start; + add(m_c, ms.count()); m_ended = true; } diff --git a/src/common/Profiler.h b/src/common/Profiler.h index 37ec04c..dbb923d 100644 --- a/src/common/Profiler.h +++ b/src/common/Profiler.h @@ -39,14 +39,7 @@ #endif #ifndef NO_TIMING -#ifdef PROFILE_CLOCKS -#include -#else -#include "sysutils.h" -#ifndef _WIN32 -#include -#endif -#endif +#include #endif #ifndef NO_TIMING @@ -75,21 +68,17 @@ public: static std::string getReport(); protected: - const char* m_c; -#ifdef PROFILE_CLOCKS - clock_t m_start; -#else - struct timeval m_start; -#endif + const char *const m_c; + std::chrono::time_point m_start; bool m_showOnDestruct; bool m_ended; - typedef std::pair TimePair; + typedef std::pair TimePair; typedef std::map ProfileMap; - typedef std::map WorstCallMap; + typedef std::map WorstCallMap; static ProfileMap m_profiles; static WorstCallMap m_worstCalls; - static void add(const char *, float); + static void add(const char *, double); }; #else diff --git a/src/common/sysutils.cpp b/src/common/sysutils.cpp index 6f36ae0..0a13b7e 100644 --- a/src/common/sysutils.cpp +++ b/src/common/sysutils.cpp @@ -150,22 +150,6 @@ system_is_multiprocessor() return mp; } -#ifdef _WIN32 - -void gettimeofday(struct timeval *tv, void *tz) -{ - union { - long long ns100; - FILETIME ft; - } now; - - ::GetSystemTimeAsFileTime(&now.ft); - tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); - tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL); -} - -#endif - void system_specific_initialise() { #if defined HAVE_IPP diff --git a/src/common/sysutils.h b/src/common/sysutils.h index 9bcdd9a..c59e1bf 100644 --- a/src/common/sysutils.h +++ b/src/common/sysutils.h @@ -99,11 +99,6 @@ extern bool system_is_multiprocessor(); extern void system_specific_initialise(); extern void system_specific_application_initialise(); -#ifdef _WIN32 -struct timeval { long tv_sec; long tv_usec; }; -void gettimeofday(struct timeval *p, void *tz); -#endif // _WIN32 - } // end namespace // The following should be functions in the RubberBand namespace, really