diff --git a/profiler/src/profiler/TracyView_FlameGraph.cpp b/profiler/src/profiler/TracyView_FlameGraph.cpp index 4b0458a98..ab9685c33 100644 --- a/profiler/src/profiler/TracyView_FlameGraph.cpp +++ b/profiler/src/profiler/TracyView_FlameGraph.cpp @@ -17,6 +17,9 @@ struct FlameGraphItem static void BuildFlameGraph( const Worker& worker, Vector& data, const Vector>& zones ) { + FlameGraphItem* it; + int16_t last = 0; + if( zones.is_magic() ) { auto& vec = *(Vector*)&zones; @@ -25,24 +28,38 @@ static void BuildFlameGraph( const Worker& worker, Vector& 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; } } } @@ -53,24 +70,38 @@ static void BuildFlameGraph( const Worker& worker, Vector& 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; } } }