mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Remember to calibrate timer.
This commit is contained in:
parent
7b1135239c
commit
2fb4c47491
@ -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<std::chrono::nanoseconds>( t1 - t0 ).count();
|
||||
|
@ -14,6 +14,10 @@
|
||||
# include <intrin.h>
|
||||
#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::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
|
Loading…
Reference in New Issue
Block a user