From 2783e6e64bf0083d7203cee8f8f336accb2696fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Wed, 9 Apr 2025 16:56:20 +0200 Subject: [PATCH] Add information about the context switch when hovering the thread in the cpu data timeline --- profiler/src/profiler/TracyView_CpuData.cpp | 81 ++++++++++++++++++--- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/profiler/src/profiler/TracyView_CpuData.cpp b/profiler/src/profiler/TracyView_CpuData.cpp index 3cdc0415..2c3482a6 100644 --- a/profiler/src/profiler/TracyView_CpuData.cpp +++ b/profiler/src/profiler/TracyView_CpuData.cpp @@ -216,15 +216,17 @@ bool View::DrawCpuData( const TimelineContext& ctx, const std::vectorAddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + sty ), color ); if( m_drawThreadHighlight == thread ) @@ -330,6 +332,67 @@ bool View::DrawCpuData( const TimelineContext& ctx, const std::vectorv; + auto it = std::lower_bound( v.begin(), v.end(), ev.Start(), [](const auto& l, const auto& r) { return l.End() < r; } ); + // We should have the data, or something went wrong. + assert( it != v.end() && it->Start() == ev.Start() ); + + // Do we have information about the previous CSwitch? + if( it != v.begin() ) + { + auto& prev = *( it - 1 ); + + ImGui::Separator(); + + TextFocused( "Wait reason:", DecodeContextSwitchReasonCode( prev.Reason() ) ); + ImGui::SameLine(); + ImGui::PushFont( m_smallFont ); + ImGui::AlignTextToFramePadding(); + TextDisabledUnformatted( DecodeContextSwitchReason( prev.Reason() ) ); + ImGui::PopFont(); + TextFocused( "Wait state:", DecodeContextSwitchStateCode( prev.State() ) ); + TextFocused( "Waiting time:", TimeToString( it->WakeupVal() - prev.End() ) ); + } + + // Do we have information about the readying thread? + if( it->Start() - it->WakeupVal() ) + { + ImGui::Separator(); + TextFocused( "WakeUp delay:", TimeToString( it->Start() - it->WakeupVal() ) ); + assert( it->WakeupCpu() < cpuCnt ); + const auto& wakeUpCpuCSwitches = cpuData[it->WakeupCpu()].cs; + auto wakeupit = std::lower_bound( wakeUpCpuCSwitches.begin(), wakeUpCpuCSwitches.end(), it->WakeupVal(), []( const auto& l, const auto& r ) { return l.End() < r; } ); + if( wakeupit != wakeUpCpuCSwitches.end() + && wakeupit->Start() < it->WakeupVal() + && it->WakeupVal() < wakeupit->End() ) + { + TextDisabledUnformatted( "Woken up by:" ); + ImGui::SameLine(); + + const auto wakeupThread = m_worker.DecompressThreadExternal( wakeupit->Thread() ); + bool wakeupThreadLocal, wakeupThreadUntracked; + const char* wakeUpThreadProgram; + auto wakeuplabel = GetThreadContextData( wakeupThread, wakeupThreadLocal, wakeupThreadUntracked, wakeUpThreadProgram ); + + uint32_t wakeupThreadColor = getDisplayThreadColor( wakeupThread, wakeupThreadLocal, wakeupThreadUntracked ); + TextColoredUnformatted( HighlightColor<75>( wakeupThreadColor ), wakeuplabel ); + ImGui::SameLine(); + ImGui::TextDisabled( "(%s)", RealToString( wakeupThread ) ); + } + else + { + TextDisabledUnformatted( "Woken up by Kernel" ); + } + } + + } + + ImGui::EndTooltip(); ImGui::PushFont( m_smallFont );