Draw samples using precalculated data.

This commit is contained in:
Bartosz Taudul 2023-03-22 22:25:55 +01:00
parent 8bbd50361a
commit 80c15c0f9b
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 40 additions and 60 deletions

View File

@ -259,7 +259,7 @@ void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int of
bool TimelineItemThread::DrawContents( const TimelineContext& ctx, int& offset ) bool TimelineItemThread::DrawContents( const TimelineContext& ctx, int& offset )
{ {
const auto res = m_view.DrawThread( ctx, *m_thread, m_draw, m_ctxDraw, offset, m_depth ); const auto res = m_view.DrawThread( ctx, *m_thread, m_draw, m_ctxDraw, m_samplesDraw, offset, m_depth );
if( !res ) if( !res )
{ {
auto& crash = m_worker.GetCrashEvent(); auto& crash = m_worker.GetCrashEvent();

View File

@ -43,6 +43,7 @@ class SourceView;
struct TimelineContext; struct TimelineContext;
struct TimelineDraw; struct TimelineDraw;
struct ContextSwitchDraw; struct ContextSwitchDraw;
struct SamplesDraw;
class View class View
{ {
@ -123,7 +124,7 @@ public:
void HighlightThread( uint64_t thread ); void HighlightThread( uint64_t thread );
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 );
bool DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, int& offset, int depth ); bool 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 DrawThreadMessages( const TimelineContext& ctx, const ThreadData& thread, int offset );
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 );
@ -206,7 +207,7 @@ private:
void DrawTimelineFramesHeader(); void DrawTimelineFramesHeader();
void DrawTimelineFrames( const FrameData& frames ); void DrawTimelineFrames( const FrameData& frames );
void DrawTimeline(); void DrawTimeline();
void DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ); void DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset );
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid ); void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid );
void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, int offset, int endOffset, bool isFiber ); void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, int offset, int endOffset, bool isFiber );
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );

View File

@ -6,60 +6,57 @@
#include "TracyMouse.hpp" #include "TracyMouse.hpp"
#include "TracyPrint.hpp" #include "TracyPrint.hpp"
#include "TracySourceView.hpp" #include "TracySourceView.hpp"
#include "TracyTimelineContext.hpp"
#include "TracyTimelineDraw.hpp"
#include "TracyView.hpp" #include "TracyView.hpp"
namespace tracy namespace tracy
{ {
void View::DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ) void View::DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset )
{ {
const auto MinVis = 6 * GetScale(); const auto& wpos = ctx.wpos;
auto it = std::lower_bound( vec.begin(), vec.end(), m_vd.zvStart - 2 * MinVis * nspx, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); const auto ty = ctx.ty;
if( it == vec.end() ) return; const auto vStart = ctx.vStart;
const auto itend = std::lower_bound( it, vec.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); const auto pxns = ctx.pxns;
if( it == itend ) return; const auto hover = ctx.hover;
const auto ty0375 = offset + round( ImGui::GetTextLineHeight() * 0.375f ); const auto MinVis = 6 * GetScale();
const auto ty02 = round( ImGui::GetTextLineHeight() * 0.2f ); const auto ty0375 = offset + round( ty * 0.375f );
const auto ty01 = round( ImGui::GetTextLineHeight() * 0.1f ); const auto ty02 = round( ty * 0.2f );
const auto ty01 = round( ty * 0.1f );
const auto y0 = ty0375 - ty02 - 3; const auto y0 = ty0375 - ty02 - 3;
const auto y1 = ty0375 + ty02 - 1; const auto y1 = ty0375 + ty02 - 1;
auto begin = vec.begin();
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
bool tooltipDisplayed = false; bool tooltipDisplayed = false;
while( it < itend ) for( auto& v : drawList )
{ {
bool visible = true; auto it = begin + v.idx;
const auto px0 = ( it->time.Val() - m_vd.zvStart ) * pxns; const auto t0 = it->time.Val();
double px1; const auto px0 = ( t0 - vStart ) * pxns;
auto next = it+1; if( v.folded )
int num;
if( next != itend )
{ {
auto px1ns = next->time.Val() - m_vd.zvStart; const auto eit = it + v.num;
px1 = px1ns * pxns; const auto t1 = eit->time.Val();
if( px1 - px0 < MinVis ) const auto px1 = ( t1 - vStart ) * pxns;
DrawZigZag( draw, wpos + ImVec2( 0, ty0375 ), px0, std::max( px1, px0+MinVis ), ty01, 0xFF997777 );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, y0 ), wpos + ImVec2( std::max( px1, px0+MinVis ), y1 ) ) )
{ {
const auto MinVisNs = MinVis * nspx; ImGui::BeginTooltip();
visible = false; ImGui::TextUnformatted( "Multiple call stack samples" );
auto nextTime = px0 + MinVisNs; TextFocused( "Number of samples:", RealToString( v.num ) );
for(;;) ImGui::EndTooltip();
if( IsMouseClicked( 2 ) )
{ {
const auto prev = next; ZoomToRange( t0, t1 );
next = std::lower_bound( next, itend, nextTime, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
if( prev == next ) ++next;
if( next == itend ) break;
const auto nsnext = next->time.Val() - m_vd.zvStart;
if( nsnext - px1ns >= MinVisNs ) break;
px1ns = nsnext;
nextTime = next->time.Val() + nspx;
}
num = next - it;
px1 = px1ns * pxns;
} }
} }
if( visible ) }
else
{ {
draw->AddCircleFilled( wpos + ImVec2( px0, ty0375 ), ty02, 0xFFDD8888 ); draw->AddCircleFilled( wpos + ImVec2( px0, ty0375 ), ty02, 0xFFDD8888 );
if( !tooltipDisplayed && hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0 - ty02 - 2, y0 ), wpos + ImVec2( px0 + ty02 + 1, y1 ) ) ) if( !tooltipDisplayed && hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0 - ty02 - 2, y0 ), wpos + ImVec2( px0 + ty02 + 1, y1 ) ) )
@ -72,24 +69,6 @@ void View::DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns,
} }
} }
} }
else
{
DrawZigZag( draw, wpos + ImVec2( 0, ty0375 ), px0, std::max( px1, px0+MinVis ), ty01, 0xFF997777 );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, y0 ), wpos + ImVec2( std::max( px1, px0+MinVis ), y1 ) ) )
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Multiple call stack samples" );
TextFocused( "Number of samples:", RealToString( num ) );
ImGui::EndTooltip();
if( IsMouseClicked( 2 ) )
{
const auto prev = next-1;
ZoomToRange( it->time.Val(), prev->time.Val() + 1 );
}
}
}
it = next;
} }
} }

View File

@ -23,7 +23,7 @@ static tracy_force_inline uint32_t MixGhostColor( uint32_t c0, uint32_t c1 )
( ( ( ( ( c0 & 0x000000FF ) ) + 3 * ( ( c1 & 0x000000FF ) ) ) >> 2 ) ); ( ( ( ( ( c0 & 0x000000FF ) ) + 3 * ( ( c1 & 0x000000FF ) ) ) >> 2 ) );
} }
bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, int& offset, int depth ) bool View::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 )
{ {
const auto& wpos = ctx.wpos; const auto& wpos = ctx.wpos;
const auto ty = ctx.ty; const auto ty = ctx.ty;
@ -40,7 +40,7 @@ bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
ImGui::PopFont(); ImGui::PopFont();
const auto sampleOffset = offset; const auto sampleOffset = offset;
const auto hasSamples = m_vd.drawSamples && !thread.samples.empty(); const auto hasSamples = m_vd.drawSamples && !samplesDraw.empty();
const auto hasCtxSwitch = m_vd.drawContextSwitches && !ctxDraw.empty(); const auto hasCtxSwitch = m_vd.drawContextSwitches && !ctxDraw.empty();
if( hasSamples ) if( hasSamples )
@ -74,7 +74,7 @@ bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
} }
if( hasSamples ) if( hasSamples )
{ {
DrawSamples( thread.samples, hover, pxns, int64_t( nspx ), wpos, sampleOffset ); DrawSampleList( ctx, samplesDraw, thread.samples, sampleOffset );
} }
if( m_vd.drawLocks ) if( m_vd.drawLocks )
@ -446,7 +446,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
const auto color = m_vd.dynamicColors == 2 ? 0xFF666666 : MixGhostColor( GetThreadColor( tid, v.depth ), 0x665555 ); const auto color = m_vd.dynamicColors == 2 ? 0xFF666666 : MixGhostColor( GetThreadColor( tid, v.depth ), 0x665555 );
const auto rend = v.rend.Val(); const auto rend = v.rend.Val();
const auto px0 = ( ev.start.Val() - m_vd.zvStart ) * pxns; const auto px0 = ( ev.start.Val() - m_vd.zvStart ) * pxns;
const auto px1 = ( rend - m_vd.zvStart ) * pxns; const auto px1 = ( rend - ev.end.Val() ) * pxns;
draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( std::max( px1, px0+MinVisSize ), double( w + 10 ) ), offset + ty ), color ); draw->AddRectFilled( 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 ) ); 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 ) ) ) 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 ) ) )