From 6d00a56c61cec0c582d1b379eb9adecf41455d06 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 12 Sep 2019 20:08:57 +0200 Subject: [PATCH] Draw thread migrations across CPU cores. --- server/TracyView.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ server/TracyView.hpp | 1 + 2 files changed, 44 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 363ebebe..6edb16c1 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1937,6 +1937,7 @@ void View::DrawZones() m_msgHighlight.Decay( nullptr ); m_zoneSrcLocHighlight.Decay( 0 ); m_lockHoverHighlight.Decay( InvalidId ); + m_drawThreadMigrations.Decay( 0 ); m_zoneHover = nullptr; if( m_vd.zvStart == m_vd.zvEnd ) return; @@ -2318,6 +2319,7 @@ void View::DrawZones() if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, oldOffset ), wpos + ImVec2( ty + txtsz.x, oldOffset + ty ) ) ) { + m_drawThreadMigrations = v->id; ImGui::BeginTooltip(); SmallColorBox( GetThreadColor( v->id, 0 ) ); ImGui::SameLine(); @@ -4193,6 +4195,7 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, const auto sty = ImGui::GetFontSize(); const auto sstep = sty + 1; + const auto origOffset = offset; auto cpuData = m_worker.GetCpuData(); for( int i=0; i<256; i++ ) { @@ -4345,6 +4348,7 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, TextFocused( "Thread:", m_worker.GetThreadName( thread ) ); ImGui::SameLine(); ImGui::TextDisabled( "(%s)", RealToString( thread, true ) ); + m_drawThreadMigrations = thread; } else { @@ -4404,6 +4408,45 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, } } + if( m_drawThreadMigrations != 0 ) + { + auto ctxSwitch = m_worker.GetContextSwitchData( m_drawThreadMigrations ); + if( ctxSwitch ) + { + const auto color = HighlightColor( GetThreadColor( m_drawThreadMigrations, -8 ) ); + + auto& v = ctxSwitch->v; + auto it = std::lower_bound( v.begin(), v.end(), m_vd.zvStart, [] ( const auto& l, const auto& r ) { return l.End() < r; } ); + if( it != v.begin() ) --it; + auto end = std::lower_bound( it, v.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.Start() < r; } ); + if( end == v.end() ) --end; + + while( it < end ) + { + const auto t0 = it->End(); + const auto cpu0 = it->Cpu(); + + ++it; + + const auto t1 = it->Start(); + const auto cpu1 = it->Cpu(); + + const auto px0 = ( t0 - m_vd.zvStart ) * pxns; + const auto px1 = ( t1 - m_vd.zvStart ) * pxns; + + if( t1 - t0 < 2.f * nspx ) + { + draw->AddLine( wpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), wpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), color ); + } + else + { + draw->AddLine( wpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), wpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), 0xFF000000, 4.f ); + draw->AddLine( wpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), wpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), color, 2.f ); + } + } + } + } + ImGui::PopFont(); } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index b3946bcf..de307140 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -275,6 +275,7 @@ private: ImGuiTextFilter m_messageFilter; int m_visibleMessages = 0; bool m_disconnectIssued = false; + DecayValue m_drawThreadMigrations = 0; Region m_highlight; Region m_highlightZoom;