diff --git a/Tracy.hpp b/Tracy.hpp index 1c757230..a2551d04 100644 --- a/Tracy.hpp +++ b/Tracy.hpp @@ -12,7 +12,7 @@ #define ZoneScopedNC(x,y) #define ZoneText(x,y) -#define ZoneName(x) +#define ZoneName(x,y) #define FrameMark @@ -46,6 +46,7 @@ #define ZoneScopedNC( name, color ) static const tracy::SourceLocation __tracy_source_location { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location ); #define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size ); +#define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size ); #define FrameMark tracy::Profiler::FrameMark(); diff --git a/TracyLua.hpp b/TracyLua.hpp index 23f7bd75..174498f1 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -27,6 +27,8 @@ static inline void LuaRegister( lua_State* L ) lua_pushcfunction( L, detail::noop ); lua_setfield( L, -2, "ZoneText" ); lua_pushcfunction( L, detail::noop ); + lua_setfield( L, -2, "ZoneName" ); + lua_pushcfunction( L, detail::noop ); lua_setfield( L, -2, "Message" ); lua_setglobal( L, "tracy" ); } @@ -67,6 +69,12 @@ static inline void LuaRemove( char* script ) memset( script, ' ', end - script ); script = end; } + else if( strncmp( script + 10, "Name(", 5 ) == 0 ) + { + auto end = FindEnd( script + 15 ); + memset( script, ' ', end - script ); + script = end; + } else if( strncmp( script + 10, "BeginN(", 7 ) == 0 ) { auto end = FindEnd( script + 17 ); @@ -247,6 +255,25 @@ static inline int LuaZoneText( lua_State* L ) return 0; } +static inline int LuaZoneName( lua_State* L ) +{ + auto txt = lua_tostring( L, 1 ); + const auto size = strlen( txt ); + + Magic magic; + auto& token = s_token.ptr; + 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::ZoneName ); + MemWrite( &item->zoneText.thread, GetThreadHandle() ); + MemWrite( &item->zoneText.text, (uint64_t)ptr ); + tail.store( magic + 1, std::memory_order_release ); + return 0; +} + static inline int LuaMessage( lua_State* L ) { auto txt = lua_tostring( L, 1 ); @@ -280,6 +307,8 @@ static inline void LuaRegister( lua_State* L ) lua_setfield( L, -2, "ZoneEnd" ); lua_pushcfunction( L, detail::LuaZoneText ); lua_setfield( L, -2, "ZoneText" ); + lua_pushcfunction( L, detail::LuaZoneName ); + lua_setfield( L, -2, "ZoneName" ); lua_pushcfunction( L, detail::LuaMessage ); lua_setfield( L, -2, "Message" ); lua_setglobal( L, "tracy" ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 8fee5591..f38e631b 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -375,6 +375,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) switch( (QueueType)idx ) { case QueueType::ZoneText: + case QueueType::ZoneName: ptr = MemRead( &item->zoneText.text ); SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); tracy_free( (void*)ptr ); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 12a87993..21e5fcd2 100644 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -92,6 +92,21 @@ public: tail.store( magic + 1, std::memory_order_release ); } + tracy_force_inline void Name( const char* txt, size_t size ) + { + Magic magic; + auto& token = s_token.ptr; + 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::ZoneName ); + MemWrite( &item->zoneText.thread, m_thread ); + MemWrite( &item->zoneText.text, (uint64_t)ptr ); + tail.store( magic + 1, std::memory_order_release ); + } + private: uint64_t m_thread; }; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index d91e3154..dcdf77b2 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -9,6 +9,7 @@ namespace tracy enum class QueueType : uint8_t { ZoneText, + ZoneName, Message, ZoneBeginAllocSrcLoc, CallstackMemory, @@ -273,6 +274,7 @@ enum { QueueItemSize = sizeof( QueueItem ) }; static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneText ), + sizeof( QueueHeader ) + sizeof( QueueZoneText ), // zone name sizeof( QueueHeader ) + sizeof( QueueMessage ), sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location sizeof( QueueHeader ) + sizeof( QueueCallstackMemory ),