From db3e8026439ae86f644c18d701f984a9d7ec0db0 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 29 Nov 2019 22:46:57 +0100 Subject: [PATCH] Build reverse CPU topology map. --- server/TracyWorker.cpp | 12 ++++++++++++ server/TracyWorker.hpp | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 6aab6260..834956a4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -366,6 +366,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) uint32_t thread; f.Read( thread ); core.second.emplace_back( thread ); + + m_data.cpuTopologyMap.emplace( thread, CpuThreadTopology { packageId, coreId } ); } } } @@ -4622,6 +4624,9 @@ void Worker::ProcessCpuTopology( const QueueCpuTopology& ev ) auto core = package->second.find( ev.core ); if( core == package->second.end() ) core = package->second.emplace( ev.core, std::vector {} ).first; core->second.emplace_back( ev.thread ); + + assert( m_data.cpuTopologyMap.find( ev.thread ) == m_data.cpuTopologyMap.end() ); + m_data.cpuTopologyMap.emplace( ev.thread, CpuThreadTopology { ev.package, ev.core } ); } void Worker::MemAllocChanged( int64_t time ) @@ -5747,4 +5752,11 @@ void Worker::SetParameter( size_t paramIdx, int32_t val ) Query( ServerQueryParameter, ( idx << 32 ) | val ); } +const Worker::CpuThreadTopology* Worker::GetThreadTopology( uint32_t cpuThread ) const +{ + auto it = m_data.cpuTopologyMap.find( cpuThread ); + if( it == m_data.cpuTopologyMap.end() ) return nullptr; + return &it->second; +} + } diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index e808c419..2ffc07f7 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -100,6 +100,12 @@ public: enum { ZoneThreadDataSize = sizeof( ZoneThreadData ) }; #pragma pack() + struct CpuThreadTopology + { + uint32_t package; + uint32_t core; + }; + private: struct SourceLocationZones { @@ -230,6 +236,7 @@ private: #endif flat_hash_map>> cpuTopology; + flat_hash_map> cpuTopologyMap; }; struct MbpsBlock @@ -425,6 +432,7 @@ public: void SetParameter( size_t paramIdx, int32_t val ); const decltype(DataBlock::cpuTopology)& GetCpuTopology() const { return m_data.cpuTopology; } + const CpuThreadTopology* GetThreadTopology( uint32_t cpuThread ) const; private: void Network();