1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-30 20:53:52 +00:00

Extract flame graph level drawing to a separate function.

This commit is contained in:
Bartosz Taudul 2024-10-27 11:27:44 +01:00
parent a916050724
commit 869d75f53e
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 14 additions and 12 deletions

View File

@ -277,6 +277,7 @@ private:
void DrawWaitStacks(); void DrawWaitStacks();
void DrawFlameGraph(); void DrawFlameGraph();
void DrawFlameGraphHeader( uint64_t timespan ); void DrawFlameGraphHeader( uint64_t timespan );
void DrawFlameGraphLevel( const std::vector<FlameGraphItem>& data, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples );
void DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples ); void DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples );
void BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones ); void BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones );
void BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones, const ContextSwitch* ctx ); void BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones, const ContextSwitch* ctx );

View File

@ -260,6 +260,15 @@ struct FlameGraphContext
double nxps; double nxps;
}; };
void View::DrawFlameGraphLevel( const std::vector<FlameGraphItem>& data, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples )
{
for( auto& v : data )
{
DrawFlameGraphItem( v, ctx, ts, depth, samples );
ts += v.time;
}
}
void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples ) void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ctx, uint64_t ts, int depth, bool samples )
{ {
const auto x0 = ctx.dpos.x + ts * ctx.pxns; const auto x0 = ctx.dpos.x + ts * ctx.pxns;
@ -448,12 +457,7 @@ void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ct
} }
} }
uint64_t cts = ts; DrawFlameGraphLevel( item.children, ctx, ts, depth+1, samples );
for( auto& v : item.children )
{
DrawFlameGraphItem( v, ctx, cts, depth+1, samples );
cts += v.time;
}
} }
void View::DrawFlameGraphHeader( uint64_t timespan ) void View::DrawFlameGraphHeader( uint64_t timespan )
@ -532,6 +536,8 @@ static void MergeFlameGraph( std::vector<FlameGraphItem>& dst, std::vector<Flame
} }
} }
void View::DrawFlameGraph() void View::DrawFlameGraph()
{ {
const auto scale = GetScale(); const auto scale = GetScale();
@ -724,12 +730,7 @@ void View::DrawFlameGraph()
ctx.nxps = 1.0 / ctx.pxns; ctx.nxps = 1.0 / ctx.pxns;
ImGui::ItemSize( region ); ImGui::ItemSize( region );
uint64_t ts = 0; DrawFlameGraphLevel( m_flameGraphData, ctx, 0, 0, m_flameMode == 1 );
for( auto& v : m_flameGraphData )
{
DrawFlameGraphItem( v, ctx, ts, 0, m_flameMode == 1 );
ts += v.time;
}
} }
ImGui::EndChild(); ImGui::EndChild();