diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 3b083583..0a9ccbb8 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1882,6 +1882,13 @@ void View::DrawZones() offset += ostep; if( showFull ) { + auto ctxSwitch = m_worker.GetContextSwitchData( v->id ); + if( ctxSwitch ) + { + DrawContextSwitches( ctxSwitch, pxns, wpos, offset ); + offset += ostep; + } + if( m_drawZones ) { depth = DispatchZoneLevel( v->timeline, hover, pxns, int64_t( nspx ), wpos, offset, 0, yMin, yMax ); @@ -2189,6 +2196,30 @@ void View::DrawZones() } } +void View::DrawContextSwitches( const ContextSwitch* ctx, double pxns, const ImVec2& wpos, int offset ) +{ + auto& vec = ctx->v; + auto it = std::lower_bound( vec.begin(), vec.end(), std::max( 0, m_zvStart ), [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } ); + if( it == vec.end() ) return; + + const auto citend = std::lower_bound( it, vec.end(), m_zvEnd, [] ( const auto& l, const auto& r ) { return l.start < r; } ); + if( it == citend ) return; + + const auto w = ImGui::GetWindowContentRegionWidth() - 1; + const auto ty = ImGui::GetFontSize(); + auto draw = ImGui::GetWindowDrawList(); + + while( it < citend ) + { + auto& ev = *it; + const auto end = ev.end >= 0 ? ev.end : m_worker.GetLastTime(); + const auto px0 = std::max( ( ev.start - m_zvStart ) * pxns, -10.0 ); + const auto px1 = std::min( ( end - m_zvStart ) * pxns, w + 10.0 ); + draw->AddLine( wpos + ImVec2( px0, round( offset + ty * 0.5 ) ), wpos + ImVec2( px1, round( offset + ty * 0.5 ) ), 0xFF00FF00 ); + ++it; + } +} + int View::DispatchZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax ) { const auto ty = ImGui::GetFontSize(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 19d56e21..a271e5de 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -108,6 +108,7 @@ private: bool DrawZoneFramesHeader(); bool DrawZoneFrames( const FrameData& frames ); void DrawZones(); + void DrawContextSwitches( const ContextSwitch* ctx, double pxns, const ImVec2& wpos, int offset ); int DispatchZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax ); int DrawZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax ); int SkipZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax );