Move context switch minpx calculation to rendering code.

This commit is contained in:
Bartosz Taudul 2023-03-24 23:10:58 +01:00
parent f2700b2786
commit b3e9ede557
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 22 additions and 20 deletions

View File

@ -51,7 +51,6 @@ struct ContextSwitchDraw
{ {
ContextSwitchDrawType type; ContextSwitchDrawType type;
short_ptr<ContextSwitchData> ev; short_ptr<ContextSwitchData> ev;
float minpx;
union union
{ {
ContextSwitchDrawFolded folded; ContextSwitchDrawFolded folded;

View File

@ -456,8 +456,6 @@ int TimelineItemThread::PreprocessZoneLevel( const TimelineContext& ctx, const V
void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx, const ContextSwitch& ctxSwitch ) void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx, const ContextSwitch& ctxSwitch )
{ {
const auto w = ctx.w;
const auto pxns = ctx.pxns;
const auto nspx = ctx.nspx; const auto nspx = ctx.nspx;
const auto vStart = ctx.vStart; const auto vStart = ctx.vStart;
const auto vEnd = ctx.vEnd; const auto vEnd = ctx.vEnd;
@ -475,7 +473,6 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
const auto& sampleData = m_thread->samples; const auto& sampleData = m_thread->samples;
auto pit = citend; auto pit = citend;
double minpx = -10.0;
while( it < citend ) while( it < citend )
{ {
auto& ev = *it; auto& ev = *it;
@ -496,17 +493,16 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
if( found ) waitStack = sdit->callstack.Val(); if( found ) waitStack = sdit->callstack.Val();
} }
auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::Waiting, &ev, float( minpx ) } ); auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::Waiting, &ev } );
ref.waiting.prev = pit; ref.waiting.prev = pit;
ref.waiting.waitStack = waitStack; ref.waiting.waitStack = waitStack;
} }
const auto end = ev.IsEndValid() ? ev.End() : m_worker.GetLastTime(); const auto end = ev.IsEndValid() ? ev.End() : m_worker.GetLastTime();
const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 ); const auto zsz = end - ev.Start();
if( zsz < MinCtxSize ) if( zsz < MinCtxNs )
{ {
int num = 0; int num = 0;
const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 );
auto px1ns = end - vStart; auto px1ns = end - vStart;
auto rend = end; auto rend = end;
auto nextTime = end + MinCtxNs; auto nextTime = end + MinCtxNs;
@ -524,15 +520,14 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
rend = nend; rend = nend;
nextTime = nend + nspx; nextTime = nend + nspx;
} }
minpx = std::min( std::max( px1ns * pxns, px0+MinCtxSize ), double( w + 10 ) );
if( num == 1 ) if( num == 1 )
{ {
auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::FoldedOne, &ev, float( minpx ) } ); auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::FoldedOne, &ev } );
ref.folded.rend = rend; ref.folded.rend = rend;
} }
else else
{ {
auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::FoldedMulti, &ev, float( minpx ) } ); auto& ref = m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::FoldedMulti, &ev } );
ref.folded.rend = rend; ref.folded.rend = rend;
ref.folded.num = num; ref.folded.num = num;
} }
@ -540,7 +535,7 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
} }
else else
{ {
m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::Running, &ev, float( minpx ) } ); m_ctxDraw.emplace_back( ContextSwitchDraw { ContextSwitchDrawType::Running, &ev } );
pit = it; pit = it;
++it; ++it;
} }

View File

@ -136,6 +136,8 @@ const char* View::DecodeContextSwitchState( uint8_t state )
void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, int offset, int endOffset, bool isFiber ) void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, int offset, int endOffset, bool isFiber )
{ {
constexpr float MinCtxSize = 4;
const auto vStart = ctx.vStart; const auto vStart = ctx.vStart;
const auto& wpos = ctx.wpos; const auto& wpos = ctx.wpos;
const auto pxns = ctx.pxns; const auto pxns = ctx.pxns;
@ -148,6 +150,8 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
const auto ty05 = round( ty * 0.5f ); const auto ty05 = round( ty * 0.5f );
double minpx = -10;
for( auto& v : drawList ) for( auto& v : drawList )
{ {
const auto& ev = *v.ev; const auto& ev = *v.ev;
@ -157,7 +161,7 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
{ {
const auto& prev = *v.waiting.prev; const auto& prev = *v.waiting.prev;
const bool migration = prev.Cpu() != ev.Cpu(); const bool migration = prev.Cpu() != ev.Cpu();
const auto px0 = std::max( { ( prev.End() - vStart ) * pxns, -10.0, double( v.minpx ) } ); const auto px0 = std::max( { ( prev.End() - vStart ) * pxns, -10.0, double( minpx ) } );
const auto pxw = ( ev.WakeupVal() - vStart ) * pxns; const auto pxw = ( ev.WakeupVal() - vStart ) * pxns;
const auto px1 = std::min( ( ev.Start() - vStart ) * pxns, w + 10.0 ); const auto px1 = std::min( ( ev.Start() - vStart ) * pxns, w + 10.0 );
const auto color = migration ? 0xFFEE7711 : 0xFF2222AA; const auto color = migration ? 0xFFEE7711 : 0xFF2222AA;
@ -253,10 +257,12 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
case ContextSwitchDrawType::FoldedOne: case ContextSwitchDrawType::FoldedOne:
{ {
const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 ); const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 );
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( v.minpx, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize ); const auto end = v.folded.rend.Val();
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( v.minpx, offset + ty + 1 ) ) ) const auto px1ns = end - vStart;
minpx = std::min( std::max( px1ns * pxns, px0+MinCtxSize ), double( w + 10 ) );
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( minpx, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
{ {
const auto end = v.folded.rend.Val();
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if( isFiber ) if( isFiber )
{ {
@ -285,10 +291,12 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
case ContextSwitchDrawType::FoldedMulti: case ContextSwitchDrawType::FoldedMulti:
{ {
const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 ); const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 );
DrawZigZag( draw, wpos + ImVec2( 0, offset + ty05 ), px0, v.minpx, ty/4, 0xFF888888, 1.5 ); const auto end = v.folded.rend.Val();
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( v.minpx, offset + ty + 1 ) ) ) const auto px1ns = end - vStart;
minpx = std::min( std::max( px1ns * pxns, px0+MinCtxSize ), double( w + 10 ) );
DrawZigZag( draw, wpos + ImVec2( 0, offset + ty05 ), px0, minpx, ty/4, 0xFF888888, 1.5 );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
{ {
const auto end = v.folded.rend.Val();
ImGui::BeginTooltip(); ImGui::BeginTooltip();
TextFocused( isFiber ? "Fiber is" : "Thread is", "changing activity multiple times" ); TextFocused( isFiber ? "Fiber is" : "Thread is", "changing activity multiple times" );
TextFocused( "Number of running regions:", RealToString( v.folded.num ) ); TextFocused( "Number of running regions:", RealToString( v.folded.num ) );
@ -305,7 +313,7 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
case ContextSwitchDrawType::Running: case ContextSwitchDrawType::Running:
{ {
const auto end = ev.IsEndValid() ? ev.End() : m_worker.GetLastTime(); const auto end = ev.IsEndValid() ? ev.End() : m_worker.GetLastTime();
const auto px0 = std::max( { ( ev.Start() - vStart ) * pxns, -10.0, double( v.minpx ) } ); const auto px0 = std::max( { ( ev.Start() - vStart ) * pxns, -10.0, double( minpx ) } );
const auto px1 = std::min( ( end - vStart ) * pxns, w + 10.0 ); const auto px1 = std::min( ( end - vStart ) * pxns, w + 10.0 );
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( px1, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize ); DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( px1, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + ty + 1 ) ) ) if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + ty + 1 ) ) )