From 60d2384a6a573f8a40afa16f3a582e846971dbf6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 12 Jul 2019 18:14:42 +0200 Subject: [PATCH] Allow sending application information messages. --- Tracy.hpp | 2 ++ TracyC.h | 3 +++ client/TracyProfiler.cpp | 21 +++++++++++++++++++++ client/TracyProfiler.hpp | 22 ++++++++++++++++++++++ common/TracyProtocol.hpp | 2 +- common/TracyQueue.hpp | 4 +++- 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Tracy.hpp b/Tracy.hpp index 4a8eb814..a3ec997a 100644 --- a/Tracy.hpp +++ b/Tracy.hpp @@ -40,6 +40,7 @@ #define TracyMessageL(x) #define TracyMessageC(x,y,z) #define TracyMessageLC(x,y) +#define TracyAppInfo(x,y) #define TracyAlloc(x,y) #define TracyFree(x) @@ -104,6 +105,7 @@ #define TracyMessageL( txt ) tracy::Profiler::Message( txt ); #define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color ); #define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color ); +#define TracyAppInfo( txt, size ) tracy::Profiler::MessageAppInfo( txt, size ); #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK # define TracyAlloc( ptr, size ) tracy::Profiler::MemAllocCallstack( ptr, size, TRACY_CALLSTACK ); diff --git a/TracyC.h b/TracyC.h index c5137cd5..aec4d119 100644 --- a/TracyC.h +++ b/TracyC.h @@ -36,6 +36,7 @@ typedef const void* TracyCZoneCtx; #define TracyCMessageL(x) #define TracyCMessageC(x,y,z) #define TracyCMessageLC(x,y) +#define TracyCAppInfo(x,y) #else @@ -120,12 +121,14 @@ void ___tracy_emit_message( const char* txt, size_t size ); void ___tracy_emit_messageL( const char* txt ); void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color ); void ___tracy_emit_messageLC( const char* txt, uint32_t color ); +void ___tracy_emit_message_appinfo( const char* txt, size_t size ); #define TracyCPlot( name, val ) ___tracy_emit_plot( name, val ); #define TracyCMessage( txt, size ) ___tracy_emit_message( txt, size ); #define TracyCMessageL( txt ) ___tracy_emit_messageL( txt ); #define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color ); #define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color ); +#define TracyCAppInfo( txt, color ) ___tracy_emit_message_appinfo( txt, color ); #ifdef TRACY_HAS_CALLSTACK diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 1f5cc916..b5d2eda6 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1338,6 +1338,11 @@ void Profiler::Worker() for( auto& item : m_deferredQueue ) { const auto idx = MemRead( &item.hdr.idx ); + if( (QueueType)idx == QueueType::MessageAppInfo ) + { + uint64_t ptr = MemRead( &item.message.text ); + SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); + } AppendData( &item, QueueDataSize[idx] ); } m_deferredLock.unlock(); @@ -1591,6 +1596,9 @@ static void FreeAssociatedMemory( const QueueItem& item ) break; case QueueType::Message: case QueueType::MessageColor: +#ifndef TRACY_ON_DEMAND + case QueueType::MessageAppInfo: +#endif ptr = MemRead( &item.message.text ); tracy_free( (void*)ptr ); break; @@ -1617,6 +1625,11 @@ static void FreeAssociatedMemory( const QueueItem& item ) ptr = MemRead( &item.frameImage.image ); tracy_free( (void*)ptr ); break; +#ifdef TRACY_ON_DEMAND + case QueueType::MessageAppInfo: + // Don't free memory associated with deferred messages. + break; +#endif default: assert( false ); break; @@ -1681,6 +1694,13 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); tracy_free( (void*)ptr ); break; + case QueueType::MessageAppInfo: + ptr = MemRead( &item->message.text ); + SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); +#ifndef TRACY_ON_DEMAND + tracy_free( (void*)ptr ); +#endif + break; case QueueType::ZoneBeginAllocSrcLoc: case QueueType::ZoneBeginAllocSrcLocCallstack: ptr = MemRead( &item->zoneBegin.srcloc ); @@ -2445,6 +2465,7 @@ void ___tracy_emit_message( const char* txt, size_t size ) { tracy::Profiler::Me void ___tracy_emit_messageL( const char* txt ) { tracy::Profiler::Message( txt ); } void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color ) { tracy::Profiler::MessageColor( txt, size, color ); } void ___tracy_emit_messageLC( const char* txt, uint32_t color ) { tracy::Profiler::MessageColor( txt, color ); } +void ___tracy_emit_message_appinfo( const char* txt, size_t size ) { tracy::Profiler::MessageAppInfo( txt, size ); } #ifdef __cplusplus } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 2a8f8aa3..3c0bb357 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -335,6 +335,28 @@ public: tail.store( magic + 1, std::memory_order_release ); } + static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) + { + Magic magic; + const auto thread = GetThreadHandle(); + auto token = GetToken(); + auto ptr = (char*)tracy_malloc( size+1 ); + memcpy( ptr, txt, size ); + ptr[size] = '\0'; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + MemWrite( &item->hdr.type, QueueType::MessageAppInfo ); + MemWrite( &item->message.time, GetTime() ); + MemWrite( &item->message.thread, thread ); + MemWrite( &item->message.text, (uint64_t)ptr ); + +#ifdef TRACY_ON_DEMAND + GetProfiler().DeferItem( *item ); +#endif + + tail.store( magic + 1, std::memory_order_release ); + } + static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) { #ifdef TRACY_ON_DEMAND diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 4a188b03..39ce5d96 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy { -enum : uint32_t { ProtocolVersion = 10 }; +enum : uint32_t { ProtocolVersion = 11 }; enum : uint32_t { BroadcastVersion = 0 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 42225f40..e51a1ff9 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -12,6 +12,7 @@ enum class QueueType : uint8_t ZoneName, Message, MessageColor, + MessageAppInfo, ZoneBeginAllocSrcLoc, ZoneBeginAllocSrcLocCallstack, CallstackMemory, @@ -348,9 +349,9 @@ struct QueueItem QueueSysTime sysTime; }; }; - #pragma pack() + enum { QueueItemSize = sizeof( QueueItem ) }; static const size_t QueueDataSize[] = { @@ -358,6 +359,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneText ), // zone name sizeof( QueueHeader ) + sizeof( QueueMessage ), sizeof( QueueHeader ) + sizeof( QueueMessageColor ), + sizeof( QueueHeader ) + sizeof( QueueMessage ), // app info sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location, callstack sizeof( QueueHeader ) + sizeof( QueueCallstackMemory ),