From 40e08e9594781a60ad9d4f8021d7733e5771ceb6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 23 Mar 2023 22:16:47 +0100 Subject: [PATCH] Draw messages using precalculated list. --- server/TracyTimelineItemThread.cpp | 2 +- server/TracyView.hpp | 3 +- server/TracyView_ZoneTimeline.cpp | 72 ++++++++++++------------------ 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index 304f636c..a46b4b6e 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -233,7 +233,7 @@ void TimelineItemThread::HeaderTooltip( const char* label ) const void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) { - m_view.DrawThreadMessages( ctx, *m_thread, offset ); + m_view.DrawThreadMessagesList( ctx, m_msgDraw, offset, m_thread->id ); #ifndef TRACY_NO_STATISTICS const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 3e48c200..e0acae7c 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -44,6 +44,7 @@ struct TimelineContext; struct TimelineDraw; struct ContextSwitchDraw; struct SamplesDraw; +struct MessagesDraw; class View { @@ -127,7 +128,7 @@ public: void ZoomToRange( int64_t start, int64_t end, bool pause = true ); bool DrawPlot( const TimelineContext& ctx, PlotData& plot, int& offset ); void DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector& draw, const std::vector& ctxDraw, const std::vector& samplesDraw, int& offset, int depth ); - void DrawThreadMessages( const TimelineContext& ctx, const ThreadData& thread, int offset ); + void DrawThreadMessagesList( const TimelineContext& ctx, const std::vector& drawList, int offset, uint64_t tid ); void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr ); bool DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offset ); bool DrawCpuData( const TimelineContext& ctx, int& offset ); diff --git a/server/TracyView_ZoneTimeline.cpp b/server/TracyView_ZoneTimeline.cpp index 049f6622..a563a33a 100644 --- a/server/TracyView_ZoneTimeline.cpp +++ b/server/TracyView_ZoneTimeline.cpp @@ -84,96 +84,80 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con } } -void View::DrawThreadMessages( const TimelineContext& ctx, const ThreadData& thread, int offset ) +void View::DrawThreadMessagesList( const TimelineContext& ctx, const std::vector& drawList, int offset, uint64_t tid ) { - const auto& wpos = ctx.wpos; + const auto vStart = ctx.vStart; + const auto vEnd = ctx.vEnd; const auto pxns = ctx.pxns; - const auto nspx = ctx.nspx; const auto hover = ctx.hover; + const auto& wpos = ctx.wpos; const auto ty = ctx.ty; const auto to = 9.f * GetScale(); const auto th = ( ty - to ) * sqrt( 3 ) * 0.5; auto draw = ImGui::GetWindowDrawList(); - auto msgit = std::lower_bound( thread.messages.begin(), thread.messages.end(), m_vd.zvStart, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); - auto msgend = std::lower_bound( msgit, thread.messages.end(), m_vd.zvEnd+1, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); - - while( msgit < msgend ) + for( auto& v : drawList ) { - const auto next = std::upper_bound( msgit, thread.messages.end(), (*msgit)->time + MinVisSize * nspx, [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs->time; } ); - const auto dist = std::distance( msgit, next ); - - const auto px = ( (*msgit)->time - m_vd.zvStart ) * pxns; + const auto& msg = *v.msg; + const auto px = ( msg.time - vStart ) * pxns; const bool isMsgHovered = hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px - (ty - to) * 0.5 - 1, offset ), wpos + ImVec2( px + (ty - to) * 0.5 + 1, offset + ty ) ); unsigned int color = 0xFFDDDDDD; float animOff = 0; - if( dist > 1 ) + if( v.highlight ) { - if( m_msgHighlight && m_worker.DecompressThread( m_msgHighlight->thread ) == thread.id ) + color = 0xFF4444FF; + if( !isMsgHovered ) { - const auto hTime = m_msgHighlight->time; - if( (*msgit)->time <= hTime && ( next == thread.messages.end() || (*next)->time > hTime ) ) - { - color = 0xFF4444FF; - if( !isMsgHovered ) - { - animOff = -fabs( sin( s_time * 8 ) ) * th; - m_wasActive = true; - } - } + animOff = -fabs( sin( s_time * 8 ) ) * th; + m_wasActive = true; } - draw->AddTriangleFilled( wpos + ImVec2( px - (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px, animOff + offset + to + th ), color ); + } + + if( v.num == 1 ) + { draw->AddTriangle( wpos + ImVec2( px - (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px, animOff + offset + to + th ), color, 2.0f ); } else { - if( m_msgHighlight == *msgit ) - { - color = 0xFF4444FF; - if( !isMsgHovered ) - { - animOff = -fabs( sin( s_time * 8 ) ) * th; - m_wasActive = true; - } - } + draw->AddTriangleFilled( wpos + ImVec2( px - (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px, animOff + offset + to + th ), color ); draw->AddTriangle( wpos + ImVec2( px - (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, animOff + offset + to ), wpos + ImVec2( px, animOff + offset + to + th ), color, 2.0f ); } + if( isMsgHovered ) { ImGui::BeginTooltip(); - if( dist > 1 ) + if( v.num > 1 ) { - ImGui::Text( "%i messages", (int)dist ); + ImGui::Text( "%" PRIu32 " messages", v.num ); } else { - TextFocused( "Message at", TimeToStringExact( (*msgit)->time ) ); - ImGui::PushStyleColor( ImGuiCol_Text, (*msgit)->color ); - ImGui::TextUnformatted( m_worker.GetString( (*msgit)->ref ) ); + TextFocused( "Message at", TimeToStringExact( msg.time ) ); + ImGui::PushStyleColor( ImGuiCol_Text, msg.color ); + ImGui::TextUnformatted( m_worker.GetString( msg.ref ) ); ImGui::PopStyleColor(); } ImGui::EndTooltip(); - m_msgHighlight = *msgit; + m_msgHighlight = &msg; if( IsMouseClicked( 0 ) ) { m_showMessages = true; - m_msgToFocus = *msgit; + m_msgToFocus = &msg; } if( IsMouseClicked( 2 ) ) { - CenterAtTime( (*msgit)->time ); + CenterAtTime( msg.time ); } } - msgit = next; } auto& crash = m_worker.GetCrashEvent(); - if( crash.thread == thread.id && crash.time >= m_vd.zvStart && crash.time <= m_vd.zvEnd ) + if( crash.thread == tid && crash.time >= vStart && crash.time <= vEnd ) { - const auto px = ( crash.time - m_vd.zvStart ) * pxns; + const auto px = ( crash.time - vStart ) * pxns; draw->AddTriangleFilled( wpos + ImVec2( px - (ty - to) * 0.25f, offset + to + th * 0.5f ), wpos + ImVec2( px + (ty - to) * 0.25f, offset + to + th * 0.5f ), wpos + ImVec2( px, offset + to + th ), 0xFF2222FF ); draw->AddTriangle( wpos + ImVec2( px - (ty - to) * 0.25f, offset + to + th * 0.5f ), wpos + ImVec2( px + (ty - to) * 0.25f, offset + to + th * 0.5f ), wpos + ImVec2( px, offset + to + th ), 0xFF2222FF, 2.0f );