Draw thread migrations across CPU cores.

This commit is contained in:
Bartosz Taudul 2019-09-12 20:08:57 +02:00
parent c1731f864b
commit 6d00a56c61
2 changed files with 44 additions and 0 deletions

View File

@ -1937,6 +1937,7 @@ void View::DrawZones()
m_msgHighlight.Decay( nullptr ); m_msgHighlight.Decay( nullptr );
m_zoneSrcLocHighlight.Decay( 0 ); m_zoneSrcLocHighlight.Decay( 0 );
m_lockHoverHighlight.Decay( InvalidId ); m_lockHoverHighlight.Decay( InvalidId );
m_drawThreadMigrations.Decay( 0 );
m_zoneHover = nullptr; m_zoneHover = nullptr;
if( m_vd.zvStart == m_vd.zvEnd ) return; 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 ) ) ) if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, oldOffset ), wpos + ImVec2( ty + txtsz.x, oldOffset + ty ) ) )
{ {
m_drawThreadMigrations = v->id;
ImGui::BeginTooltip(); ImGui::BeginTooltip();
SmallColorBox( GetThreadColor( v->id, 0 ) ); SmallColorBox( GetThreadColor( v->id, 0 ) );
ImGui::SameLine(); 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 sty = ImGui::GetFontSize();
const auto sstep = sty + 1; const auto sstep = sty + 1;
const auto origOffset = offset;
auto cpuData = m_worker.GetCpuData(); auto cpuData = m_worker.GetCpuData();
for( int i=0; i<256; i++ ) 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 ) ); TextFocused( "Thread:", m_worker.GetThreadName( thread ) );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( thread, true ) ); ImGui::TextDisabled( "(%s)", RealToString( thread, true ) );
m_drawThreadMigrations = thread;
} }
else 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(); ImGui::PopFont();
} }

View File

@ -275,6 +275,7 @@ private:
ImGuiTextFilter m_messageFilter; ImGuiTextFilter m_messageFilter;
int m_visibleMessages = 0; int m_visibleMessages = 0;
bool m_disconnectIssued = false; bool m_disconnectIssued = false;
DecayValue<uint64_t> m_drawThreadMigrations = 0;
Region m_highlight; Region m_highlight;
Region m_highlightZoom; Region m_highlightZoom;