diff --git a/server/TracyView.cpp b/server/TracyView.cpp index eec486ac..451ef772 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5092,6 +5092,44 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, return cnt; } +const char* View::GetThreadContextData( uint64_t thread, bool& _local, bool& _untracked, const char*& program ) +{ + static char buf[256]; + const auto local = m_worker.IsThreadLocal( thread ); + auto txt = local ? m_worker.GetThreadName( thread ) : m_worker.GetExternalName( thread ).first; + auto label = txt; + bool untracked = false; + if( !local ) + { + if( m_worker.GetPid() == 0 ) + { + untracked = strcmp( txt, m_worker.GetCaptureProgram().c_str() ) == 0; + } + else + { + const auto pid = m_worker.GetPidFromTid( thread ); + untracked = pid == m_worker.GetPid(); + if( untracked ) + { + label = txt = m_worker.GetExternalName( thread ).second; + } + else + { + const auto ttxt = m_worker.GetExternalName( thread ).second; + if( strcmp( ttxt, "???" ) != 0 && strcmp( ttxt, txt ) != 0 ) + { + snprintf( buf, 256, "%s (%s)", txt, ttxt ); + label = buf; + } + } + } + } + _local = local; + _untracked = untracked; + program = txt; + return label; +} + int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ) { const auto w = ImGui::GetWindowContentRegionWidth() - 1; @@ -5271,37 +5309,10 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, } else { - char buf[256]; const auto thread = m_worker.DecompressThreadExternal( it->Thread() ); - const auto local = m_worker.IsThreadLocal( thread ); - auto txt = local ? m_worker.GetThreadName( thread ) : m_worker.GetExternalName( thread ).first; - auto label = txt; - bool untracked = false; - if( !local ) - { - if( m_worker.GetPid() == 0 ) - { - untracked = strcmp( txt, m_worker.GetCaptureProgram().c_str() ) == 0; - } - else - { - const auto pid = m_worker.GetPidFromTid( thread ); - untracked = pid == m_worker.GetPid(); - if( untracked ) - { - label = txt = m_worker.GetExternalName( thread ).second; - } - else - { - const auto ttxt = m_worker.GetExternalName( thread ).second; - if( strcmp( ttxt, "???" ) != 0 && strcmp( ttxt, txt ) != 0 ) - { - snprintf( buf, 256, "%s (%s)", txt, ttxt ); - label = buf; - } - } - } - } + bool local, untracked; + const char* txt; + auto label = GetThreadContextData( thread, local, untracked, txt ); const auto pr0 = ( start - m_vd.zvStart ) * pxns; const auto pr1 = ( end - m_vd.zvStart ) * pxns; const auto px0 = std::max( pr0, -10.0 ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 437991da..010f3b4d 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -244,6 +244,7 @@ private: int64_t GetZoneSelfTime( const ZoneEvent& zone ); int64_t GetZoneSelfTime( const GpuEvent& zone ); bool GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt ); + const char* GetThreadContextData( uint64_t thread, bool& local, bool& untracked, const char*& program ); tracy_force_inline void CalcZoneTimeData( unordered_flat_map& data, int64_t& ztime, const ZoneEvent& zone ); tracy_force_inline void CalcZoneTimeData( const ContextSwitch* ctx, unordered_flat_map& data, int64_t& ztime, const ZoneEvent& zone );