From 527b5f331185460c6a91371c3fe8bad5d1ff5f9f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 23 Mar 2023 00:04:12 +0100 Subject: [PATCH] Rewrite ghost zone folding. --- server/TracyTimelineItemThread.cpp | 31 +++++++++++++----------------- server/TracyView_ZoneTimeline.cpp | 3 +-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index b1b8c6fa..6fe4bc32 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -323,45 +323,40 @@ void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& t #ifndef TRACY_NO_STATISTICS int TimelineItemThread::PreprocessGhostLevel( const TimelineContext& ctx, const Vector& vec, int depth ) { - const auto pxns = ctx.pxns; const auto nspx = ctx.nspx; const auto vStart = ctx.vStart; const auto vEnd = ctx.vEnd; - auto it = std::lower_bound( vec.begin(), vec.end(), std::max( 0, vStart - 2 * MinVisSize * nspx ), [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } ); + const auto MinVisNs = int64_t( round( MinVisSize * nspx ) ); + + auto it = std::lower_bound( vec.begin(), vec.end(), std::max( 0, vStart - 2 * MinVisNs ), [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } ); if( it == vec.end() ) return depth; const auto zitend = std::lower_bound( it, vec.end(), vEnd, [] ( const auto& l, const auto& r ) { return l.start.Val() < r; } ); if( it == zitend ) return depth; if( (zitend-1)->end.Val() < vStart ) return depth; - const auto MinVisNs = MinVisSize * nspx; int maxdepth = depth + 1; while( it < zitend ) { auto& ev = *it; const auto end = ev.end.Val(); - const auto zsz = std::max( ( end - ev.start.Val() ) * pxns, pxns * 0.5 ); - if( zsz < MinVisSize ) + const auto zsz = end - ev.start.Val(); + if( zsz < MinVisNs ) { - auto px1ns = ev.end.Val() - vStart; - auto rend = end; auto nextTime = end + MinVisNs; + auto next = it + 1; for(;;) { - const auto prevIt = it; - it = std::lower_bound( it, zitend, nextTime, [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } ); - if( it == prevIt ) ++it; - if( it == zitend ) break; - const auto nend = it->end.Val(); - const auto nsnext = nend - vStart; - if( nsnext - px1ns >= MinVisNs * 2 ) break; - px1ns = nsnext; - rend = nend; - nextTime = nend + nspx; + next = std::lower_bound( next, zitend, nextTime, [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } ); + if( next == zitend ) break; + const auto nt = next->end.Val(); + if( nt - nextTime >= MinVisNs ) break; + nextTime = nt + MinVisNs; } - m_draw.emplace_back( TimelineDraw { TimelineDrawType::GhostFolded, uint16_t( depth ), (void**)&ev, rend } ); + m_draw.emplace_back( TimelineDraw { TimelineDrawType::GhostFolded, uint16_t( depth ), (void**)&ev, (next-1)->end } ); + it = next; } else { diff --git a/server/TracyView_ZoneTimeline.cpp b/server/TracyView_ZoneTimeline.cpp index 74e2e758..686e90c1 100644 --- a/server/TracyView_ZoneTimeline.cpp +++ b/server/TracyView_ZoneTimeline.cpp @@ -29,7 +29,6 @@ bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con const auto ty = ctx.ty; const auto ostep = ty + 1; const auto pxns = ctx.pxns; - const auto nspx = ctx.nspx; const auto hover = ctx.hover; const auto yMin = ctx.yMin; const auto yMax = ctx.yMax; @@ -446,7 +445,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vectorAddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( std::max( px1, px0+MinVisSize ), double( w + 10 ) ), offset + ty ), color ); DrawZigZag( draw, wpos + ImVec2( 0, offset + ty/2 ), std::max( px0, -10.0 ), std::min( std::max( px1, px0+MinVisSize ), double( w + 10 ) ), ty/4, DarkenColor( color ) ); if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( std::max( px1, px0+MinVisSize ), double( w + 10 ) ), offset + ty + 1 ) ) )