From 8c1c395cec97f39b40f34d719d4cad88cd76a08a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 28 Sep 2017 19:28:24 +0200 Subject: [PATCH] Allow sending custom zone names. --- client/Tracy.hpp | 2 ++ client/TracyProfiler.cpp | 9 +++++++++ client/TracyProfiler.hpp | 1 + client/TracyScoped.hpp | 5 +++++ common/TracyQueue.hpp | 8 ++++++++ server/TracyEvent.hpp | 1 + server/TracyView.cpp | 11 +++++++++++ server/TracyView.hpp | 1 + 8 files changed, 38 insertions(+) diff --git a/client/Tracy.hpp b/client/Tracy.hpp index cfb317ea..8c2d4283 100755 --- a/client/Tracy.hpp +++ b/client/Tracy.hpp @@ -7,6 +7,7 @@ #define ZoneScopedC(x) #define ZoneText(x,y) +#define ZoneName(x) #define FrameMark @@ -19,6 +20,7 @@ #define ZoneScopedC( color ) static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, color }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location ); #define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size ); +#define ZoneName( name ) ___tracy_scoped_zone.Name( name ); #define FrameMark tracy::Profiler::FrameMark(); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 60ec151f..e4479e86 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -112,6 +112,15 @@ void Profiler::ZoneText( uint64_t id, QueueZoneText&& data ) s_queue.enqueue( s_token, std::move( item ) ); } +void Profiler::ZoneName( uint64_t id, QueueZoneName&& data ) +{ + QueueItem item; + item.hdr.type = QueueType::ZoneName; + item.hdr.id = id; + item.zoneName = std::move( data ); + s_queue.enqueue( s_token, std::move( item ) ); +} + void Profiler::FrameMark() { QueueItem item; diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 5dc38998..8e90afdd 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -45,6 +45,7 @@ public: static uint64_t ZoneBegin( QueueZoneBegin&& data ); static void ZoneEnd( uint64_t id, QueueZoneEnd&& data ); static void ZoneText( uint64_t id, QueueZoneText&& data ); + static void ZoneName( uint64_t id, QueueZoneName&& data ); static void FrameMark(); static bool ShouldExit(); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 3e6b74cd..71e844f9 100755 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -30,6 +30,11 @@ public: Profiler::ZoneText( m_id, QueueZoneText { (uint64_t)ptr } ); } + void Name( const char* name ) + { + Profiler::ZoneName( m_id, QueueZoneName { (uint64_t)name } ); + } + private: uint64_t m_id; }; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index f9d926ae..7926d6ff 100755 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -16,6 +16,7 @@ enum class QueueType : uint8_t FrameMark, SourceLocation, ZoneText, + ZoneName, NUM_TYPES }; @@ -46,6 +47,11 @@ struct QueueZoneText uint64_t text; // ptr }; +struct QueueZoneName +{ + uint64_t name; // ptr +}; + struct QueueHeader { union @@ -65,6 +71,7 @@ struct QueueItem QueueZoneEnd zoneEnd; QueueSourceLocation srcloc; QueueZoneText zoneText; + QueueZoneName zoneName; }; }; @@ -81,6 +88,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ), // frame mark sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), sizeof( QueueHeader ) + sizeof( QueueZoneText ), + sizeof( QueueHeader ) + sizeof( QueueZoneName ), }; static_assert( sizeof( QueueDataSize ) / sizeof( size_t ) == (uint8_t)QueueType::NUM_TYPES, "QueueDataSize mismatch" ); diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 52c9d9b2..99b52867 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -9,6 +9,7 @@ namespace tracy struct TextData { const char* userText; + uint64_t zoneName; // ptr }; struct Event diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 1d69fe8c..22f202ee 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -248,6 +248,9 @@ void View::Process( const QueueItem& ev ) case QueueType::ZoneText: ProcessZoneText( ev.hdr.id, ev.zoneText ); break; + case QueueType::ZoneName: + ProcessZoneName( ev.hdr.id, ev.zoneName ); + break; default: assert( false ); break; @@ -330,6 +333,14 @@ void View::ProcessZoneText( uint64_t id, const QueueZoneText& ev ) CheckCustomString( ev.text, it->second ); } +void View::ProcessZoneName( uint64_t id, const QueueZoneName& ev ) +{ + auto it = m_openZones.find( id ); + assert( it != m_openZones.end() ); + CheckString( ev.name ); + GetTextData( *it->second )->zoneName = ev.name; +} + void View::CheckString( uint64_t ptr ) { if( m_strings.find( ptr ) != m_strings.end() ) return; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 8c75a2a8..fb33fd8a 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -53,6 +53,7 @@ private: void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev ); void ProcessFrameMark( uint64_t id ); void ProcessZoneText( uint64_t id, const QueueZoneText& ev ); + void ProcessZoneName( uint64_t id, const QueueZoneName& ev ); void CheckString( uint64_t ptr ); void CheckThreadString( uint64_t id );