diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 93c3a6ef4..f4ea92bd0 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -82,15 +82,18 @@ void StkTime::getDate(int *day, int *month, int *year) if(year) *year = now->tm_year + 1900; } // getDate +// ---------------------------------------------------------------------------- StkTime::ScopeProfiler::ScopeProfiler(const char* name) { Log::info("ScopeProfiler", "%s {\n", name); - m_time = (float)getRealTime(); + m_time = getRealTimeMs(); m_name = name; -} +} // StkTime::ScopeProfiler::ScopeProfiler +// ---------------------------------------------------------------------------- StkTime::ScopeProfiler::~ScopeProfiler() { - float f2 = (float)getRealTime(); - Log::info("ScopeProfiler", "} // took %f s (%s)\n", (f2 - m_time), m_name.c_str()); -} \ No newline at end of file + uint64_t difference = getRealTimeMs() - m_time; + Log::info("ScopeProfiler", "} // took %d ms (%s)\n", + (int)difference, m_name.c_str()); +} // StkTime::ScopeProfiler::ScopeProfiler diff --git a/src/utils/time.hpp b/src/utils/time.hpp index 7c44a6e6d..23340eee8 100644 --- a/src/utils/time.hpp +++ b/src/utils/time.hpp @@ -21,8 +21,11 @@ #include "ITimer.h" +#include #include +#include "utils/types.hpp" + #ifdef WIN32 # define WIN32_LEAN_AND_MEAN # include @@ -90,7 +93,20 @@ public: * The value is a double precision floating point value in seconds. */ static double getRealTime(long startAt=0); - + // ------------------------------------------------------------------------ + /** Returns a time based since epoch. + * The value is a 64bit unsigned integer in milliseconds. + */ + static uint64_t getRealTimeMs() + { + auto now = std::chrono::system_clock::now(); + auto now_ms = + std::chrono::time_point_cast(now); + auto epoch = now_ms.time_since_epoch(); + auto value = + std::chrono::duration_cast(epoch); + return value.count(); + } // ------------------------------------------------------------------------ /** * \brief Compare two different times. @@ -135,7 +151,7 @@ public: // ------------------------------------------------------------------------ class ScopeProfiler { - float m_time; + uint64_t m_time; std::string m_name; public: ScopeProfiler(const char* name);