Build ghost zones tree.

This commit is contained in:
Bartosz Taudul 2020-03-10 21:06:38 +01:00
parent 693db74380
commit 452341059b
3 changed files with 91 additions and 1 deletions

View File

@ -500,6 +500,16 @@ struct FrameImage
enum { FrameImageSize = sizeof( FrameImage ) }; enum { FrameImageSize = sizeof( FrameImage ) };
struct GhostZone
{
Int48 start, end;
CallstackFrameId frame;
int32_t child;
};
enum { GhostZoneSize = sizeof( GhostZone ) };
#pragma pack() #pragma pack()
@ -514,6 +524,7 @@ struct ThreadData
Vector<uint32_t> zoneIdStack; Vector<uint32_t> zoneIdStack;
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
Vector<int64_t> childTimeStack; Vector<int64_t> childTimeStack;
Vector<GhostZone> ghostZones;
#endif #endif
Vector<SampleData> samples; Vector<SampleData> samples;
}; };

View File

@ -242,6 +242,7 @@ Worker::Worker( const char* addr, int port )
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
m_data.sourceLocationZonesReady = true; m_data.sourceLocationZonesReady = true;
m_data.callstackSamplesReady = true; m_data.callstackSamplesReady = true;
m_data.ghostZonesReady = true;
m_data.ctxUsageReady = true; m_data.ctxUsageReady = true;
#endif #endif
@ -1743,10 +1744,72 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
for( auto& v : counts ) UpdateSampleStatistics( v.first, v.second, false ); for( auto& v : counts ) UpdateSampleStatistics( v.first, v.second, false );
} }
{
std::lock_guard<std::shared_mutex> lock( m_data.lock ); std::lock_guard<std::shared_mutex> lock( m_data.lock );
m_data.callstackSamplesReady = true; m_data.callstackSamplesReady = true;
} }
uint32_t gcnt = 0;
for( auto& t : m_data.threads )
{
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
for( auto& sd : t->samples )
{
const auto& cs = GetCallstack( sd.callstack.Val() );
const auto time = sd.time.Val();
auto vec = &t->ghostZones;
auto idx = cs.size() - 1;
do
{
auto& entry = cs[idx];
if( vec->empty() )
{
gcnt++;
auto& zone = vec->push_next();
zone.start.SetVal( time );
zone.end.SetVal( time + m_samplingPeriod );
zone.frame = entry;
zone.child = -1;
}
else if( vec->back().frame == entry )
{
auto& zone = vec->back();
zone.end.SetVal( time + m_samplingPeriod );
}
else
{
gcnt++;
vec->back().end.SetVal( time );
auto& zone = vec->push_next();
zone.start.SetVal( time );
zone.end.SetVal( time + m_samplingPeriod );
zone.frame = entry;
zone.child = -1;
}
if( idx > 0 )
{
auto& zone = vec->back();
if( zone.child < 0 )
{
zone.child = m_data.ghostChildren.size();
vec = &m_data.ghostChildren.push_next();
}
else
{
vec = &m_data.ghostChildren[zone.child];
}
}
}
while( idx-- > 0 );
}
}
std::lock_guard<std::shared_mutex> lock( m_data.lock );
m_data.ghostZonesReady = true;
m_data.ghostCnt = gcnt;
}
m_backgroundDone.store( true, std::memory_order_relaxed ); m_backgroundDone.store( true, std::memory_order_relaxed );
} ); } );
#else #else
@ -1781,6 +1844,7 @@ Worker::~Worker()
v->samples.~Vector(); v->samples.~Vector();
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
v->childTimeStack.~Vector(); v->childTimeStack.~Vector();
v->ghostZones.~Vector();
#endif #endif
} }
for( auto& v : m_data.gpuData ) for( auto& v : m_data.gpuData )
@ -1803,6 +1867,12 @@ Worker::~Worker()
{ {
v.second->~LockMap(); v.second->~LockMap();
} }
#ifndef TRACY_NO_STATISTICS
for( auto& v : m_data.ghostChildren )
{
v.~Vector();
}
#endif
} }
uint64_t Worker::GetLockCount() const uint64_t Worker::GetLockCount() const

View File

@ -196,6 +196,7 @@ private:
uint64_t zonesCnt = 0; uint64_t zonesCnt = 0;
uint64_t gpuCnt = 0; uint64_t gpuCnt = 0;
uint64_t samplesCnt = 0; uint64_t samplesCnt = 0;
uint64_t ghostCnt = 0;
int64_t baseTime = 0; int64_t baseTime = 0;
int64_t lastTime = 0; int64_t lastTime = 0;
uint64_t frameOffset = 0; uint64_t frameOffset = 0;
@ -232,6 +233,7 @@ private:
unordered_flat_map<uint32_t, uint32_t> postponedSamples; unordered_flat_map<uint32_t, uint32_t> postponedSamples;
bool newFramesWereReceived = false; bool newFramesWereReceived = false;
bool callstackSamplesReady = false; bool callstackSamplesReady = false;
bool ghostZonesReady = false;
#endif #endif
unordered_flat_map<uint32_t, LockMap*> lockMap; unordered_flat_map<uint32_t, LockMap*> lockMap;
@ -241,6 +243,9 @@ private:
Vector<Vector<short_ptr<ZoneEvent>>> zoneChildren; Vector<Vector<short_ptr<ZoneEvent>>> zoneChildren;
Vector<Vector<short_ptr<GpuEvent>>> gpuChildren; Vector<Vector<short_ptr<GpuEvent>>> gpuChildren;
#ifndef TRACY_NO_STATISTICS
Vector<Vector<GhostZone>> ghostChildren;
#endif
Vector<Vector<short_ptr<ZoneEvent>>> zoneVectorCache; Vector<Vector<short_ptr<ZoneEvent>>> zoneVectorCache;
@ -368,6 +373,7 @@ public:
uint64_t GetCallstackFrameCount() const { return m_data.callstackFrameMap.size(); } uint64_t GetCallstackFrameCount() const { return m_data.callstackFrameMap.size(); }
uint64_t GetCallstackSampleCount() const { return m_data.samplesCnt; } uint64_t GetCallstackSampleCount() const { return m_data.samplesCnt; }
uint64_t GetSymbolsCount() const { return m_data.symbolMap.size(); } uint64_t GetSymbolsCount() const { return m_data.symbolMap.size(); }
uint64_t GetGhostZonesCount() const { return m_data.ghostCnt; }
uint32_t GetFrameImageCount() const { return (uint32_t)m_data.frameImage.size(); } uint32_t GetFrameImageCount() const { return (uint32_t)m_data.frameImage.size(); }
uint64_t GetStringsCount() const { return m_data.strings.size() + m_data.stringData.size(); } uint64_t GetStringsCount() const { return m_data.strings.size() + m_data.stringData.size(); }
uint64_t GetFrameOffset() const { return m_data.frameOffset; } uint64_t GetFrameOffset() const { return m_data.frameOffset; }
@ -437,6 +443,9 @@ public:
tracy_force_inline const Vector<short_ptr<ZoneEvent>>& GetZoneChildren( int32_t idx ) const { return m_data.zoneChildren[idx]; } tracy_force_inline const Vector<short_ptr<ZoneEvent>>& GetZoneChildren( int32_t idx ) const { return m_data.zoneChildren[idx]; }
tracy_force_inline const Vector<short_ptr<GpuEvent>>& GetGpuChildren( int32_t idx ) const { return m_data.gpuChildren[idx]; } tracy_force_inline const Vector<short_ptr<GpuEvent>>& GetGpuChildren( int32_t idx ) const { return m_data.gpuChildren[idx]; }
#ifndef TRACY_NO_STATISTICS
tracy_force_inline const Vector<GhostZone>& GetGhostChildren( int32_t idx ) const { return m_data.ghostChildren[idx]; }
#endif
tracy_force_inline const bool HasZoneExtra( const ZoneEvent& ev ) const { return ev.extra != 0; } tracy_force_inline const bool HasZoneExtra( const ZoneEvent& ev ) const { return ev.extra != 0; }
tracy_force_inline const ZoneExtra& GetZoneExtra( const ZoneEvent& ev ) const { return m_data.zoneExtra[ev.extra]; } tracy_force_inline const ZoneExtra& GetZoneExtra( const ZoneEvent& ev ) const { return m_data.zoneExtra[ev.extra]; }