Use short ptr for CPU zone data.

This commit is contained in:
Bartosz Taudul 2019-11-02 16:17:20 +01:00
parent cb20bf01f9
commit a40bbacb17
5 changed files with 41 additions and 39 deletions

View File

@ -393,9 +393,9 @@ struct ThreadData
{ {
uint64_t id; uint64_t id;
uint64_t count; uint64_t count;
Vector<ZoneEvent*> timeline; Vector<short_ptr<ZoneEvent>> timeline;
Vector<ZoneEvent*> stack; Vector<short_ptr<ZoneEvent>> stack;
Vector<MessageData*> messages; Vector<short_ptr<MessageData>> messages;
uint32_t nextZoneId; uint32_t nextZoneId;
Vector<uint32_t> zoneIdStack; Vector<uint32_t> zoneIdStack;
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS

View File

@ -3004,7 +3004,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
} }
} }
int View::DispatchZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) int View::DispatchZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid )
{ {
const auto ty = ImGui::GetFontSize(); const auto ty = ImGui::GetFontSize();
const auto ostep = ty + 1; const auto ostep = ty + 1;
@ -3021,7 +3021,7 @@ int View::DispatchZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double p
} }
} }
int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) int View::DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid )
{ {
const auto delay = m_worker.GetDelay(); const auto delay = m_worker.GetDelay();
const auto resolution = m_worker.GetResolution(); const auto resolution = m_worker.GetResolution();
@ -3240,7 +3240,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
return maxdepth; return maxdepth;
} }
int View::SkipZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid ) int View::SkipZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int _offset, int depth, float yMin, float yMax, uint64_t tid )
{ {
const auto delay = m_worker.GetDelay(); const auto delay = m_worker.GetDelay();
const auto resolution = m_worker.GetResolution(); const auto resolution = m_worker.GetResolution();
@ -13330,7 +13330,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
for( const auto& thread : m_worker.GetThreadData() ) for( const auto& thread : m_worker.GetThreadData() )
{ {
const ZoneEvent* parent = nullptr; const ZoneEvent* parent = nullptr;
const Vector<ZoneEvent*>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{ {
@ -13350,7 +13350,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone, uint64_t tid ) cons
{ {
const auto thread = m_worker.GetThreadData( tid ); const auto thread = m_worker.GetThreadData( tid );
const ZoneEvent* parent = nullptr; const ZoneEvent* parent = nullptr;
const Vector<ZoneEvent*>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) return nullptr; if( timeline->empty() ) return nullptr;
for(;;) for(;;)
{ {
@ -13393,7 +13393,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
{ {
for( const auto& thread : m_worker.GetThreadData() ) for( const auto& thread : m_worker.GetThreadData() )
{ {
const Vector<ZoneEvent*>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{ {
@ -13477,9 +13477,9 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
} }
if( !td ) return nullptr; if( !td ) return nullptr;
const Vector<ZoneEvent*>* timeline = &td->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &td->timeline;
if( timeline->empty() ) return nullptr; if( timeline->empty() ) return nullptr;
ZoneEvent* ret = nullptr; const ZoneEvent* ret = nullptr;
for(;;) for(;;)
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->Start(); } );

View File

@ -119,9 +119,9 @@ private:
bool DrawZoneFrames( const FrameData& frames ); bool DrawZoneFrames( const FrameData& frames );
void DrawZones(); void DrawZones();
void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset ); void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset );
int DispatchZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int DispatchZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
int DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int DrawZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
int SkipZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int SkipZoneLevel( const Vector<short_ptr<ZoneEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid );
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int DrawGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int DrawGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int SkipGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); int SkipGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
@ -284,7 +284,7 @@ private:
int m_memoryAllocHoverWait = 0; int m_memoryAllocHoverWait = 0;
const FrameData* m_frames; const FrameData* m_frames;
uint32_t m_lockInfoWindow = InvalidId; uint32_t m_lockInfoWindow = InvalidId;
ZoneEvent* m_zoneHover = nullptr; const ZoneEvent* m_zoneHover = nullptr;
int m_frameHover = -1; int m_frameHover = -1;
bool m_messagesScrollBottom; bool m_messagesScrollBottom;
ImGuiTextFilter m_messageFilter; ImGuiTextFilter m_messageFilter;

View File

@ -896,7 +896,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
{ {
f.Read( sz ); f.Read( sz );
m_data.zoneChildren.reserve_exact( sz, m_slab ); m_data.zoneChildren.reserve_exact( sz, m_slab );
memset( m_data.zoneChildren.data(), 0, sizeof( Vector<ZoneEvent*> ) * sz ); memset( m_data.zoneChildren.data(), 0, sizeof( Vector<short_ptr<ZoneEvent>> ) * sz );
} }
int32_t childIdx = 0; int32_t childIdx = 0;
f.Read( sz ); f.Read( sz );
@ -1746,8 +1746,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
m_backgroundDone.store( false, std::memory_order_relaxed ); m_backgroundDone.store( false, std::memory_order_relaxed );
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
m_threadBackground = std::thread( [this, reconstructMemAllocPlot] { m_threadBackground = std::thread( [this, reconstructMemAllocPlot] {
std::function<void(const Vector<ZoneEvent*>&, uint16_t)> ProcessTimeline; std::function<void(Vector<short_ptr<ZoneEvent>>&, uint16_t)> ProcessTimeline;
ProcessTimeline = [this, &ProcessTimeline] ( const Vector<ZoneEvent*>& vec, uint16_t thread ) ProcessTimeline = [this, &ProcessTimeline] ( Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread )
{ {
if( m_shutdown.load( std::memory_order_relaxed ) ) return; if( m_shutdown.load( std::memory_order_relaxed ) ) return;
for( auto& zone : vec ) for( auto& zone : vec )
@ -1755,7 +1755,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
ReadTimelineUpdateStatistics( zone, thread ); ReadTimelineUpdateStatistics( zone, thread );
if( zone->Child() >= 0 ) if( zone->Child() >= 0 )
{ {
ProcessTimeline( GetZoneChildren( zone->Child() ), thread ); ProcessTimeline( GetZoneChildrenMutable( zone->Child() ), thread );
} }
} }
}; };
@ -2840,11 +2840,11 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
back->SetChild( int32_t( m_data.zoneChildren.size() ) ); back->SetChild( int32_t( m_data.zoneChildren.size() ) );
if( m_data.zoneVectorCache.empty() ) if( m_data.zoneVectorCache.empty() )
{ {
m_data.zoneChildren.push_back( Vector<ZoneEvent*>( zone ) ); m_data.zoneChildren.push_back( Vector<short_ptr<ZoneEvent>>( zone ) );
} }
else else
{ {
Vector<ZoneEvent*> vze = std::move( m_data.zoneVectorCache.back_and_pop() ); Vector<short_ptr<ZoneEvent>> vze = std::move( m_data.zoneVectorCache.back_and_pop() );
assert( !vze.empty() ); assert( !vze.empty() );
vze.clear(); vze.clear();
vze.push_back_non_empty( zone ); vze.push_back_non_empty( zone );
@ -3603,9 +3603,9 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
const auto sz = childVec.size(); const auto sz = childVec.size();
if( sz <= 8 * 1024 ) if( sz <= 8 * 1024 )
{ {
Vector<ZoneEvent*> fitVec; Vector<short_ptr<ZoneEvent>> fitVec;
fitVec.reserve_exact( sz, m_slab ); fitVec.reserve_exact( sz, m_slab );
memcpy( fitVec.data(), childVec.data(), sz * sizeof( ZoneEvent* ) ); memcpy( fitVec.data(), childVec.data(), sz * sizeof( short_ptr<ZoneEvent> ) );
fitVec.swap( childVec ); fitVec.swap( childVec );
m_data.zoneVectorCache.push_back( std::move( fitVec ) ); m_data.zoneVectorCache.push_back( std::move( fitVec ) );
} }
@ -4888,8 +4888,8 @@ void Worker::ReadTimelinePre042( FileRead& f, ZoneEvent* zone, uint16_t thread,
{ {
const auto child = m_data.zoneChildren.size(); const auto child = m_data.zoneChildren.size();
zone->SetChild( child ); zone->SetChild( child );
m_data.zoneChildren.push_back( Vector<ZoneEvent*>() ); m_data.zoneChildren.push_back( Vector<short_ptr<ZoneEvent>>() );
Vector<ZoneEvent*> tmp; Vector<short_ptr<ZoneEvent>> tmp;
ReadTimelinePre042( f, tmp, thread, sz, fileVer ); ReadTimelinePre042( f, tmp, thread, sz, fileVer );
m_data.zoneChildren[child] = std::move( tmp ); m_data.zoneChildren[child] = std::move( tmp );
} }
@ -4907,8 +4907,8 @@ void Worker::ReadTimelinePre0510( FileRead& f, ZoneEvent* zone, uint16_t thread,
{ {
const auto child = m_data.zoneChildren.size(); const auto child = m_data.zoneChildren.size();
zone->SetChild( child ); zone->SetChild( child );
m_data.zoneChildren.push_back( Vector<ZoneEvent*>() ); m_data.zoneChildren.push_back( Vector<short_ptr<ZoneEvent>>() );
Vector<ZoneEvent*> tmp; Vector<short_ptr<ZoneEvent>> tmp;
ReadTimelinePre0510( f, tmp, thread, sz, refTime, fileVer ); ReadTimelinePre0510( f, tmp, thread, sz, refTime, fileVer );
m_data.zoneChildren[child] = std::move( tmp ); m_data.zoneChildren[child] = std::move( tmp );
} }
@ -4989,7 +4989,7 @@ void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
#endif #endif
} }
void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int32_t& childIdx ) void Worker::ReadTimeline( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int32_t& childIdx )
{ {
assert( size != 0 ); assert( size != 0 );
vec.reserve_exact( size, m_slab ); vec.reserve_exact( size, m_slab );
@ -5022,7 +5022,7 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread
while( ++zone != zptr ); while( ++zone != zptr );
} }
void Worker::ReadTimelinePre042( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int fileVer ) void Worker::ReadTimelinePre042( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int fileVer )
{ {
assert( fileVer <= FileVersion( 0, 4, 1 ) ); assert( fileVer <= FileVersion( 0, 4, 1 ) );
assert( size != 0 ); assert( size != 0 );
@ -5073,7 +5073,7 @@ void Worker::ReadTimelinePre042( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t
} }
} }
void Worker::ReadTimelinePre0510( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int fileVer ) void Worker::ReadTimelinePre0510( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int fileVer )
{ {
assert( fileVer <= FileVersion( 0, 5, 9 ) ); assert( fileVer <= FileVersion( 0, 5, 9 ) );
assert( size != 0 ); assert( size != 0 );
@ -5531,7 +5531,7 @@ void Worker::Write( FileWrite& f )
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );
for( auto& v : thread->messages ) for( auto& v : thread->messages )
{ {
auto ptr = uint64_t( v ); auto ptr = uint64_t( (MessageData*)v );
f.Write( &ptr, sizeof( ptr ) ); f.Write( &ptr, sizeof( ptr ) );
} }
} }
@ -5713,7 +5713,7 @@ void Worker::Write( FileWrite& f )
} }
} }
void Worker::WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t& refTime ) void Worker::WriteTimeline( FileWrite& f, const Vector<short_ptr<ZoneEvent>>& vec, int64_t& refTime )
{ {
uint64_t sz = vec.size(); uint64_t sz = vec.size();
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );

View File

@ -198,10 +198,10 @@ private:
ThreadCompress localThreadCompress; ThreadCompress localThreadCompress;
ThreadCompress externalThreadCompress; ThreadCompress externalThreadCompress;
Vector<Vector<ZoneEvent*>> zoneChildren; Vector<Vector<short_ptr<ZoneEvent>>> zoneChildren;
Vector<Vector<short_ptr<GpuEvent>>> gpuChildren; Vector<Vector<short_ptr<GpuEvent>>> gpuChildren;
Vector<Vector<ZoneEvent*>> zoneVectorCache; Vector<Vector<short_ptr<ZoneEvent>>> zoneVectorCache;
Vector<FrameImage*> frameImage; Vector<FrameImage*> frameImage;
Vector<StringRef> appInfo; Vector<StringRef> appInfo;
@ -364,7 +364,7 @@ public:
const char* GetZoneName( const GpuEvent& ev ) const; const char* GetZoneName( const GpuEvent& ev ) const;
const char* GetZoneName( const GpuEvent& ev, const SourceLocation& srcloc ) const; const char* GetZoneName( const GpuEvent& ev, const SourceLocation& srcloc ) const;
tracy_force_inline const Vector<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]; }
std::vector<int16_t> GetMatchingSourceLocation( const char* query, bool ignoreCase ) const; std::vector<int16_t> GetMatchingSourceLocation( const char* query, bool ignoreCase ) const;
@ -553,6 +553,8 @@ private:
StringLocation StoreString( char* str, size_t sz ); StringLocation StoreString( char* str, size_t sz );
const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread ); const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread );
tracy_force_inline Vector<short_ptr<ZoneEvent>>& GetZoneChildrenMutable( int32_t idx ) { return m_data.zoneChildren[idx]; }
tracy_force_inline void ReadTimeline( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime, int32_t& childIdx ); tracy_force_inline void ReadTimeline( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime, int32_t& childIdx );
tracy_force_inline void ReadTimelinePre042( FileRead& f, ZoneEvent* zone, uint16_t thread, int fileVer ); tracy_force_inline void ReadTimelinePre042( FileRead& f, ZoneEvent* zone, uint16_t thread, int fileVer );
tracy_force_inline void ReadTimelinePre0510( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime, int fileVer ); tracy_force_inline void ReadTimelinePre0510( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime, int fileVer );
@ -561,13 +563,13 @@ private:
tracy_force_inline void ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread ); tracy_force_inline void ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread );
void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int32_t& childIdx ); void ReadTimeline( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int32_t& childIdx );
void ReadTimelinePre042( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int fileVer ); void ReadTimelinePre042( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int fileVer );
void ReadTimelinePre0510( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int fileVer ); void ReadTimelinePre0510( FileRead& f, Vector<short_ptr<ZoneEvent>>& vec, uint16_t thread, uint64_t size, int64_t& refTime, int fileVer );
void ReadTimeline( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int32_t& childIdx ); void ReadTimeline( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int32_t& childIdx );
void ReadTimelinePre0510( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int fileVer ); void ReadTimelinePre0510( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int fileVer );
void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t& refTime ); void WriteTimeline( FileWrite& f, const Vector<short_ptr<ZoneEvent>>& vec, int64_t& refTime );
void WriteTimeline( FileWrite& f, const Vector<short_ptr<GpuEvent>>& vec, int64_t& refTime, int64_t& refGpuTime ); void WriteTimeline( FileWrite& f, const Vector<short_ptr<GpuEvent>>& vec, int64_t& refTime, int64_t& refGpuTime );
int64_t TscTime( int64_t tsc ) { return int64_t( tsc * m_timerMul ); } int64_t TscTime( int64_t tsc ) { return int64_t( tsc * m_timerMul ); }