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.
This commit is contained in:
Bartosz Taudul 2023-03-23 00:40:09 +01:00
parent aa8175ed47
commit f55d0d0f55
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -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; } ); next = std::lower_bound( next, zitend, nextTime, [] ( const auto& l, const auto& r ) { return l.end.Val() < r; } );
if( next == zitend ) break; if( next == zitend ) break;
auto prev = next - 1;
if( prev == it ) break;
const auto pt = prev->end.Val();
const auto nt = next->end.Val(); const auto nt = next->end.Val();
if( nt - nextTime >= MinVisNs ) break; if( nt - pt >= MinVisNs ) break;
nextTime = nt + MinVisNs; nextTime = nt + MinVisNs;
} }
m_draw.emplace_back( TimelineDraw { TimelineDrawType::GhostFolded, uint16_t( depth ), (void**)&ev, (next-1)->end } ); 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; } ); 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; 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) ); const auto nt = m_worker.GetZoneEnd( a(*next) );
if( nt - nextTime >= MinVisNs ) break; if( nt - pt >= MinVisNs ) break;
nextTime = nt + MinVisNs; 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 ) } ); 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 vEnd = ctx.vEnd;
const auto nspx = ctx.nspx; const auto nspx = ctx.nspx;
const auto MinVis = 3 * GetScale(); const auto MinVis = 5 * GetScale();
const auto MinVisNs = int64_t( round( MinVis * nspx ) ); 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; } ); 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; } ); next = std::lower_bound( next, itend, nextTime, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
if( next == itend ) break; if( next == itend ) break;
auto prev = next - 1;
if( prev == it ) break;
const auto pt = prev->time.Val();
const auto nt = next->time.Val(); const auto nt = next->time.Val();
if( nt - nextTime >= MinVisNs ) break; if( nt - pt >= MinVisNs ) break;
nextTime = nt + MinVisNs; nextTime = nt + MinVisNs;
} }
} }