From e99db57b0370eafdd3718ed70f8fc6a44c9c3fcb Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 1 Oct 2019 13:18:24 +0200 Subject: [PATCH] Use rdtsc in Timers --- libsrc/core/paje_trace.cpp | 6 +++--- libsrc/core/profiler.hpp | 6 +++--- libsrc/core/utils.cpp | 4 ++-- libsrc/core/utils.hpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index 773e1207..5c52a378 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -98,7 +98,7 @@ namespace ngcore // return time in milliseconds as double // return std::chrono::duration(t-start_time).count()*1000.0; // return std::chrono::duration(t-start_time).count() / 2.7e3; - return 1000.0*static_cast(t-start_time) / ticks_per_second; + return 1000.0*static_cast(t-start_time) * seconds_per_tick; } enum PType @@ -629,7 +629,7 @@ namespace ngcore std::sort (events.begin(), events.end()); - root.time = 1000.0*static_cast(stop_time-start_time)/ticks_per_second; + root.time = 1000.0*static_cast(stop_time-start_time) * seconds_per_tick; for(auto & event : events) { @@ -658,7 +658,7 @@ namespace ngcore std::cout << "node stack empty!" << std::endl; break; } - double time = 1000.0*static_cast(event.time-current->start_time)/ticks_per_second; + double time = 1000.0*static_cast(event.time-current->start_time) * seconds_per_tick; current->time += time; current = node_stack.back(); current->time -= time; diff --git a/libsrc/core/profiler.hpp b/libsrc/core/profiler.hpp index 4e4b565c..36c10d55 100644 --- a/libsrc/core/profiler.hpp +++ b/libsrc/core/profiler.hpp @@ -22,7 +22,7 @@ namespace ngcore TimerVal() = default; double tottime = 0.0; - double starttime = 0.0; + TTimePoint starttime=0; double flops = 0.0; double loads = 0.0; double stores = 0.0; @@ -61,13 +61,13 @@ namespace ngcore /// start timer of index nr static void StartTimer (int nr) { - timers[nr].starttime = WallTime(); timers[nr].count++; + timers[nr].starttime = GetTimeCounter(); timers[nr].count++; } /// stop timer of index nr static void StopTimer (int nr) { - timers[nr].tottime += WallTime()-timers[nr].starttime; + timers[nr].tottime += (GetTimeCounter()-timers[nr].starttime)*seconds_per_tick; } static void StartThreadTimer (size_t nr, size_t tid) diff --git a/libsrc/core/utils.cpp b/libsrc/core/utils.cpp index 5f5376bd..4033a6eb 100644 --- a/libsrc/core/utils.cpp +++ b/libsrc/core/utils.cpp @@ -21,7 +21,7 @@ namespace ngcore &status); } #endif - double ticks_per_second = [] () noexcept + double seconds_per_tick = [] () noexcept { auto tick_start = GetTimeCounter(); double tstart = WallTime(); @@ -33,7 +33,7 @@ namespace ngcore auto tick_end = GetTimeCounter(); tend = WallTime(); - return static_cast(tick_end-tick_start)/(tend-tstart); + return (tend-tstart)/static_cast(tick_end-tick_start); }(); const std::chrono::time_point wall_time_start = TClock::now(); diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index c0d92054..65db4fff 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -44,7 +44,7 @@ namespace ngcore // High precision clock counter register using TTimePoint = size_t; - extern NGCORE_API double ticks_per_second; + extern NGCORE_API double seconds_per_tick; inline TTimePoint GetTimeCounter() noexcept {