Skip to content

Commit

Permalink
Cache last source location entry.
Browse files Browse the repository at this point in the history
227 ms -> 138 ms
  • Loading branch information
wolfpld committed Sep 8, 2024
1 parent 0c0e4f5 commit 8b8ff93
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions profiler/src/profiler/TracyView_FlameGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct FlameGraphItem

static void BuildFlameGraph( const Worker& worker, Vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones )
{
FlameGraphItem* it;
int16_t last = 0;

if( zones.is_magic() )
{
auto& vec = *(Vector<ZoneEvent>*)&zones;
Expand All @@ -25,24 +28,38 @@ static void BuildFlameGraph( const Worker& worker, Vector<FlameGraphItem>& data,
if( !v.IsEndValid() ) break;
const auto srcloc = v.SrcLoc();
const auto duration = v.End() - v.Start();
auto it = std::find_if( data.begin(), data.end(), [srcloc]( const auto& v ) { return v.srcloc == srcloc; } );
if( it == data.end() )
if( srcloc == last )
{
data.push_back( FlameGraphItem { srcloc, duration } );
it->time += duration;
if( v.HasChildren() )
{
auto& children = worker.GetZoneChildren( v.Child() );
BuildFlameGraph( worker, data.back().children, children );
BuildFlameGraph( worker, it->children, children );
}
}
else
{
it->time += duration;
if( v.HasChildren() )
it = std::find_if( data.begin(), data.end(), [srcloc]( const auto& v ) { return v.srcloc == srcloc; } );
if( it == data.end() )
{
auto& children = worker.GetZoneChildren( v.Child() );
BuildFlameGraph( worker, it->children, children );
data.push_back( FlameGraphItem { srcloc, duration } );
if( v.HasChildren() )
{
auto& children = worker.GetZoneChildren( v.Child() );
BuildFlameGraph( worker, data.back().children, children );
}
it = &data.back();
}
else
{
it->time += duration;
if( v.HasChildren() )
{
auto& children = worker.GetZoneChildren( v.Child() );
BuildFlameGraph( worker, it->children, children );
}
}
last = srcloc;
}
}
}
Expand All @@ -53,24 +70,38 @@ static void BuildFlameGraph( const Worker& worker, Vector<FlameGraphItem>& data,
if( !v->IsEndValid() ) break;
const auto srcloc = v->SrcLoc();
const auto duration = v->End() - v->Start();
auto it = std::find_if( data.begin(), data.end(), [srcloc]( const auto& v ) { return v.srcloc == srcloc; } );
if( it == data.end() )
if( srcloc == last )
{
data.push_back( FlameGraphItem { srcloc, duration } );
it->time += duration;
if( v->HasChildren() )
{
auto& children = worker.GetZoneChildren( v->Child() );
BuildFlameGraph( worker, data.back().children, children );
BuildFlameGraph( worker, it->children, children );
}
}
else
{
it->time += duration;
if( v->HasChildren() )
it = std::find_if( data.begin(), data.end(), [srcloc]( const auto& v ) { return v.srcloc == srcloc; } );
if( it == data.end() )
{
auto& children = worker.GetZoneChildren( v->Child() );
BuildFlameGraph( worker, it->children, children );
data.push_back( FlameGraphItem { srcloc, duration } );
if( v->HasChildren() )
{
auto& children = worker.GetZoneChildren( v->Child() );
BuildFlameGraph( worker, data.back().children, children );
}
it = &data.back();
}
else
{
it->time += duration;
if( v->HasChildren() )
{
auto& children = worker.GetZoneChildren( v->Child() );
BuildFlameGraph( worker, it->children, children );
}
}
last = srcloc;
}
}
}
Expand Down

0 comments on commit 8b8ff93

Please sign in to comment.