From 3c092b4bec7314dc467683ab05a4ec20b4f40757 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 27 Aug 2019 23:00:13 +0200 Subject: [PATCH] Add thread name getter combining local and external thread names. --- server/TracyWorker.cpp | 31 +++++++++++++++++++++++++++++++ server/TracyWorker.hpp | 1 + 2 files changed, 32 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 152aa5d4..e76383cc 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1849,6 +1849,37 @@ const char* Worker::GetThreadString( uint64_t id ) const } } +const char* Worker::GetThreadName( uint64_t id ) const +{ + const auto it = m_data.threadNames.find( id ); + if( it == m_data.threadNames.end() ) + { + const auto eit = m_data.externalNames.find( id ); + if( eit == m_data.externalNames.end() ) + { + return "???"; + } + else + { + return eit->second.second; + } + } + else + { + // Client should send additional information about thread name, to make this check unnecessary + const auto txt = it->second; + if( txt[0] >= '0' && txt[0] <= '9' && atoi( txt ) == id ) + { + const auto eit = m_data.externalNames.find( id ); + if( eit != m_data.externalNames.end() ) + { + return eit->second.second; + } + } + return txt; + } +} + bool Worker::IsThreadLocal( uint64_t id ) const { return m_data.localThreadCompress.Exists( id ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index e9d35aa0..66f77598 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -337,6 +337,7 @@ public: const char* GetString( const StringRef& ref ) const; const char* GetString( const StringIdx& idx ) const; const char* GetThreadString( uint64_t id ) const; + const char* GetThreadName( uint64_t id ) const; bool IsThreadLocal( uint64_t id ) const; const SourceLocation& GetSourceLocation( int16_t srcloc ) const; std::pair GetExternalName( uint64_t id ) const;