diff --git a/include/blt/std/time.h b/include/blt/std/time.h index 50d6759..970294d 100755 --- a/include/blt/std/time.h +++ b/include/blt/std/time.h @@ -43,23 +43,23 @@ namespace blt::system return std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); } - static inline auto getCPUThreadTime() + static inline int64_t getCPUThreadTime() { #ifdef unix timespec time{}; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time); - return time.tv_nsec; + return time.tv_sec * static_cast(1e9) + time.tv_nsec; #else return std::clock(); #endif } - static inline auto getCPUTime() + static inline int64_t getCPUTime() { #ifdef unix timespec time{}; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time); - return time.tv_nsec; + return time.tv_sec * static_cast(1e9) + time.tv_nsec; #else return std::clock(); #endif @@ -70,7 +70,7 @@ namespace blt::system #ifdef unix timespec res{}; clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res); - return res.tv_nsec; + return res.tv_sec * static_cast(1e9) + res.tv_nsec; #else return CLOCKS_PER_SECOND; #endif diff --git a/src/blt/profiling/profiler.cpp b/src/blt/profiling/profiler.cpp index 5e8f6b7..5ee5810 100755 --- a/src/blt/profiling/profiler.cpp +++ b/src/blt/profiling/profiler.cpp @@ -12,6 +12,8 @@ #include #include +#define TIME_FUNCTION blt::system::getCPUThreadTime() + namespace blt::profiling { // TODO: a better way @@ -148,7 +150,7 @@ namespace blt::profiling { void startInterval(const std::string& profileName, const std::string& intervalName) { std::scoped_lock lock(profileLock); capture_interval interval{}; - interval.start = system::getCPUThreadTime(); + interval.start = TIME_FUNCTION; profiles[profileName].intervals[intervalName] = interval; } @@ -157,9 +159,10 @@ namespace blt::profiling { auto& prof = profiles[profileName]; auto& ref = prof.intervals[intervalName]; - ref.end = system::getCPUThreadTime(); + ref.end = TIME_FUNCTION; auto difference = ref.end - ref.start; + auto& href = prof.intervals_total[intervalName]; href.total += difference; @@ -169,7 +172,7 @@ namespace blt::profiling { void point(const std::string& profileName, const std::string& pointName) { std::scoped_lock lock(profileLock); capture_point point{}; - point.point = system::getCPUThreadTime(); + point.point = TIME_FUNCTION; point.name = pointName; profiles[profileName].points.push(point); }