Support call stacks longer than 255 entries.

This commit is contained in:
Bartosz Taudul 2020-03-28 18:04:33 +01:00
parent 9b8eb69886
commit 48e4d33bea
6 changed files with 51 additions and 29 deletions

View File

@ -23,7 +23,7 @@ template<typename T>
class VarArray class VarArray
{ {
public: public:
VarArray( uint8_t size, const T* data ) VarArray( uint16_t size, const T* data )
: m_size( size ) : m_size( size )
, m_ptr( data ) , m_ptr( data )
{ {
@ -39,7 +39,7 @@ public:
tracy_force_inline uint32_t get_hash() const { return m_hash; } tracy_force_inline uint32_t get_hash() const { return m_hash; }
tracy_force_inline bool empty() const { return m_size == 0; } tracy_force_inline bool empty() const { return m_size == 0; }
tracy_force_inline uint8_t size() const { return m_size; } tracy_force_inline uint16_t size() const { return m_size; }
tracy_force_inline const T* data() const { return m_ptr; }; tracy_force_inline const T* data() const { return m_ptr; };
@ -54,7 +54,7 @@ public:
private: private:
tracy_force_inline void CalcHash(); tracy_force_inline void CalcHash();
uint8_t m_size; uint16_t m_size;
uint32_t m_hash; uint32_t m_hash;
const short_ptr<T> m_ptr; const short_ptr<T> m_ptr;
}; };

View File

@ -7,7 +7,7 @@ namespace Version
{ {
enum { Major = 0 }; enum { Major = 0 };
enum { Minor = 6 }; enum { Minor = 6 };
enum { Patch = 7 }; enum { Patch = 8 };
} }
} }

View File

@ -5959,8 +5959,8 @@ void DrawZoneTrace( T zone, const std::vector<T>& trace, const Worker& worker, B
auto& prevCs = worker.GetCallstack( pcv ); auto& prevCs = worker.GetCallstack( pcv );
auto& currCs = worker.GetCallstack( ccv ); auto& currCs = worker.GetCallstack( ccv );
const auto psz = int8_t( prevCs.size() ); const auto psz = int( prevCs.size() );
int8_t idx; int idx;
for( idx=0; idx<psz; idx++ ) for( idx=0; idx<psz; idx++ )
{ {
auto pf = prevCs[idx]; auto pf = prevCs[idx];
@ -5976,7 +5976,7 @@ void DrawZoneTrace( T zone, const std::vector<T>& trace, const Worker& worker, B
} }
if( found ) break; if( found ) break;
} }
for( int8_t j=1; j<idx; j++ ) for( int j=1; j<idx; j++ )
{ {
auto frameData = worker.GetCallstackFrame( prevCs[j] ); auto frameData = worker.GetCallstackFrame( prevCs[j] );
auto frame = frameData->data + frameData->size - 1; auto frame = frameData->data + frameData->size - 1;
@ -6034,7 +6034,7 @@ void DrawZoneTrace( T zone, const std::vector<T>& trace, const Worker& worker, B
{ {
auto& cs = worker.GetCallstack( lcv ); auto& cs = worker.GetCallstack( lcv );
const auto csz = cs.size(); const auto csz = cs.size();
for( uint8_t i=1; i<csz; i++ ) for( uint16_t i=1; i<csz; i++ )
{ {
auto frameData = worker.GetCallstackFrame( cs[i] ); auto frameData = worker.GetCallstackFrame( cs[i] );
auto frame = frameData->data + frameData->size - 1; auto frame = frameData->data + frameData->size - 1;
@ -14083,7 +14083,7 @@ unordered_flat_map<uint64_t, CallstackFrameTree> View::GetCallstackFrameTreeTopD
treePtr->alloc += path.second.mem; treePtr->alloc += path.second.mem;
treePtr->callstacks.emplace( path.first ); treePtr->callstacks.emplace( path.first );
for( int i = 1; i < cs.size(); i++ ) for( uint16_t i = 1; i < cs.size(); i++ )
{ {
treePtr = GetFrameTreeItemGroup( treePtr->children, cs[i], m_worker ); treePtr = GetFrameTreeItemGroup( treePtr->children, cs[i], m_worker );
if( !treePtr ) break; if( !treePtr ) break;
@ -14106,7 +14106,7 @@ unordered_flat_map<uint64_t, CallstackFrameTree> View::GetCallstackFrameTreeTopD
treePtr->alloc += path.second.mem; treePtr->alloc += path.second.mem;
treePtr->callstacks.emplace( path.first ); treePtr->callstacks.emplace( path.first );
for( int i = 1; i < cs.size(); i++ ) for( uint16_t i = 1; i < cs.size(); i++ )
{ {
treePtr = GetFrameTreeItemNoGroup( treePtr->children, cs[i], m_worker ); treePtr = GetFrameTreeItemNoGroup( treePtr->children, cs[i], m_worker );
treePtr->count += path.second.cnt; treePtr->count += path.second.cnt;
@ -15597,12 +15597,12 @@ void View::SmallCallstackButton( const char* name, uint32_t callstack, int& idx,
} }
} }
void View::DrawCallstackCalls( uint32_t callstack, uint8_t limit ) const void View::DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const
{ {
const auto& csdata = m_worker.GetCallstack( callstack ); const auto& csdata = m_worker.GetCallstack( callstack );
const auto cssz = std::min( csdata.size(), limit ); const auto cssz = std::min( csdata.size(), limit );
bool first = true; bool first = true;
for( uint8_t i=0; i<cssz; i++ ) for( uint16_t i=0; i<cssz; i++ )
{ {
const auto frameData = m_worker.GetCallstackFrame( csdata[i] ); const auto frameData = m_worker.GetCallstackFrame( csdata[i] );
if( !frameData ) break; if( !frameData ) break;

View File

@ -234,7 +234,7 @@ private:
const char* GetPlotName( const PlotData* plot ) const; const char* GetPlotName( const PlotData* plot ) const;
void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true ); void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true );
void DrawCallstackCalls( uint32_t callstack, uint8_t limit ) const; void DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const;
void SetViewToLastFrames(); void SetViewToLastFrames();
int64_t GetZoneChildTime( const ZoneEvent& zone ); int64_t GetZoneChildTime( const ZoneEvent& zone );
int64_t GetZoneChildTime( const GpuEvent& zone ); int64_t GetZoneChildTime( const GpuEvent& zone );

View File

@ -1332,6 +1332,27 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
s_loadProgress.progress.store( LoadProgress::CallStacks, std::memory_order_relaxed ); s_loadProgress.progress.store( LoadProgress::CallStacks, std::memory_order_relaxed );
f.Read( sz ); f.Read( sz );
m_data.callstackPayload.reserve( sz ); m_data.callstackPayload.reserve( sz );
if( fileVer >= FileVersion( 0, 6, 8 ) )
{
for( uint64_t i=0; i<sz; i++ )
{
uint16_t csz;
f.Read( csz );
const auto memsize = sizeof( VarArray<CallstackFrameId> ) + csz * sizeof( CallstackFrameId );
auto mem = (char*)m_slab.AllocRaw( memsize );
auto data = (CallstackFrameId*)mem;
f.Read( data, csz * sizeof( CallstackFrameId ) );
auto arr = (VarArray<CallstackFrameId>*)( mem + csz * sizeof( CallstackFrameId ) );
new(arr) VarArray<CallstackFrameId>( csz, data );
m_data.callstackPayload.push_back_no_space_check( arr );
}
}
else
{
for( uint64_t i=0; i<sz; i++ ) for( uint64_t i=0; i<sz; i++ )
{ {
uint8_t csz; uint8_t csz;
@ -1348,6 +1369,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
m_data.callstackPayload.push_back_no_space_check( arr ); m_data.callstackPayload.push_back_no_space_check( arr );
} }
}
if( fileVer >= FileVersion( 0, 6, 5 ) ) if( fileVer >= FileVersion( 0, 6, 5 ) )
{ {
@ -5720,7 +5742,7 @@ void Worker::UpdateSampleStatistics( uint32_t callstack, uint32_t count, bool ca
const auto cssz = cs.size(); const auto cssz = cs.size();
auto frames = (const CallstackFrameData**)alloca( cssz * sizeof( CallstackFrameData* ) ); auto frames = (const CallstackFrameData**)alloca( cssz * sizeof( CallstackFrameData* ) );
for( uint8_t i=0; i<cssz; i++ ) for( uint16_t i=0; i<cssz; i++ )
{ {
auto frame = GetCallstackFrame( cs[i] ); auto frame = GetCallstackFrame( cs[i] );
if( !frame ) if( !frame )
@ -5764,7 +5786,7 @@ void Worker::UpdateSampleStatisticsPostponed( decltype(Worker::DataBlock::postpo
const auto cssz = cs.size(); const auto cssz = cs.size();
auto frames = (const CallstackFrameData**)alloca( cssz * sizeof( CallstackFrameData* ) ); auto frames = (const CallstackFrameData**)alloca( cssz * sizeof( CallstackFrameData* ) );
for( uint8_t i=0; i<cssz; i++ ) for( uint16_t i=0; i<cssz; i++ )
{ {
auto frame = GetCallstackFrame( cs[i] ); auto frame = GetCallstackFrame( cs[i] );
if( !frame ) if( !frame )
@ -5779,7 +5801,7 @@ void Worker::UpdateSampleStatisticsPostponed( decltype(Worker::DataBlock::postpo
it = m_data.postponedSamples.erase( it ); it = m_data.postponedSamples.erase( it );
} }
void Worker::UpdateSampleStatisticsImpl( const CallstackFrameData** frames, uint8_t framesCount, uint32_t count, const VarArray<CallstackFrameId>& cs ) void Worker::UpdateSampleStatisticsImpl( const CallstackFrameData** frames, uint16_t framesCount, uint32_t count, const VarArray<CallstackFrameId>& cs )
{ {
const auto fexcl = frames[0]; const auto fexcl = frames[0];
const auto fxsz = fexcl->size; const auto fxsz = fexcl->size;
@ -5794,7 +5816,7 @@ void Worker::UpdateSampleStatisticsImpl( const CallstackFrameData** frames, uint
if( sym == m_data.symbolStats.end() ) sym = m_data.symbolStats.emplace( frame.symAddr, SymbolStats { 0, 0, unordered_flat_map<uint32_t, uint32_t>() } ).first; if( sym == m_data.symbolStats.end() ) sym = m_data.symbolStats.emplace( frame.symAddr, SymbolStats { 0, 0, unordered_flat_map<uint32_t, uint32_t>() } ).first;
sym->second.incl += count; sym->second.incl += count;
} }
for( uint8_t c=1; c<framesCount; c++ ) for( uint16_t c=1; c<framesCount; c++ )
{ {
const auto fincl = frames[c]; const auto fincl = frames[c];
const auto fsz = fincl->size; const auto fsz = fincl->size;
@ -6591,7 +6613,7 @@ void Worker::Write( FileWrite& f )
for( size_t i=1; i<=sz; i++ ) for( size_t i=1; i<=sz; i++ )
{ {
auto cs = m_data.callstackPayload[i]; auto cs = m_data.callstackPayload[i];
uint8_t csz = cs->size(); uint16_t csz = cs->size();
f.Write( &csz, sizeof( csz ) ); f.Write( &csz, sizeof( csz ) );
f.Write( cs->data(), sizeof( CallstackFrameId ) * csz ); f.Write( cs->data(), sizeof( CallstackFrameId ) * csz );
} }

View File

@ -697,7 +697,7 @@ private:
void ReconstructContextSwitchUsage(); void ReconstructContextSwitchUsage();
void UpdateSampleStatistics( uint32_t callstack, uint32_t count, bool canPostpone ); void UpdateSampleStatistics( uint32_t callstack, uint32_t count, bool canPostpone );
void UpdateSampleStatisticsPostponed( decltype(Worker::DataBlock::postponedSamples.begin())& it ); void UpdateSampleStatisticsPostponed( decltype(Worker::DataBlock::postponedSamples.begin())& it );
void UpdateSampleStatisticsImpl( const CallstackFrameData** frames, uint8_t framesCount, uint32_t count, const VarArray<CallstackFrameId>& cs ); void UpdateSampleStatisticsImpl( const CallstackFrameData** frames, uint16_t framesCount, uint32_t count, const VarArray<CallstackFrameId>& cs );
#endif #endif
tracy_force_inline int64_t ReadTimeline( FileRead& f, ZoneEvent* zone, int64_t refTime, int32_t& childIdx ); tracy_force_inline int64_t ReadTimeline( FileRead& f, ZoneEvent* zone, int64_t refTime, int32_t& childIdx );