diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 7a2ca095..1357c2e6 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -212,6 +212,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ) CheckString( ev.filename ); CheckString( ev.function ); + CheckThreadString( ev.thread ); zone->start = ev.time; SourceLocation srcloc { ev.filename, ev.function, ev.line }; @@ -292,6 +293,15 @@ void View::CheckString( uint64_t ptr ) m_sock.Send( &ptr, sizeof( ptr ) ); } +void View::CheckThreadString( uint64_t id ) +{ + if( m_threadNames.find( id ) != m_threadNames.end() ) return; + if( m_pendingThreads.find( id ) != m_pendingThreads.end() ) return; + + m_pendingThreads.emplace( id ); + // TODO send +} + void View::AddString( uint64_t ptr, std::string&& str ) { assert( m_strings.find( ptr ) == m_strings.end() ); @@ -302,6 +312,17 @@ void View::AddString( uint64_t ptr, std::string&& str ) m_strings.emplace( ptr, std::move( str ) ); } +void View::AddThreadString( uint64_t id, std::string&& str ) +{ + assert( m_threadNames.find( id ) == m_threadNames.end() ); + auto it = m_pendingThreads.find( id ); + assert( it != m_pendingThreads.end() ); + m_pendingThreads.erase( it ); + std::lock_guard lock( m_lock ); + m_threadNames.emplace( id, std::move( str ) ); +} + + void View::NewZone( Event* zone, uint64_t thread ) { Vector* timeline; @@ -432,6 +453,19 @@ const char* View::GetString( uint64_t ptr ) const } } +const char* View::GetThreadString( uint64_t id ) const +{ + const auto it = m_threadNames.find( id ); + if( it == m_threadNames.end() ) + { + return "???"; + } + else + { + return it->second.c_str(); + } +} + void View::Draw() { s_instance->DrawImpl(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 48e3f3f3..0b76cca7 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -49,7 +49,9 @@ private: void ProcessFrameMark( uint64_t id ); void CheckString( uint64_t ptr ); + void CheckThreadString( uint64_t id ); void AddString( uint64_t ptr, std::string&& str ); + void AddThreadString( uint64_t id, std::string&& str ); void NewZone( Event* zone, uint64_t thread ); void UpdateZone( Event* zone ); @@ -60,6 +62,7 @@ private: uint64_t GetLastTime() const; const char* TimeToString( uint64_t ns ) const; const char* GetString( uint64_t ptr ) const; + const char* GetThreadString( uint64_t id ) const; void DrawImpl(); void DrawFrames(); @@ -79,6 +82,7 @@ private: Vector m_srcFile; Vector m_threads; std::unordered_map m_strings; + std::unordered_map m_threadNames; std::mutex m_mbpslock; std::vector m_mbps; @@ -87,6 +91,7 @@ private: std::unordered_map m_pendingEndZone; std::unordered_map m_openZones; std::unordered_set m_pendingStrings; + std::unordered_set m_pendingThreads; std::unordered_map m_locationRef; std::unordered_map m_threadMap;