Extend plots to the end of the trace.

This commit is contained in:
Bartosz Taudul 2024-10-09 23:55:50 +02:00
parent 90c072b66c
commit 1bd84419c0
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 46 additions and 4 deletions

View File

@ -112,7 +112,7 @@ int64_t TimelineItemPlot::RangeEnd() const
bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset )
{
return m_view.DrawPlot( ctx, *m_plot, m_draw, offset );
return m_view.DrawPlot( ctx, *m_plot, m_draw, offset, m_rightEnd );
}
void TimelineItemPlot::DrawFinished()
@ -138,17 +138,30 @@ void TimelineItemPlot::Preprocess( const TimelineContext& ctx, TaskDispatch& td,
auto& vec = m_plot->data;
vec.ensure_sorted();
if( vec.front().time.Val() > vEnd || vec.back().time.Val() < vStart )
if( vec.front().time.Val() > vEnd )
{
m_plot->rMin = 0;
m_plot->rMax = 0;
m_plot->num = 0;
m_rightEnd = false;
return;
}
else if( vec.back().time.Val() < vStart )
{
const auto lastTime = m_worker.GetLastTime();
const auto val = vec.back().val;
m_plot->rMin = val - 1;
m_plot->rMax = val + 1;
m_plot->num = lastTime < vStart ? 0 : 1;
m_rightEnd = vec.back().time.Val() < lastTime;
return;
}
auto it = std::lower_bound( vec.begin(), vec.end(), vStart, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
auto end = std::lower_bound( it, vec.end(), vEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
m_rightEnd = end == vec.end() && vec.back().time.Val() < m_worker.GetLastTime();
if( end != vec.end() ) end++;
if( it != vec.begin() ) it--;

View File

@ -36,6 +36,7 @@ private:
PlotData* m_plot;
std::vector<uint32_t> m_draw;
bool m_rightEnd;
};
}

View File

@ -151,7 +151,7 @@ public:
void HighlightThread( uint64_t thread );
void ZoomToRange( int64_t start, int64_t end, bool pause = true );
bool DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vector<uint32_t>& plotDraw, int& offset );
bool DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vector<uint32_t>& plotDraw, int& offset, bool rightEnd );
void DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, const std::vector<SamplesDraw>& samplesDraw, const std::vector<std::unique_ptr<LockDraw>>& lockDraw, int& offset, int depth, bool hasCtxSwitches, bool hasSamples );
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 );

View File

@ -11,7 +11,7 @@
namespace tracy
{
bool View::DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vector<uint32_t>& plotDraw, int& offset )
bool View::DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vector<uint32_t>& plotDraw, int& offset, bool rightEnd )
{
auto draw = ImGui::GetWindowDrawList();
const auto& wpos = ctx.wpos;
@ -173,6 +173,34 @@ bool View::DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vect
}
}
if( rightEnd )
{
const auto lastTime = m_worker.GetLastTime();
if( lastTime > m_vd.zvStart )
{
double y;
double x0 = 0;
const auto x1 = std::min<double>( ( lastTime - m_vd.zvStart ) * pxns, w );
if( plotDraw.empty() )
{
y = PlotHeight * 0.5;
DrawLine( draw, dpos + ImVec2( 0, offset + y ), dpos + ImVec2( x1, offset + y ), color );
}
else
{
x0 = ( plot.data.back().time.Val() - m_vd.zvStart ) * pxns;
y = PlotHeight - ( plot.data.back().val - min ) * revrange * PlotHeight;
DrawLine( draw, dpos + ImVec2( x0, offset + y ), dpos + ImVec2( x1, offset + y ), color );
}
if( plot.fill )
{
draw->AddRectFilled( dpos + ImVec2( x0, offset + PlotHeight ), dpos + ImVec2( x1, offset + y ), fill );
}
}
}
auto tmp = FormatPlotValue( plot.rMax, plot.format );
DrawTextSuperContrast( draw, wpos + ImVec2( 0, offset ), color, tmp );
offset += PlotHeight - ty;