From 8286b0b72fb4fa86b973480ff4f24e8a011efe76 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 14 Nov 2019 23:40:41 +0100 Subject: [PATCH] Plumbing for message call stacks. --- Tracy.hpp | 8 ++++---- TracyC.h | 16 ++++++++-------- client/TracyProfiler.cpp | 12 ++++++++---- client/TracyProfiler.hpp | 24 ++++++++++++++++-------- common/TracyProtocol.hpp | 2 +- common/TracyQueue.hpp | 8 ++++++++ 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Tracy.hpp b/Tracy.hpp index ebeac22f..4ef18a97 100644 --- a/Tracy.hpp +++ b/Tracy.hpp @@ -103,10 +103,10 @@ #define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val ); #define TracyPlotConfig( name, type ) tracy::Profiler::ConfigurePlot( name, type ); -#define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size ); -#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 TracyMessage( txt, size ) tracy::Profiler::Message( txt, size, 0 ); +#define TracyMessageL( txt ) tracy::Profiler::Message( txt, 0 ); +#define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color, 0 ); +#define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color, 0 ); #define TracyAppInfo( txt, size ) tracy::Profiler::MessageAppInfo( txt, size ); #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK diff --git a/TracyC.h b/TracyC.h index 53ef30b5..9c1e000b 100644 --- a/TracyC.h +++ b/TracyC.h @@ -117,17 +117,17 @@ TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_ TRACY_API void ___tracy_emit_plot( const char* name, double val ); -TRACY_API void ___tracy_emit_message( const char* txt, size_t size ); -TRACY_API void ___tracy_emit_messageL( const char* txt ); -TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color ); -TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color ); +TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ); +TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ); +TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ); +TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int callstack ); TRACY_API 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 TracyCMessage( txt, size ) ___tracy_emit_message( txt, size, 0 ); +#define TracyCMessageL( txt ) ___tracy_emit_messageL( txt, 0 ); +#define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color, 0 ); +#define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color, 0 ); #define TracyCAppInfo( txt, color ) ___tracy_emit_message_appinfo( txt, color ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 68517f8f..e2d0950b 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1599,6 +1599,8 @@ static void FreeAssociatedMemory( const QueueItem& item ) break; case QueueType::Message: case QueueType::MessageColor: + case QueueType::MessageCallstack: + case QueueType::MessageColorCallstack: #ifndef TRACY_ON_DEMAND case QueueType::MessageAppInfo: #endif @@ -1706,6 +1708,8 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) break; case QueueType::Message: case QueueType::MessageColor: + case QueueType::MessageCallstack: + case QueueType::MessageColorCallstack: ptr = MemRead( &item->message.text ); SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); tracy_free( (void*)ptr ); @@ -2665,10 +2669,10 @@ TRACY_API void ___tracy_emit_frame_mark_start( const char* name ) { tracy::Profi TRACY_API void ___tracy_emit_frame_mark_end( const char* name ) { tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgEnd ); } TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_t h, uint8_t offset, int flip ) { tracy::Profiler::SendFrameImage( image, w, h, offset, flip ); } TRACY_API void ___tracy_emit_plot( const char* name, double val ) { tracy::Profiler::PlotData( name, val ); } -TRACY_API void ___tracy_emit_message( const char* txt, size_t size ) { tracy::Profiler::Message( txt, size ); } -TRACY_API void ___tracy_emit_messageL( const char* txt ) { tracy::Profiler::Message( txt ); } -TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color ) { tracy::Profiler::MessageColor( txt, size, color ); } -TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color ) { tracy::Profiler::MessageColor( txt, color ); } +TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ) { tracy::Profiler::Message( txt, size, callstack ); } +TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ) { tracy::Profiler::Message( txt, callstack ); } +TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, size, color, callstack ); } +TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, color, callstack ); } TRACY_API 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 87f84e60..f3ea50a6 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -262,7 +262,7 @@ public: tail.store( magic + 1, std::memory_order_release ); } - static tracy_force_inline void Message( const char* txt, size_t size ) + static tracy_force_inline void Message( const char* txt, size_t size, int callstack ) { #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; @@ -274,13 +274,15 @@ public: ptr[size] = '\0'; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::Message ); + MemWrite( &item->hdr.type, callstack == 0 ? QueueType::Message : QueueType::MessageCallstack ); MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.text, (uint64_t)ptr ); tail.store( magic + 1, std::memory_order_release ); + + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } - static tracy_force_inline void Message( const char* txt ) + static tracy_force_inline void Message( const char* txt, int callstack ) { #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; @@ -289,13 +291,15 @@ public: auto token = GetToken(); auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::MessageLiteral ); + MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack ); MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.text, (uint64_t)txt ); tail.store( magic + 1, std::memory_order_release ); + + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } - static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color ) + static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color, int callstack ) { #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; @@ -307,16 +311,18 @@ public: ptr[size] = '\0'; auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::MessageColor ); + MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack ); MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.text, (uint64_t)ptr ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); tail.store( magic + 1, std::memory_order_release ); + + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } - static tracy_force_inline void MessageColor( const char* txt, uint32_t color ) + static tracy_force_inline void MessageColor( const char* txt, uint32_t color, int callstack ) { #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; @@ -325,13 +331,15 @@ public: auto token = GetToken(); auto& tail = token->get_tail_index(); auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::MessageLiteralColor ); + MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack ); MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.text, (uint64_t)txt ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); tail.store( magic + 1, std::memory_order_release ); + + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 5daa360e..43144c48 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } -enum : uint32_t { ProtocolVersion = 22 }; +enum : uint32_t { ProtocolVersion = 23 }; enum : uint32_t { BroadcastVersion = 0 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index fc08d1fa..113d74d0 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -12,6 +12,8 @@ enum class QueueType : uint8_t ZoneName, Message, MessageColor, + MessageCallstack, + MessageColorCallstack, MessageAppInfo, ZoneBeginAllocSrcLoc, ZoneBeginAllocSrcLocCallstack, @@ -57,6 +59,8 @@ enum class QueueType : uint8_t LockMark, MessageLiteral, MessageLiteralColor, + MessageLiteralCallstack, + MessageLiteralColorCallstack, GpuNewContext, CallstackFrameSize, CallstackFrame, @@ -405,6 +409,8 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneText ), // zone name sizeof( QueueHeader ) + sizeof( QueueMessage ), sizeof( QueueHeader ) + sizeof( QueueMessageColor ), + sizeof( QueueHeader ) + sizeof( QueueMessage ), // callstack + sizeof( QueueHeader ) + sizeof( QueueMessageColor ), // callstack sizeof( QueueHeader ) + sizeof( QueueMessage ), // app info sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location, callstack @@ -451,6 +457,8 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueLockMark ), sizeof( QueueHeader ) + sizeof( QueueMessage ), // literal sizeof( QueueHeader ) + sizeof( QueueMessageColor ), // literal + sizeof( QueueHeader ) + sizeof( QueueMessage ), // literal, callstack + sizeof( QueueHeader ) + sizeof( QueueMessageColor ), // literal, callstack sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ), sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ), sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),