mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-29 08:54:34 +00:00
Draw samples using precalculated data.
This commit is contained in:
parent
8bbd50361a
commit
80c15c0f9b
@ -259,7 +259,7 @@ void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int of
|
||||
|
||||
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 )
|
||||
{
|
||||
auto& crash = m_worker.GetCrashEvent();
|
||||
|
@ -43,6 +43,7 @@ class SourceView;
|
||||
struct TimelineContext;
|
||||
struct TimelineDraw;
|
||||
struct ContextSwitchDraw;
|
||||
struct SamplesDraw;
|
||||
|
||||
class View
|
||||
{
|
||||
@ -123,7 +124,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, 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 DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr );
|
||||
bool DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offset );
|
||||
@ -206,7 +207,7 @@ private:
|
||||
void DrawTimelineFramesHeader();
|
||||
void DrawTimelineFrames( const FrameData& frames );
|
||||
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 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 );
|
||||
|
@ -6,60 +6,57 @@
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracySourceView.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
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();
|
||||
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; } );
|
||||
if( it == vec.end() ) return;
|
||||
const auto itend = std::lower_bound( it, vec.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
|
||||
if( it == itend ) return;
|
||||
const auto& wpos = ctx.wpos;
|
||||
const auto ty = ctx.ty;
|
||||
const auto vStart = ctx.vStart;
|
||||
const auto pxns = ctx.pxns;
|
||||
const auto hover = ctx.hover;
|
||||
|
||||
const auto ty0375 = offset + round( ImGui::GetTextLineHeight() * 0.375f );
|
||||
const auto ty02 = round( ImGui::GetTextLineHeight() * 0.2f );
|
||||
const auto ty01 = round( ImGui::GetTextLineHeight() * 0.1f );
|
||||
const auto MinVis = 6 * GetScale();
|
||||
const auto ty0375 = offset + round( ty * 0.375f );
|
||||
const auto ty02 = round( ty * 0.2f );
|
||||
const auto ty01 = round( ty * 0.1f );
|
||||
const auto y0 = ty0375 - ty02 - 3;
|
||||
const auto y1 = ty0375 + ty02 - 1;
|
||||
auto begin = vec.begin();
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
|
||||
bool tooltipDisplayed = false;
|
||||
|
||||
while( it < itend )
|
||||
for( auto& v : drawList )
|
||||
{
|
||||
bool visible = true;
|
||||
const auto px0 = ( it->time.Val() - m_vd.zvStart ) * pxns;
|
||||
double px1;
|
||||
auto next = it+1;
|
||||
int num;
|
||||
if( next != itend )
|
||||
auto it = begin + v.idx;
|
||||
const auto t0 = it->time.Val();
|
||||
const auto px0 = ( t0 - vStart ) * pxns;
|
||||
if( v.folded )
|
||||
{
|
||||
auto px1ns = next->time.Val() - m_vd.zvStart;
|
||||
px1 = px1ns * pxns;
|
||||
if( px1 - px0 < MinVis )
|
||||
const auto eit = it + v.num;
|
||||
const auto t1 = eit->time.Val();
|
||||
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;
|
||||
visible = false;
|
||||
auto nextTime = px0 + MinVisNs;
|
||||
for(;;)
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted( "Multiple call stack samples" );
|
||||
TextFocused( "Number of samples:", RealToString( v.num ) );
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
const auto prev = next;
|
||||
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;
|
||||
ZoomToRange( t0, t1 );
|
||||
}
|
||||
num = next - it;
|
||||
px1 = px1ns * pxns;
|
||||
}
|
||||
}
|
||||
if( visible )
|
||||
else
|
||||
{
|
||||
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 ) ) )
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ static tracy_force_inline uint32_t MixGhostColor( uint32_t c0, uint32_t c1 )
|
||||
( ( ( ( ( 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 ty = ctx.ty;
|
||||
@ -40,7 +40,7 @@ bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
|
||||
ImGui::PopFont();
|
||||
|
||||
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();
|
||||
|
||||
if( hasSamples )
|
||||
@ -74,7 +74,7 @@ bool View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
|
||||
}
|
||||
if( hasSamples )
|
||||
{
|
||||
DrawSamples( thread.samples, hover, pxns, int64_t( nspx ), wpos, sampleOffset );
|
||||
DrawSampleList( ctx, samplesDraw, thread.samples, sampleOffset );
|
||||
}
|
||||
|
||||
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 rend = v.rend.Val();
|
||||
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 );
|
||||
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 ) ) )
|
||||
|
Loading…
Reference in New Issue
Block a user