mirror of
https://github.com/wolfpld/tracy
synced 2025-05-02 13:43:52 +00:00
Flame graph builder.
This commit is contained in:
parent
692fcc225f
commit
5b75954c5b
@ -1,8 +1,92 @@
|
|||||||
|
#include "TracyEvent.hpp"
|
||||||
|
#include "TracyVector.hpp"
|
||||||
#include "TracyView.hpp"
|
#include "TracyView.hpp"
|
||||||
|
#include "tracy_robin_hood.h"
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct FlameGraphItem
|
||||||
|
{
|
||||||
|
int16_t srcloc;
|
||||||
|
int64_t time;
|
||||||
|
Vector<FlameGraphItem> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void BuildFlameGraph( const Worker& worker, Vector<FlameGraphItem>& data, const Vector<short_ptr<ZoneEvent>>& zones )
|
||||||
|
{
|
||||||
|
unordered_flat_map<int16_t, uint16_t> map;
|
||||||
|
for( size_t i=0; i<data.size(); i++ ) map.emplace( data[i].srcloc, i );
|
||||||
|
|
||||||
|
if( zones.is_magic() )
|
||||||
|
{
|
||||||
|
auto& vec = *(Vector<ZoneEvent>*)&zones;
|
||||||
|
for( auto& v : vec )
|
||||||
|
{
|
||||||
|
if( !v.IsEndValid() ) break;
|
||||||
|
const auto srcloc = v.SrcLoc();
|
||||||
|
const auto duration = v.End() - v.Start();
|
||||||
|
auto it = map.find( srcloc );
|
||||||
|
if( it == map.end() )
|
||||||
|
{
|
||||||
|
map.emplace( srcloc, data.size() );
|
||||||
|
data.push_back( FlameGraphItem { srcloc, duration } );
|
||||||
|
if( v.HasChildren() )
|
||||||
|
{
|
||||||
|
auto& children = worker.GetZoneChildren( v.Child() );
|
||||||
|
BuildFlameGraph( worker, data.back().children, children );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto& item = data[it->second];
|
||||||
|
item.time += duration;
|
||||||
|
if( v.HasChildren() )
|
||||||
|
{
|
||||||
|
auto& children = worker.GetZoneChildren( v.Child() );
|
||||||
|
BuildFlameGraph( worker, item.children, children );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for( auto& v : zones )
|
||||||
|
{
|
||||||
|
if( !v->IsEndValid() ) break;
|
||||||
|
const auto srcloc = v->SrcLoc();
|
||||||
|
const auto duration = v->End() - v->Start();
|
||||||
|
auto it = map.find( srcloc );
|
||||||
|
if( it == map.end() )
|
||||||
|
{
|
||||||
|
map.emplace( srcloc, data.size() );
|
||||||
|
data.push_back( FlameGraphItem { srcloc, duration } );
|
||||||
|
if( v->HasChildren() )
|
||||||
|
{
|
||||||
|
auto& children = worker.GetZoneChildren( v->Child() );
|
||||||
|
BuildFlameGraph( worker, data.back().children, children );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto& item = data[it->second];
|
||||||
|
item.time += duration;
|
||||||
|
if( v->HasChildren() )
|
||||||
|
{
|
||||||
|
auto& children = worker.GetZoneChildren( v->Child() );
|
||||||
|
BuildFlameGraph( worker, item.children, children );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SortFlameGraph( Vector<FlameGraphItem>& data )
|
||||||
|
{
|
||||||
|
std::sort( data.begin(), data.end(), []( const FlameGraphItem& lhs, const FlameGraphItem& rhs ) { return lhs.time > rhs.time; } );
|
||||||
|
for( auto& v : data ) SortFlameGraph( v.children );
|
||||||
|
}
|
||||||
|
|
||||||
void View::DrawFlameGraph()
|
void View::DrawFlameGraph()
|
||||||
{
|
{
|
||||||
const auto scale = GetScale();
|
const auto scale = GetScale();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user