diff --git a/client/Tracy.hpp b/client/Tracy.hpp index b7a4dc55..2e6c6534 100755 --- a/client/Tracy.hpp +++ b/client/Tracy.hpp @@ -16,6 +16,8 @@ #define ZoneScoped static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, 0 }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location ); #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 FrameMark tracy::Profiler::FrameMark(); #endif diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index efe670c6..60ec151f 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -103,6 +103,15 @@ void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data ) ZoneEndImpl( s_token, id, std::move( data ) ); } +void Profiler::ZoneText( uint64_t id, QueueZoneText&& data ) +{ + QueueItem item; + item.hdr.type = QueueType::ZoneText; + item.hdr.id = id; + item.zoneText = std::move( data ); + s_queue.enqueue( s_token, std::move( item ) ); +} + void Profiler::FrameMark() { QueueItem item; @@ -199,7 +208,7 @@ bool Profiler::SendData( const char* data, size_t len ) bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type ) { - assert( type == QueueType::StringData || type == QueueType::ThreadName ); + assert( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::CustomStringData ); QueueHeader hdr; hdr.type = type; @@ -261,6 +270,10 @@ bool Profiler::HandleServerQuery() SendString( ptr, GetThreadName( ptr ), QueueType::ThreadName ); } break; + case ServerQueryCustomString: + SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); + delete[] (const char*)ptr; + break; case ServerQuerySourceLocation: SendSourceLocation( ptr ); break; diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 40358796..5dc38998 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -44,6 +44,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 FrameMark(); static bool ShouldExit(); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index e03f5228..3e6b74cd 100755 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -22,6 +22,14 @@ public: Profiler::ZoneEnd( m_id, QueueZoneEnd { Profiler::GetTime() } ); } + void Text( const char* txt, size_t size ) + { + auto ptr = new char[size+1]; + memcpy( ptr, txt, size ); + ptr[size] = '\0'; + Profiler::ZoneText( m_id, QueueZoneText { (uint64_t)ptr } ); + } + private: uint64_t m_id; }; diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 8f484dca..54d16ef4 100755 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -20,7 +20,8 @@ enum ServerQuery : uint8_t { ServerQueryString, ServerQueryThreadString, - ServerQuerySourceLocation + ServerQueryCustomString, + ServerQuerySourceLocation, }; #pragma pack( 1 ) diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 2d84fbb6..1a474d3a 100755 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -12,8 +12,10 @@ enum class QueueType : uint8_t ZoneEnd, StringData, ThreadName, + CustomStringData, FrameMark, SourceLocation, + ZoneText, NUM_TYPES }; @@ -39,6 +41,11 @@ struct QueueSourceLocation uint32_t color; }; +struct QueueZoneText +{ + uint64_t text; // ptr +}; + struct QueueHeader { union @@ -57,6 +64,7 @@ struct QueueItem QueueZoneBegin zoneBegin; QueueZoneEnd zoneEnd; QueueSourceLocation srcloc; + QueueZoneText zoneText; }; }; @@ -70,7 +78,9 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ), sizeof( QueueHeader ), sizeof( QueueHeader ), + sizeof( QueueHeader ), sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), + sizeof( QueueHeader ) + sizeof( QueueZoneText ), }; 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 87fa1cf2..d7579d8e 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -12,6 +12,7 @@ struct Event int64_t end; uint64_t srcloc; + const char* text; Event* parent; Vector child; }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f5f74538..bbfb1da1 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -157,7 +157,7 @@ close: void View::DispatchProcess( const QueueItem& ev ) { - if( ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName ) + if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName ) { timeval tv; tv.tv_sec = 0; @@ -167,7 +167,11 @@ void View::DispatchProcess( const QueueItem& ev ) uint16_t sz; m_sock.Read( &sz, sizeof( sz ), &tv, ShouldExit ); m_sock.Read( buf, sz, &tv, ShouldExit ); - if( ev.hdr.type == QueueType::StringData ) + if( ev.hdr.type == QueueType::CustomStringData ) + { + AddCustomString( ev.hdr.id, std::string( buf, buf+sz ) ); + } + else if( ev.hdr.type == QueueType::StringData ) { AddString( ev.hdr.id, std::string( buf, buf+sz ) ); } @@ -185,12 +189,16 @@ void View::DispatchProcess( const QueueItem& ev ) void View::DispatchProcess( const QueueItem& ev, const char*& ptr ) { ptr += QueueDataSize[ev.hdr.idx]; - if( ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName ) + if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName ) { uint16_t sz; memcpy( &sz, ptr, sizeof( sz ) ); ptr += sizeof( sz ); - if( ev.hdr.type == QueueType::StringData ) + if( ev.hdr.type == QueueType::CustomStringData ) + { + AddCustomString( ev.hdr.id, std::string( ptr, ptr+sz ) ); + } + else if( ev.hdr.type == QueueType::StringData ) { AddString( ev.hdr.id, std::string( ptr, ptr+sz ) ); } @@ -222,6 +230,9 @@ void View::Process( const QueueItem& ev ) case QueueType::SourceLocation: AddSourceLocation( ev.hdr.id, ev.srcloc ); break; + case QueueType::ZoneText: + ProcessZoneText( ev.hdr.id, ev.zoneText ); + break; default: assert( false ); break; @@ -238,6 +249,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ) zone->start = ev.time * m_timerMul; zone->srcloc = ev.srcloc; + zone->text = nullptr; std::unique_lock lock( m_lock ); @@ -296,6 +308,13 @@ void View::ProcessFrameMark( uint64_t id ) } } +void View::ProcessZoneText( uint64_t id, const QueueZoneText& ev ) +{ + auto it = m_openZones.find( id ); + assert( it != m_openZones.end() ); + CheckCustomString( ev.text, it->second ); +} + void View::CheckString( uint64_t ptr ) { if( m_strings.find( ptr ) != m_strings.end() ) return; @@ -320,6 +339,16 @@ void View::CheckThreadString( uint64_t id ) m_sock.Send( &id, sizeof( id ) ); } +void View::CheckCustomString( uint64_t ptr, Event* dst ) +{ + assert( m_pendingCustomStrings.find( ptr ) == m_pendingCustomStrings.end() ); + m_pendingCustomStrings.emplace( ptr, dst ); + + uint8_t type = ServerQueryCustomString; + m_sock.Send( &type, sizeof( type ) ); + m_sock.Send( &ptr, sizeof( ptr ) ); +} + void View::CheckSourceLocation( uint64_t ptr ) { if( m_sourceLocation.find( ptr ) != m_sourceLocation.end() ) return; @@ -352,6 +381,23 @@ void View::AddThreadString( uint64_t id, std::string&& str ) m_threadNames.emplace( id, std::move( str ) ); } +void View::AddCustomString( uint64_t ptr, std::string&& str ) +{ + auto pit = m_pendingCustomStrings.find( ptr ); + assert( pit != m_pendingCustomStrings.end() ); + auto sit = m_customStrings.find( str ); + if( sit == m_customStrings.end() ) + { + pit->second->text = str.c_str(); + m_customStrings.emplace( std::move( str ) ); + } + else + { + pit->second->text = sit->c_str(); + } + m_pendingCustomStrings.erase( pit ); +} + void View::AddSourceLocation( uint64_t ptr, const QueueSourceLocation& srcloc ) { assert( m_sourceLocation.find( ptr ) == m_sourceLocation.end() ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index e3d66f6d..92ec1cd8 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -49,13 +49,16 @@ private: void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ); void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev ); void ProcessFrameMark( uint64_t id ); + void ProcessZoneText( uint64_t id, const QueueZoneText& ev ); void CheckString( uint64_t ptr ); void CheckThreadString( uint64_t id ); + void CheckCustomString( uint64_t ptr, Event* dst ); void CheckSourceLocation( uint64_t ptr ); void AddString( uint64_t ptr, std::string&& str ); void AddThreadString( uint64_t id, std::string&& str ); + void AddCustomString( uint64_t ptr, std::string&& str ); void AddSourceLocation( uint64_t id, const QueueSourceLocation& srcloc ); void NewZone( Event* zone, uint64_t thread ); @@ -93,6 +96,7 @@ private: Vector m_threads; std::unordered_map m_strings; std::unordered_map m_threadNames; + std::unordered_set m_customStrings; std::unordered_map m_sourceLocation; uint64_t m_zonesCnt; @@ -105,6 +109,7 @@ private: std::unordered_set m_pendingStrings; std::unordered_set m_pendingThreads; std::unordered_set m_pendingSourceLocation; + std::unordered_map m_pendingCustomStrings; std::unordered_map m_threadMap; Slab m_slab;