From 3fce5c1280cda365789706833b3bbb8587cbcbd6 Mon Sep 17 00:00:00 2001 From: Eric Eaton Date: Wed, 9 Jul 2025 23:08:58 -0700 Subject: [PATCH] Use a map to record counter values This removes the limitation of 10 counters. --- profiler/src/profiler/TracyView_ZoneInfo.cpp | 18 +++++------ public/client/TracyRocprof.cpp | 2 -- server/TracyEvent.hpp | 4 +-- server/TracyWorker.cpp | 32 ++++++++++++++------ 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/profiler/src/profiler/TracyView_ZoneInfo.cpp b/profiler/src/profiler/TracyView_ZoneInfo.cpp index 3ea2d4fd..adae1f94 100644 --- a/profiler/src/profiler/TracyView_ZoneInfo.cpp +++ b/profiler/src/profiler/TracyView_ZoneInfo.cpp @@ -1580,16 +1580,15 @@ void View::DrawGpuInfoWindow() } TextFocused( "Query ID:", RealToString( ev.query_id ) ); - for( int i = 0; i < ev.note_count; i++ ) + for( auto& p : ev.notes ) { - auto id = ev.note_ids[i]; - if( ctx->notes.count( id ) ) + if( ctx->notes.count( p.first ) ) { - TextFocused( m_worker.GetString( ctx->notes.at( id ) ), RealToString( ev.note_vals[i] ) ); + TextFocused( m_worker.GetString( ctx->notes.at( p.first ) ), RealToString( p.second ) ); } else { - TextFocused( RealToString( ev.note_ids[i] ), RealToString( ev.note_vals[i] ) ); + TextFocused( RealToString( p.first ), RealToString( p.second ) ); } } @@ -2061,16 +2060,15 @@ void View::ZoneTooltip( const GpuEvent& ev ) } TextFocused( "Query ID:", RealToString( ev.query_id ) ); - for( int i = 0; i < ev.note_count; i++ ) + for( auto& p : ev.notes ) { - auto id = ev.note_ids[i]; - if( ctx->notes.count( id ) ) + if( ctx->notes.count( p.first ) ) { - TextFocused( m_worker.GetString( ctx->notes.at( id ) ), RealToString( ev.note_vals[i] ) ); + TextFocused( m_worker.GetString( ctx->notes.at( p.first ) ), RealToString( p.second ) ); } else { - TextFocused( RealToString( ev.note_ids[i] ), RealToString( ev.note_vals[i] ) ); + TextFocused( RealToString( p.first ), RealToString( p.second ) ); } } diff --git a/public/client/TracyRocprof.cpp b/public/client/TracyRocprof.cpp index adbf30dc..d38b3bba 100644 --- a/public/client/TracyRocprof.cpp +++ b/public/client/TracyRocprof.cpp @@ -366,8 +366,6 @@ void dispatch_callback( rocprofiler_dispatch_counting_service_data_t dispatch_da *config = profile; } -using kernel_symbol_data_t = rocprofiler_callback_tracing_code_object_kernel_symbol_register_data_t; - void tool_callback_tracing_callback( rocprofiler_callback_tracing_record_t record, rocprofiler_user_data_t* user_data, void* callback_data ) { diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 630124c0..6a323c42 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -413,9 +413,7 @@ struct GpuEvent uint64_t _gpuEnd_child2; Int24 callstack; uint16_t query_id; - int64_t note_ids[10]; - double note_vals[10]; - uint8_t note_count; + unordered_flat_map notes; }; enum { GpuEventSize = sizeof( GpuEvent ) }; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index c8809120..7cb98f9a 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -5774,6 +5774,10 @@ void Worker::ProcessGpuZoneBeginImplCommon( GpuEvent* zone, const QueueGpuZoneBe zone->callstack.SetVal( 0 ); zone->SetChild( -1 ); zone->query_id = ev.queryId; + // tracy allocates slab memory without invoking the constructor + new( &zone->notes ) unordered_flat_map(); + // reserve space for all the counters we've been given a name for + zone->notes.reserve( ctx->notes.size() ); uint64_t ztid; if( ctx->thread == 0 ) @@ -6054,10 +6058,7 @@ void Worker::ProcessGpuZoneAnnotation( const QueueGpuZoneAnnotation& ev ) } } auto& zone = timeline[i]; - assert( zone->note_count < 10 ); - zone->note_ids[zone->note_count] = ev.noteId; - zone->note_vals[zone->note_count] = ev.value; - zone->note_count++; + zone->notes.insert_or_assign( ev.noteId, ev.value ); } MemEvent* Worker::ProcessMemAllocImpl( MemData& memdata, const QueueMemAlloc& ev ) @@ -7836,9 +7837,17 @@ void Worker::ReadTimeline( FileRead& f, Vector>& _vec, uint6 zone->SetCpuEnd( refTime ); zone->SetGpuEnd( refGpuTime ); f.Read( zone->query_id ); - f.Read( zone->note_count ); - f.Read( zone->note_ids ); - f.Read( zone->note_vals ); + uint64_t note_count; + f.Read( note_count ); + new( &zone->notes ) unordered_flat_map(); + zone->notes.reserve( note_count ); + for( uint64_t i = 0; i < note_count; i++ ) + { + int64_t id; + double value; + f.Read2( id, value ); + zone->notes[id] = value; + } } while( ++zone != end ); } @@ -8570,9 +8579,12 @@ void Worker::WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime, in WriteTimeOffset( f, refTime, v.CpuEnd() ); WriteTimeOffset( f, refGpuTime, v.GpuEnd() ); f.Write( &v.query_id, sizeof( v.query_id ) ); - f.Write( &v.note_count, sizeof( v.note_count ) ); - f.Write( &v.note_ids, sizeof( v.note_ids ) ); - f.Write( &v.note_vals, sizeof( v.note_vals ) ); + uint64_t note_count = v.notes.size(); + f.Write( ¬e_count, sizeof( note_count ) ); + for ( auto& p : v.notes ) { + f.Write( &p.first, sizeof( p.first ) ); + f.Write( &p.second, sizeof( p.second ) ); + } } }