From a754db16f8046d63030fe140bf5c809cd0ef7de5 Mon Sep 17 00:00:00 2001 From: Eric Eaton Date: Wed, 2 Jul 2025 15:24:46 -0700 Subject: [PATCH] Show counter name in GUI --- profiler/src/profiler/TracyView_ZoneInfo.cpp | 14 +++++++-- public/client/TracyProfiler.cpp | 18 ++++++++++++ public/client/TracyRocprof.cpp | 14 ++++++++- public/common/TracyQueue.hpp | 16 +++++++++++ server/TracyEvent.hpp | 1 + server/TracyWorker.cpp | 30 ++++++++++++++++++++ server/TracyWorker.hpp | 1 + 7 files changed, 91 insertions(+), 3 deletions(-) diff --git a/profiler/src/profiler/TracyView_ZoneInfo.cpp b/profiler/src/profiler/TracyView_ZoneInfo.cpp index fd70b831..98af9e63 100644 --- a/profiler/src/profiler/TracyView_ZoneInfo.cpp +++ b/profiler/src/profiler/TracyView_ZoneInfo.cpp @@ -1581,7 +1581,12 @@ void View::DrawGpuInfoWindow() TextFocused( "Query ID:", RealToString(ev.query_id) ); for (int i = 0; i < ev.note_count; i++ ) { - TextFocused( RealToString(ev.note_ids[i]), RealToString(ev.note_vals[i]) ); + auto id = ev.note_ids[i]; + if (ctx->notes.count(id)) { + TextFocused( m_worker.GetString( ctx->notes.at(id) ), RealToString(ev.note_vals[i]) ); + } else { + TextFocused( RealToString(ev.note_ids[i]), RealToString(ev.note_vals[i]) ); + } } ImGui::Separator(); @@ -2053,7 +2058,12 @@ void View::ZoneTooltip( const GpuEvent& ev ) TextFocused( "Query ID:", RealToString(ev.query_id) ); for (int i = 0; i < ev.note_count; i++ ) { - TextFocused( RealToString(ev.note_ids[i]), RealToString(ev.note_vals[i]) ); + auto id = ev.note_ids[i]; + if (ctx->notes.count(id)) { + TextFocused( m_worker.GetString( ctx->notes.at(id) ), RealToString(ev.note_vals[i]) ); + } else { + TextFocused( RealToString(ev.note_ids[i]), RealToString(ev.note_vals[i]) ); + } } ImGui::EndTooltip(); diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index e2e0747b..9848a639 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -2358,6 +2358,10 @@ static void FreeAssociatedMemory( const QueueItem& item ) tracy_free( (void*)ptr ); break; #endif + case QueueType::GpuAnnotationName: + ptr = MemRead( &item.gpuAnnotationNameFat.ptr ); + tracy_free( (void*)ptr ); + break; #ifdef TRACY_ON_DEMAND case QueueType::MessageAppInfo: case QueueType::GpuContextName: @@ -2573,6 +2577,12 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) tracy_free_fast( (void*)ptr ); #endif break; + case QueueType::GpuAnnotationName: + ptr = MemRead( &item->gpuAnnotationNameFat.ptr ); + size = MemRead( &item->gpuAnnotationNameFat.size ); + SendSingleString( (const char*)ptr, size ); + tracy_free_fast( (void*)ptr ); + break; case QueueType::PlotDataInt: case QueueType::PlotDataFloat: case QueueType::PlotDataDouble: @@ -2931,6 +2941,14 @@ Profiler::DequeueStatus Profiler::DequeueSerial() #endif break; } + case QueueType::GpuAnnotationName: + { + ptr = MemRead( &item->gpuAnnotationNameFat.ptr ); + uint16_t size = MemRead( &item->gpuAnnotationNameFat.size ); + SendSingleString( (const char*)ptr, size ); + tracy_free_fast( (void*)ptr ); + break; + } #ifdef TRACY_FIBERS case QueueType::ZoneBegin: case QueueType::ZoneBeginCallstack: diff --git a/public/client/TracyRocprof.cpp b/public/client/TracyRocprof.cpp index b225249c..6caf220b 100644 --- a/public/client/TracyRocprof.cpp +++ b/public/client/TracyRocprof.cpp @@ -263,7 +263,6 @@ record_callback(rocprofiler_dispatch_counting_service_data_t dispatch_data, ROCPROFILER_CALL(rocprofiler_query_record_counter_id(record_data[0].id, &_counter_id), "query record counter id"); tracy::MemWrite(&item->zoneAnnotation.noteId, _counter_id.handle); - fprintf(stderr, "note %lu\n", _counter_id.handle); tracy::MemWrite(&item->zoneAnnotation.queryId, query_id); tracy::MemWrite(&item->zoneAnnotation.value, sum); tracy::MemWrite(&item->zoneAnnotation.context, data->context_id); @@ -351,6 +350,19 @@ dispatch_callback(rocprofiler_dispatch_counting_service_data_t dispatch_data, { std::clog << "Counter: " << counter.handle << " " << info.name << "\n"; collect_counters.push_back(counter); + + size_t name_length = strlen(info.name); + char* cloned_name = (char*)tracy::tracy_malloc(name_length); + memcpy(cloned_name, info.name, name_length); + { + auto* item = tracy::Profiler::QueueSerial(); + tracy::MemWrite(&item->hdr.type, tracy::QueueType::GpuAnnotationName); + tracy::MemWrite(&item->gpuAnnotationNameFat.context, data->context_id); + tracy::MemWrite(&item->gpuAnnotationNameFat.noteId, counter.handle); + tracy::MemWrite(&item->gpuAnnotationNameFat.ptr, (uint64_t)cloned_name); + tracy::MemWrite(&item->gpuAnnotationNameFat.size, name_length); + tracy::Profiler::QueueSerialFinish(); + } } } diff --git a/public/common/TracyQueue.hpp b/public/common/TracyQueue.hpp index 12ee4cf9..c8644053 100644 --- a/public/common/TracyQueue.hpp +++ b/public/common/TracyQueue.hpp @@ -61,6 +61,7 @@ enum class QueueType : uint8_t ThreadWakeup, GpuTime, GpuContextName, + GpuAnnotationName, CallstackFrameSize, SymbolInformation, ExternalNameMetadata, @@ -488,6 +489,18 @@ struct QueueGpuContextNameFat : public QueueGpuContextName uint16_t size; }; +struct QueueGpuAnnotationName +{ + int64_t noteId; + uint8_t context; +}; + +struct QueueGpuAnnotationNameFat : public QueueGpuAnnotationName +{ + uint64_t ptr; + uint16_t size; +}; + struct QueueMemNamePayload { uint64_t name; @@ -765,6 +778,8 @@ struct QueueItem QueueGpuTimeSync gpuTimeSync; QueueGpuContextName gpuContextName; QueueGpuContextNameFat gpuContextNameFat; + QueueGpuAnnotationName gpuAnnotationName; + QueueGpuAnnotationNameFat gpuAnnotationNameFat; QueueMemAlloc memAlloc; QueueMemFree memFree; QueueMemDiscard memDiscard; @@ -859,6 +874,7 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueThreadWakeup ), sizeof( QueueHeader ) + sizeof( QueueGpuTime ), sizeof( QueueHeader ) + sizeof( QueueGpuContextName ), + sizeof( QueueHeader ) + sizeof( QueueGpuAnnotationName ), sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ), sizeof( QueueHeader ) + sizeof( QueueSymbolInformation ), sizeof( QueueHeader ), // ExternalNameMetadata - not for wire transfer diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 6e2949a4..630124c0 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -778,6 +778,7 @@ struct GpuCtxData uint32_t overflowMul; StringIdx name; unordered_flat_map threadData; + unordered_flat_map notes; short_ptr query[64*1024]; }; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 94e50fad..72595ece 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1105,6 +1105,15 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks, bool allow auto ctx = m_slab.AllocInit(); uint8_t calibration; f.Read7( ctx->thread, calibration, ctx->count, ctx->period, ctx->type, ctx->name, ctx->overflow ); + uint64_t notesz; + f.Read( notesz ); + for ( uint64_t i=0; inotes)::key_type key; + decltype(ctx->notes)::mapped_type value; + f.Read2( key, value ); + ctx->notes[key] = value; + } ctx->hasCalibration = calibration; ctx->hasPeriod = ctx->period != 1.f; m_data.gpuCnt += ctx->count; @@ -4622,6 +4631,9 @@ bool Worker::Process( const QueueItem& ev ) case QueueType::GpuContextName: ProcessGpuContextName( ev.gpuContextName ); break; + case QueueType::GpuAnnotationName: + ProcessGpuAnnotationName( ev.gpuAnnotationName ); + break; case QueueType::GpuZoneAnnotation: ProcessGpuZoneAnnotation( ev.zoneAnnotation ); break; @@ -6017,6 +6029,14 @@ void Worker::ProcessGpuContextName( const QueueGpuContextName& ev ) ctx->name = StringIdx( idx ); } +void Worker::ProcessGpuAnnotationName( const QueueGpuAnnotationName& ev ) +{ + auto ctx = m_gpuCtxMap[ev.context]; + assert( ctx ); + const auto idx = GetSingleStringIdx(); + ctx->notes[ev.noteId] = StringIdx( idx ); +} + void Worker::ProcessGpuZoneAnnotation( const QueueGpuZoneAnnotation& ev ) { auto ctx = m_gpuCtxMap[ev.context]; @@ -6031,6 +6051,9 @@ void Worker::ProcessGpuZoneAnnotation( const QueueGpuZoneAnnotation& ev ) zone->note_ids[zone->note_count] = ev.noteId; zone->note_vals[zone->note_count] = ev.value; zone->note_count++; + + if (ctx->notes.contains(ev.noteId)) + fprintf(stderr, "%s: %f\n", GetString(ctx->notes[ev.noteId]), ev.value); } MemEvent* Worker::ProcessMemAllocImpl( MemData& memdata, const QueueMemAlloc& ev ) @@ -8149,6 +8172,13 @@ void Worker::Write( FileWrite& f, bool fiDict ) f.Write( &ctx->type, sizeof( ctx->type ) ); f.Write( &ctx->name, sizeof( ctx->name ) ); f.Write( &ctx->overflow, sizeof( ctx->overflow ) ); + sz = ctx->notes.size(); + f.Write( &sz, sizeof( sz ) ); + for( auto& p : ctx->notes ) + { + f.Write( &p.first, sizeof( p.first ) ); + f.Write( &p.second, sizeof( p.second ) ); + } sz = ctx->threadData.size(); f.Write( &sz, sizeof( sz ) ); for( auto& td : ctx->threadData ) diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index fd1dc8ee..ff4b16af 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -740,6 +740,7 @@ private: tracy_force_inline void ProcessGpuCalibration( const QueueGpuCalibration& ev ); tracy_force_inline void ProcessGpuTimeSync( const QueueGpuTimeSync& ev ); tracy_force_inline void ProcessGpuContextName( const QueueGpuContextName& ev ); + tracy_force_inline void ProcessGpuAnnotationName( const QueueGpuAnnotationName& ev ); tracy_force_inline void ProcessGpuZoneAnnotation( const QueueGpuZoneAnnotation& ev ); tracy_force_inline MemEvent* ProcessMemAlloc( const QueueMemAlloc& ev ); tracy_force_inline MemEvent* ProcessMemAllocNamed( const QueueMemAlloc& ev );