diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index d662c7f9..956ede81 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -50,7 +50,8 @@ Profiler::Profiler() CalibrateTimer(); CalibrateDelay(); - m_timeBegin = GetTime(); + int8_t cpu; + m_timeBegin = GetTime( cpu ); m_thread = std::thread( [this] { Worker(); } ); SetThreadName( m_thread, "Tracy Profiler" ); @@ -85,9 +86,10 @@ uint64_t Profiler::GetNewId() void Profiler::FrameMark() { + int8_t cpu; auto item = s_queue.enqueue_begin( s_token ); item->hdr.type = QueueType::FrameMarkMsg; - item->hdr.id = (uint64_t)GetTime(); + item->hdr.id = (uint64_t)GetTime( cpu ); s_queue.enqueue_finish( s_token ); } @@ -296,6 +298,7 @@ void Profiler::CalibrateDelay() enum { Events = Iterations * 2 }; // start + end static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" ); + int8_t cpu; moodycamel::ProducerToken ptoken( s_queue ); for( int i=0; ihdr.type = QueueType::ZoneBegin; item->hdr.id = id; - item->zoneBegin.time = GetTime(); + item->zoneBegin.time = GetTime( item->zoneBegin.cpu ); item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location; item->zoneBegin.thread = GetThreadHandle(); s_queue.enqueue_finish( ptoken ); @@ -314,17 +317,17 @@ void Profiler::CalibrateDelay() auto item = s_queue.enqueue_begin( ptoken ); item->hdr.type = QueueType::ZoneEnd; item->hdr.id = id; - item->zoneEnd.time = GetTime(); + item->zoneEnd.time = GetTime( item->zoneEnd.cpu ); s_queue.enqueue_finish( ptoken ); } } - const auto f0 = GetTime(); + const auto f0 = GetTime( cpu ); for( int i=0; ihdr.type = QueueType::ZoneBegin; item->hdr.id = id; - item->zoneBegin.time = GetTime(); + item->zoneBegin.time = GetTime( item->zoneBegin.cpu ); item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location; item->zoneBegin.thread = GetThreadHandle(); s_queue.enqueue_finish( ptoken ); @@ -342,11 +345,11 @@ void Profiler::CalibrateDelay() auto item = s_queue.enqueue_begin( ptoken ); item->hdr.type = QueueType::ZoneEnd; item->hdr.id = id; - item->zoneEnd.time = GetTime(); + item->zoneEnd.time = GetTime( item->zoneEnd.cpu ); s_queue.enqueue_finish( ptoken ); } } - const auto t1 = GetTime(); + const auto t1 = GetTime( cpu ); const auto dt = t1 - t0; const auto df = t0 - f0; m_delay = ( dt - df ) / Events; @@ -354,8 +357,8 @@ void Profiler::CalibrateDelay() uint64_t mindiff = std::numeric_limits::max(); for( int i=0; i 0 && dt < mindiff ) mindiff = dt; } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 043f3634..9e57d967 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -32,12 +32,15 @@ public: Profiler(); ~Profiler(); - static int64_t GetTime() + static int64_t GetTime( int8_t& cpu ) { #if defined _MSC_VER || defined __CYGWIN__ unsigned int ui; - return int64_t( __rdtscp( &ui ) ); + const auto t = int64_t( __rdtscp( &ui ) ); + cpu = (int8_t)ui; + return t; #else + cpu = -1; return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); #endif } diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index f7a9ba23..55f18cb4 100755 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -19,7 +19,7 @@ public: auto item = Profiler::StartItem(); item->hdr.type = QueueType::ZoneBegin; item->hdr.id = m_id; - item->zoneBegin.time = Profiler::GetTime(); + item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu ); item->zoneBegin.srcloc = (uint64_t)srcloc; item->zoneBegin.thread = GetThreadHandle(); Profiler::FinishItem(); @@ -30,7 +30,7 @@ public: auto item = Profiler::StartItem(); item->hdr.type = QueueType::ZoneEnd; item->hdr.id = m_id; - item->zoneEnd.time = Profiler::GetTime(); + item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu ); Profiler::FinishItem(); } diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index ddff4431..69330897 100755 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -27,11 +27,13 @@ struct QueueZoneBegin int64_t time; uint64_t srcloc; // ptr uint64_t thread; + int8_t cpu; }; struct QueueZoneEnd { int64_t time; + int8_t cpu; }; struct QueueSourceLocation