diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index 5f41ce23..db791ecb 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -28,7 +28,6 @@ public: tracy_force_inline void lock() { - uint32_t cpu; const auto thread = GetThreadHandle(); { Magic magic; @@ -38,7 +37,7 @@ public: item->hdr.type = QueueType::LockWait; item->lockWait.id = m_id; item->lockWait.thread = thread; - item->lockWait.time = Profiler::GetTime( cpu ); + item->lockWait.time = Profiler::GetTime(); item->lockWait.lckloc = m_lckloc; tail.store( magic + 1, std::memory_order_release ); } @@ -53,7 +52,7 @@ public: item->hdr.type = QueueType::LockObtain; item->lockObtain.id = m_id; item->lockObtain.thread = thread; - item->lockObtain.time = Profiler::GetTime( cpu ); + item->lockObtain.time = Profiler::GetTime(); tail.store( magic + 1, std::memory_order_release ); } } @@ -62,7 +61,6 @@ public: { m_lockable.unlock(); - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); @@ -70,7 +68,7 @@ public: item->hdr.type = QueueType::LockRelease; item->lockRelease.id = m_id; item->lockRelease.thread = GetThreadHandle(); - item->lockRelease.time = Profiler::GetTime( cpu ); + item->lockRelease.time = Profiler::GetTime(); tail.store( magic + 1, std::memory_order_release ); } @@ -79,7 +77,6 @@ public: const auto ret = m_lockable.try_lock(); if( ret ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); @@ -87,7 +84,7 @@ public: item->hdr.type = QueueType::LockObtain; item->lockObtain.id = (uint64_t)&m_lockable; item->lockObtain.thread = GetThreadHandle(); - item->lockObtain.time = Profiler::GetTime( cpu ); + item->lockObtain.time = Profiler::GetTime(); tail.store( magic + 1, std::memory_order_release ); } return ret; diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 7914632e..00cf5b19 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -73,7 +73,6 @@ enum { QueuePrealloc = 256 * 1024 }; static Profiler* s_instance = nullptr; static Thread* s_thread = nullptr; -static unsigned int __dontcare_cpu; // 1a. But s_queue is needed for initialization of variables in point 2. extern moodycamel::ConcurrentQueue s_queue; @@ -90,7 +89,7 @@ thread_local ProducerWrapper init_order(108) s_token { s_queue.get_explicit_prod # pragma init_seg( ".CRT$XCB" ) #endif -static InitTimeWrapper init_order(101) s_initTime { Profiler::GetTime( __dontcare_cpu ) }; +static InitTimeWrapper init_order(101) s_initTime { Profiler::GetTime() }; static RPMallocInit init_order(102) s_rpmalloc_init; moodycamel::ConcurrentQueue init_order(103) s_queue( QueuePrealloc ); std::atomic init_order(104) s_lockCounter( 0 ); @@ -123,8 +122,7 @@ Profiler::Profiler() new(s_thread) Thread( LaunchWorker, this ); SetThreadName( s_thread->Handle(), "Tracy Profiler" ); - uint32_t cpu; - m_timeBegin.store( GetTime( cpu ), std::memory_order_relaxed ); + m_timeBegin.store( GetTime(), std::memory_order_relaxed ); } Profiler::~Profiler() @@ -406,7 +404,6 @@ void Profiler::CalibrateDelay() enum { Events = Iterations * 2 }; // start + end static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" ); - uint32_t cpu; moodycamel::ProducerToken ptoken_detail( s_queue ); moodycamel::ConcurrentQueue::ExplicitProducer* ptoken = s_queue.get_explicit_producer( ptoken_detail ); for( int i=0; i::max(); for( int i=0; i 0 && dt < mindiff ) mindiff = dt; } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index a2913088..3f099985 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -61,6 +61,21 @@ public: } #endif +#ifdef TRACY_RDTSCP_SUPPORTED + static tracy_force_inline int64_t tracy_rdtscp() + { +#if defined _MSC_VER || defined __CYGWIN__ + static unsigned int dontcare; + const auto t = int64_t( __rdtscp( &dontcare ) ); + return t; +#elif defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 + uint32_t eax, edx; + asm volatile ( "rdtscp" : "=a" (eax), "=d" (edx) :: ); + return ( uint64_t( edx ) << 32 ) + uint64_t( eax ); +#endif + } +#endif + static tracy_force_inline int64_t GetTime( uint32_t& cpu ) { #ifdef TRACY_RDTSCP_SUPPORTED @@ -71,28 +86,35 @@ public: #endif } + static tracy_force_inline int64_t GetTime() + { +#ifdef TRACY_RDTSCP_SUPPORTED + return tracy_rdtscp(); +#else + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); +#endif + } + static tracy_force_inline void FrameMark() { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::FrameMarkMsg; - item->frameMark.time = GetTime( cpu ); + item->frameMark.time = GetTime(); tail.store( magic + 1, std::memory_order_release ); } static tracy_force_inline void PlotData( const char* name, int64_t val ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::PlotData; item->plotData.name = (uint64_t)name; - item->plotData.time = GetTime( cpu ); + item->plotData.time = GetTime(); item->plotData.type = PlotDataType::Int; item->plotData.data.i = val; tail.store( magic + 1, std::memory_order_release ); @@ -100,14 +122,13 @@ public: static tracy_force_inline void PlotData( const char* name, float val ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::PlotData; item->plotData.name = (uint64_t)name; - item->plotData.time = GetTime( cpu ); + item->plotData.time = GetTime(); item->plotData.type = PlotDataType::Float; item->plotData.data.f = val; tail.store( magic + 1, std::memory_order_release ); @@ -115,14 +136,13 @@ public: static tracy_force_inline void PlotData( const char* name, double val ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::PlotData; item->plotData.name = (uint64_t)name; - item->plotData.time = GetTime( cpu ); + item->plotData.time = GetTime(); item->plotData.type = PlotDataType::Double; item->plotData.data.d = val; tail.store( magic + 1, std::memory_order_release ); @@ -130,7 +150,6 @@ public: static tracy_force_inline void Message( const char* txt, size_t size ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto ptr = (char*)tracy_malloc( size+1 ); @@ -139,7 +158,7 @@ public: auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::Message; - item->message.time = GetTime( cpu ); + item->message.time = GetTime(); item->message.thread = GetThreadHandle(); item->message.text = (uint64_t)ptr; tail.store( magic + 1, std::memory_order_release ); @@ -147,13 +166,12 @@ public: static tracy_force_inline void Message( const char* txt ) { - uint32_t cpu; Magic magic; auto& token = s_token.ptr; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::MessageLiteral; - item->message.time = GetTime( cpu ); + item->message.time = GetTime(); item->message.thread = GetThreadHandle(); item->message.text = (uint64_t)txt; tail.store( magic + 1, std::memory_order_release );