1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-01 05:03:53 +00:00

Properly show fiber context switch data.

This commit is contained in:
Bartosz Taudul 2021-11-06 21:06:08 +01:00
parent 40cd5435df
commit d33de972f0
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 172 additions and 117 deletions

View File

@ -3287,7 +3287,7 @@ void View::DrawZones()
auto ctxSwitch = m_worker.GetContextSwitchData( v->id );
if( ctxSwitch )
{
DrawContextSwitches( ctxSwitch, hover, pxns, int64_t( nspx ), wpos, ctxOffset, offset );
DrawContextSwitches( ctxSwitch, hover, pxns, int64_t( nspx ), wpos, ctxOffset, offset, v->isFiber );
}
}
@ -3875,7 +3875,7 @@ static const char* DecodeContextSwitchState( uint8_t state )
}
}
void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset )
void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset, bool isFiber )
{
auto& vec = ctx->v;
auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_vd.zvStart ), [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
@ -3920,6 +3920,13 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
if( ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( pxw, offset + ty ) ) )
{
ImGui::BeginTooltip();
if( isFiber )
{
TextFocused( "Fiber is", "yielding" );
TextFocused( "Yield time:", TimeToString( ev.Start() - pit->End() ) );
}
else
{
TextFocused( "Thread is", migration ? "migrating CPUs" : "waiting" );
TextFocused( "Waiting time:", TimeToString( ev.WakeupVal() - pit->End() ) );
if( migration )
@ -3941,6 +3948,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
TextFocused( "Wait state:", DecodeContextSwitchStateCode( pit->State() ) );
ImGui::SameLine();
TextDisabledUnformatted( DecodeContextSwitchState( pit->State() ) );
}
ImGui::EndTooltip();
if( IsMouseClicked( 2 ) )
@ -3950,6 +3958,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
}
else if( ev.WakeupVal() != ev.Start() && ImGui::IsMouseHoveringRect( wpos + ImVec2( pxw, offset ), wpos + ImVec2( px1, offset + ty ) ) )
{
assert( !isFiber );
ImGui::BeginTooltip();
TextFocused( "Thread is", "waking up" );
TextFocused( "Scheduling delay:", TimeToString( ev.Start() - ev.WakeupVal() ) );
@ -3994,9 +4003,21 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
{
ImGui::BeginTooltip();
if( isFiber )
{
const auto tid = m_worker.DecompressThread( ev.Thread() );
TextFocused( "Fiber is", "running" );
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( tid ) );
}
else
{
TextFocused( "Thread is", "running" );
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
}
ImGui::EndTooltip();
if( IsMouseClicked( 2 ) )
@ -4011,7 +4032,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
{
ImGui::BeginTooltip();
TextFocused( "Thread is", "changing activity multiple times" );
TextFocused( isFiber ? "Fiber is" : "Thread is", "changing activity multiple times" );
TextFocused( "Number of running regions:", RealToString( num ) );
TextFocused( "Time:", TimeToString( rend - ev.Start() ) );
ImGui::EndTooltip();
@ -4032,9 +4053,21 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + ty + 1 ) ) )
{
ImGui::BeginTooltip();
if( isFiber )
{
const auto tid = m_worker.DecompressThread( ev.Thread() );
TextFocused( "Fiber is", "running" );
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( tid ) );
}
else
{
TextFocused( "Thread is", "running" );
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
}
ImGui::EndTooltip();
if( IsMouseClicked( 2 ) )
@ -7352,7 +7385,7 @@ void View::DrawZoneInfoWindow()
TextDisabledUnformatted( "(100%)" );
ImGui::Separator();
TextFocused( "Running state regions:", "1" );
TextFocused( "CPU:", RealToString( it->Cpu() ) );
if( !threadData->isFiber ) TextFocused( "CPU:", RealToString( it->Cpu() ) );
}
}
else if( cnt > 1 )
@ -7385,6 +7418,8 @@ void View::DrawZoneInfoWindow()
}
TextFocused( "Running state regions:", RealToString( cnt ) );
if( !threadData->isFiber )
{
int numCpus = 0;
for( int i=0; i<256; i++ ) numCpus += cpus[i];
if( numCpus == 1 )
@ -7437,6 +7472,7 @@ void View::DrawZoneInfoWindow()
}
}
}
}
--eit;
if( ImGui::TreeNode( "Wait regions" ) )
@ -7448,15 +7484,23 @@ void View::DrawZoneInfoWindow()
const int64_t adjust = m_ctxSwitchTimeRelativeToZone ? ev.Start() : 0;
const auto wrsz = eit - bit;
if( ImGui::BeginTable( "##waitregions", 6, ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min<int64_t>( 1+wrsz, 15 ) ) ) )
const auto numColumns = threadData->isFiber ? 4 : 6;
if( ImGui::BeginTable( "##waitregions", numColumns, ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min<int64_t>( 1+wrsz, 15 ) ) ) )
{
ImGui::TableSetupScrollFreeze( 0, 1 );
ImGui::TableSetupColumn( "Begin" );
ImGui::TableSetupColumn( "End" );
ImGui::TableSetupColumn( "Time" );
if( threadData->isFiber )
{
ImGui::TableSetupColumn( "Thread" );
}
else
{
ImGui::TableSetupColumn( "Wakeup" );
ImGui::TableSetupColumn( "CPU" );
ImGui::TableSetupColumn( "State" );
}
ImGui::TableHeadersRow();
ImGuiListClipper clipper;
@ -7466,12 +7510,8 @@ void View::DrawZoneInfoWindow()
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{
const auto cend = bit[i].End();
const auto state = bit[i].State();
const auto reason = bit[i].Reason();
const auto cpu0 = bit[i].Cpu();
const auto cstart = bit[i+1].Start();
const auto cwakeup = bit[i+1].WakeupVal();
const auto cpu1 = bit[i+1].Cpu();
ImGui::PushID( i );
ImGui::TableNextRow();
@ -7494,6 +7534,20 @@ void View::DrawZoneInfoWindow()
ZoomToRange( cend, cwakeup );
}
ImGui::TableNextColumn();
if( threadData->isFiber )
{
const auto ftid = m_worker.DecompressThread( bit[i].Thread() );
ImGui::TextUnformatted( m_worker.GetThreadName( ftid ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( ftid ) );
}
else
{
const auto cpu0 = bit[i].Cpu();
const auto reason = bit[i].Reason();
const auto state = bit[i].State();
const auto cpu1 = bit[i+1].Cpu();
if( cstart != cwakeup )
{
if( ImGui::Selectable( TimeToString( cstart - cwakeup ) ) )
@ -7547,6 +7601,7 @@ void View::DrawZoneInfoWindow()
ImGui::TextUnformatted( desc );
ImGui::EndTooltip();
}
}
ImGui::PopID();
}
}

View File

@ -174,7 +174,7 @@ private:
void DrawZoneFramesHeader();
void DrawZoneFrames( const FrameData& frames );
void DrawZones();
void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset );
void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset, bool isFiber );
void DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset );
#ifndef TRACY_NO_STATISTICS
int DispatchGhostLevel( const Vector<GhostZone>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );