Draw messages using precalculated list.

This commit is contained in:
Bartosz Taudul 2023-03-23 22:16:47 +01:00
parent 6c21edd509
commit 40e08e9594
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 31 additions and 46 deletions

View File

@ -233,7 +233,7 @@ void TimelineItemThread::HeaderTooltip( const char* label ) const
void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) 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 #ifndef TRACY_NO_STATISTICS
const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty(); const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty();

View File

@ -44,6 +44,7 @@ struct TimelineContext;
struct TimelineDraw; struct TimelineDraw;
struct ContextSwitchDraw; struct ContextSwitchDraw;
struct SamplesDraw; struct SamplesDraw;
struct MessagesDraw;
class View class View
{ {
@ -127,7 +128,7 @@ public:
void ZoomToRange( int64_t start, int64_t end, bool pause = true ); void ZoomToRange( int64_t start, int64_t end, bool pause = true );
bool DrawPlot( const TimelineContext& ctx, PlotData& plot, int& offset ); bool DrawPlot( const TimelineContext& ctx, PlotData& plot, int& offset );
void DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, const std::vector<SamplesDraw>& samplesDraw, int& offset, int depth ); void DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, const std::vector<SamplesDraw>& samplesDraw, int& offset, int depth );
void DrawThreadMessages( const TimelineContext& ctx, const ThreadData& thread, int offset ); void DrawThreadMessagesList( const TimelineContext& ctx, const std::vector<MessagesDraw>& drawList, int offset, uint64_t tid );
void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr ); void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr );
bool DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offset ); bool DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offset );
bool DrawCpuData( const TimelineContext& ctx, int& offset ); bool DrawCpuData( const TimelineContext& ctx, int& offset );

View File

@ -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<MessagesDraw>& 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 pxns = ctx.pxns;
const auto nspx = ctx.nspx;
const auto hover = ctx.hover; const auto hover = ctx.hover;
const auto& wpos = ctx.wpos;
const auto ty = ctx.ty; const auto ty = ctx.ty;
const auto to = 9.f * GetScale(); const auto to = 9.f * GetScale();
const auto th = ( ty - to ) * sqrt( 3 ) * 0.5; const auto th = ( ty - to ) * sqrt( 3 ) * 0.5;
auto draw = ImGui::GetWindowDrawList(); 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; } ); for( auto& v : drawList )
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 )
{ {
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& msg = *v.msg;
const auto dist = std::distance( msgit, next ); const auto px = ( msg.time - vStart ) * pxns;
const auto px = ( (*msgit)->time - m_vd.zvStart ) * 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 ) ); 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; unsigned int color = 0xFFDDDDDD;
float animOff = 0; 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; animOff = -fabs( sin( s_time * 8 ) ) * th;
if( (*msgit)->time <= hTime && ( next == thread.messages.end() || (*next)->time > hTime ) ) m_wasActive = true;
{
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 ); }
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 ); 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 else
{ {
if( m_msgHighlight == *msgit ) 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 );
{
color = 0xFF4444FF;
if( !isMsgHovered )
{
animOff = -fabs( sin( s_time * 8 ) ) * th;
m_wasActive = true;
}
}
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 ); 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 ) if( isMsgHovered )
{ {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if( dist > 1 ) if( v.num > 1 )
{ {
ImGui::Text( "%i messages", (int)dist ); ImGui::Text( "%" PRIu32 " messages", v.num );
} }
else else
{ {
TextFocused( "Message at", TimeToStringExact( (*msgit)->time ) ); TextFocused( "Message at", TimeToStringExact( msg.time ) );
ImGui::PushStyleColor( ImGuiCol_Text, (*msgit)->color ); ImGui::PushStyleColor( ImGuiCol_Text, msg.color );
ImGui::TextUnformatted( m_worker.GetString( (*msgit)->ref ) ); ImGui::TextUnformatted( m_worker.GetString( msg.ref ) );
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
ImGui::EndTooltip(); ImGui::EndTooltip();
m_msgHighlight = *msgit; m_msgHighlight = &msg;
if( IsMouseClicked( 0 ) ) if( IsMouseClicked( 0 ) )
{ {
m_showMessages = true; m_showMessages = true;
m_msgToFocus = *msgit; m_msgToFocus = &msg;
} }
if( IsMouseClicked( 2 ) ) if( IsMouseClicked( 2 ) )
{ {
CenterAtTime( (*msgit)->time ); CenterAtTime( msg.time );
} }
} }
msgit = next;
} }
auto& crash = m_worker.GetCrashEvent(); 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->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 ); 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 );