Remember to calibrate timer.

This commit is contained in:
Bartosz Taudul 2017-10-03 15:35:43 +02:00
parent 7b1135239c
commit 2fb4c47491
2 changed files with 18 additions and 5 deletions

View File

@ -236,16 +236,16 @@ bool Profiler::HandleServerQuery()
void Profiler::CalibrateTimer() void Profiler::CalibrateTimer()
{ {
#if defined _MSC_VER || defined __CYGWIN__ #ifdef TRACY_RDTSCP_SUPPORTED
unsigned int ui; int8_t cpu;
std::atomic_signal_fence( std::memory_order_acq_rel ); std::atomic_signal_fence( std::memory_order_acq_rel );
const auto t0 = std::chrono::high_resolution_clock::now(); 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::atomic_signal_fence( std::memory_order_acq_rel );
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
std::atomic_signal_fence( std::memory_order_acq_rel ); std::atomic_signal_fence( std::memory_order_acq_rel );
const auto t1 = std::chrono::high_resolution_clock::now(); 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 ); std::atomic_signal_fence( std::memory_order_acq_rel );
const auto dt = std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count(); const auto dt = std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count();

View File

@ -14,6 +14,10 @@
# include <intrin.h> # include <intrin.h>
#endif #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 namespace tracy
{ {
@ -39,7 +43,8 @@ public:
Profiler(); Profiler();
~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__ #if defined _MSC_VER || defined __CYGWIN__
unsigned int ui; unsigned int ui;
@ -52,6 +57,14 @@ public:
asm volatile ( "rdtscp" : "=a" (eax), "=d" (edx), "=c" (ui) :: ); asm volatile ( "rdtscp" : "=a" (eax), "=d" (edx), "=c" (ui) :: );
cpu = (int8_t)ui; cpu = (int8_t)ui;
return ( edx << 32 ) + eax; 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 #else
cpu = -1; cpu = -1;
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();