From 2fb4c47491758ec877d7be86e7d86fd75dc2d9e2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 3 Oct 2017 15:35:43 +0200 Subject: [PATCH] Remember to calibrate timer. --- client/TracyProfiler.cpp | 8 ++++---- client/TracyProfiler.hpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index b18f553a..44e93404 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -236,16 +236,16 @@ bool Profiler::HandleServerQuery() void Profiler::CalibrateTimer() { -#if defined _MSC_VER || defined __CYGWIN__ - unsigned int ui; +#ifdef TRACY_RDTSCP_SUPPORTED + int8_t cpu; std::atomic_signal_fence( std::memory_order_acq_rel ); const auto t0 = std::chrono::high_resolution_clock::now(); - const auto r0 = __rdtscp( &ui ); + const auto r0 = tracy_rdtscp( cpu ); std::atomic_signal_fence( std::memory_order_acq_rel ); std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); std::atomic_signal_fence( std::memory_order_acq_rel ); const auto t1 = std::chrono::high_resolution_clock::now(); - const auto r1 = __rdtscp( &ui ); + const auto r1 = tracy_rdtscp( cpu ); std::atomic_signal_fence( std::memory_order_acq_rel ); const auto dt = std::chrono::duration_cast( t1 - t0 ).count(); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index fa8769d0..b5bb5837 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -14,6 +14,10 @@ # include #endif +#if defined _MSC_VER || defined __CYGWIN__ || defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 +# define TRACY_RDTSCP_SUPPORTED +#endif + namespace tracy { @@ -39,7 +43,8 @@ public: Profiler(); ~Profiler(); - static tracy_force_inline int64_t GetTime( int8_t& cpu ) +#ifdef TRACY_RDTSCP_SUPPORTED + static tracy_force_inline int64_t tracy_rdtscp( int8_t& cpu ) { #if defined _MSC_VER || defined __CYGWIN__ unsigned int ui; @@ -52,6 +57,14 @@ public: asm volatile ( "rdtscp" : "=a" (eax), "=d" (edx), "=c" (ui) :: ); cpu = (int8_t)ui; return ( edx << 32 ) + eax; +#endif + } +#endif + + static tracy_force_inline int64_t GetTime( int8_t& cpu ) + { +#ifdef TRACY_RDTSCP_SUPPORTED + return tracy_rdtscp( cpu ); #else cpu = -1; return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();