From f55d0d0f55c3169b6f44f012548bc6d1643b343f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 23 Mar 2023 00:40:09 +0100 Subject: [PATCH] Fix distance calculation in folding. The folding process starts at the "next" item. The nextTime variable represents a time point before which everything should be folded, because all items in that range are smaller than MinVis range. The lower_bound search finds a new "next" item, which will be beyond the nextTime range. But nextTime has origin in the previous "next" item, which may be not the last item in the folding range. If the distance between the new "next" and the item before is smaller than MinVis, then the new "next" item is also folded and the folding loop must continue to run. --- server/TracyTimelineItemThread.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index 2040a8c6..0b587092 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -351,8 +351,11 @@ int TimelineItemThread::PreprocessGhostLevel( const TimelineContext& ctx, const { next = std::lower_bound( next, zitend, nextTime, [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } ); if( next == zitend ) break; + auto prev = next - 1; + if( prev == it ) break; + const auto pt = prev->end.Val(); const auto nt = next->end.Val(); - if( nt - nextTime >= MinVisNs ) break; + if( nt - pt >= MinVisNs ) break; nextTime = nt + MinVisNs; } m_draw.emplace_back( TimelineDraw { TimelineDrawType::GhostFolded, uint16_t( depth ), (void**)&ev, (next-1)->end } ); @@ -422,8 +425,11 @@ int TimelineItemThread::PreprocessZoneLevel( const TimelineContext& ctx, const V { next = std::lower_bound( next, zitend, nextTime, [] ( const auto& l, const auto& r ) { Adapter a; return (uint64_t)a(l).End() < (uint64_t)r; } ); if( next == zitend ) break; + auto prev = next - 1; + if( prev == it ) break; + const auto pt = m_worker.GetZoneEnd( a(*prev) ); const auto nt = m_worker.GetZoneEnd( a(*next) ); - if( nt - nextTime >= MinVisNs ) break; + if( nt - pt >= MinVisNs ) break; nextTime = nt + MinVisNs; } m_draw.emplace_back( TimelineDraw { TimelineDrawType::Folded, uint16_t( depth ), (void**)&ev, m_worker.GetZoneEnd( a(*(next-1)) ), uint32_t( next - it ) } ); @@ -543,7 +549,7 @@ void TimelineItemThread::PreprocessSamples( const TimelineContext& ctx, const Ve const auto vEnd = ctx.vEnd; const auto nspx = ctx.nspx; - const auto MinVis = 3 * GetScale(); + const auto MinVis = 5 * GetScale(); const auto MinVisNs = int64_t( round( MinVis * nspx ) ); auto it = std::lower_bound( vec.begin(), vec.end(), vStart - MinVisNs, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); @@ -562,8 +568,11 @@ void TimelineItemThread::PreprocessSamples( const TimelineContext& ctx, const Ve { next = std::lower_bound( next, itend, nextTime, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); if( next == itend ) break; + auto prev = next - 1; + if( prev == it ) break; + const auto pt = prev->time.Val(); const auto nt = next->time.Val(); - if( nt - nextTime >= MinVisNs ) break; + if( nt - pt >= MinVisNs ) break; nextTime = nt + MinVisNs; } }