Skip to content

Commit

Permalink
Extend plots to the end of the trace.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Oct 9, 2024
1 parent 90c072b commit 1bd8441
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
17 changes: 15 additions & 2 deletions profiler/src/profiler/TracyTimelineItemPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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--;

Expand Down
1 change: 1 addition & 0 deletions profiler/src/profiler/TracyTimelineItemPlot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TimelineItemPlot final : public TimelineItem
PlotData* m_plot;

std::vector<uint32_t> m_draw;
bool m_rightEnd;
};

}
Expand Down
2 changes: 1 addition & 1 deletion profiler/src/profiler/TracyView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class View

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 );
Expand Down
30 changes: 29 additions & 1 deletion profiler/src/profiler/TracyView_Plots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1bd8441

Please sign in to comment.