Preprocess thread messages.

This commit is contained in:
Bartosz Taudul 2023-03-23 21:47:40 +01:00
parent fbc87275e7
commit a141aafaab
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 59 additions and 0 deletions

View File

@ -65,6 +65,13 @@ struct SamplesDraw
uint32_t idx;
};
struct MessagesDraw
{
short_ptr<MessageData> msg;
bool highlight;
uint32_t num;
};
}
#endif

View File

@ -278,6 +278,7 @@ void TimelineItemThread::DrawFinished()
m_samplesDraw.clear();
m_ctxDraw.clear();
m_draw.clear();
m_msgDraw.clear();
}
void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& td )
@ -285,6 +286,7 @@ void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& t
assert( m_samplesDraw.empty() );
assert( m_ctxDraw.empty() );
assert( m_draw.empty() );
assert( m_msgDraw.empty() );
td.Queue( [this, &ctx] {
#ifndef TRACY_NO_STATISTICS
@ -318,6 +320,10 @@ void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& t
PreprocessSamples( ctx, m_thread->samples );
} );
}
td.Queue( [this, &ctx] {
PreprocessMessages( ctx, m_thread->messages, m_thread->id );
} );
}
#ifndef TRACY_NO_STATISTICS
@ -581,4 +587,48 @@ void TimelineItemThread::PreprocessSamples( const TimelineContext& ctx, const Ve
}
}
void TimelineItemThread::PreprocessMessages( const TimelineContext& ctx, const Vector<short_ptr<MessageData>>& vec, uint64_t tid )
{
const auto vStart = ctx.vStart;
const auto vEnd = ctx.vEnd;
const auto nspx = ctx.nspx;
const auto MinVisNs = MinVisSize * nspx;
auto it = std::lower_bound( vec.begin(), vec.end(), vStart, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
if( it == vec.end() ) return;
auto end = std::lower_bound( it, vec.end(), vEnd+1, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
if( it == end ) return;
const auto hMsg = m_view.GetMessageHighlight();
const auto hThread = hMsg ? m_worker.DecompressThread( hMsg->thread ) : 0;
while( it < end )
{
const auto msgTime = (*it)->time;
const auto nextTime = msgTime + MinVisNs;
const auto next = std::upper_bound( it, vec.end(), nextTime, [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs->time; } );
const auto num = next - it;
bool hilite;
if( num == 1 )
{
hilite = hMsg == *it;
}
else
{
if( hMsg && hThread == tid )
{
const auto hTime = hMsg->time;
hilite = (*it)->time <= hTime && ( next == vec.end() || (*next)->time > hTime );
}
else
{
hilite = false;
}
}
m_msgDraw.emplace_back( MessagesDraw { *it, hilite, uint32_t( num ) } );
it = next;
}
}
}

View File

@ -44,6 +44,7 @@ private:
void PreprocessContextSwitches( const TimelineContext& ctx, const ContextSwitch& ctxSwitch );
void PreprocessSamples( const TimelineContext& ctx, const Vector<SampleData>& vec );
void PreprocessMessages( const TimelineContext& ctx, const Vector<short_ptr<MessageData>>& vec, uint64_t tid );
const ThreadData* m_thread;
bool m_ghost;
@ -51,6 +52,7 @@ private:
std::vector<SamplesDraw> m_samplesDraw;
std::vector<ContextSwitchDraw> m_ctxDraw;
std::vector<TimelineDraw> m_draw;
std::vector<MessagesDraw> m_msgDraw;
int m_depth;
};