From 2b304581cfca72566977cd790abb7836476c052d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 24 May 2020 16:13:09 +0200 Subject: [PATCH] Implement transfer of integral values for zones. --- Tracy.hpp | 2 ++ TracyC.h | 3 +++ client/TracyProfiler.cpp | 17 +++++++++++++++++ client/TracyScoped.hpp | 11 +++++++++++ common/TracyProtocol.hpp | 2 +- common/TracyQueue.hpp | 8 ++++++++ server/TracyWorker.cpp | 35 +++++++++++++++++++++++++++++++++++ server/TracyWorker.hpp | 1 + 8 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Tracy.hpp b/Tracy.hpp index 71778567..7d3d1f10 100644 --- a/Tracy.hpp +++ b/Tracy.hpp @@ -18,6 +18,7 @@ #define ZoneText(x,y) #define ZoneName(x,y) +#define ZoneValue(x) #define FrameMark #define FrameMarkNamed(x) @@ -93,6 +94,7 @@ #define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size ); #define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size ); +#define ZoneValue( value ) ___tracy_scoped_zone.Value( value ); #define FrameMark tracy::Profiler::SendFrameMark( nullptr ); #define FrameMarkNamed( name ) tracy::Profiler::SendFrameMark( name ); diff --git a/TracyC.h b/TracyC.h index 55689498..9df1b651 100644 --- a/TracyC.h +++ b/TracyC.h @@ -22,6 +22,7 @@ typedef const void* TracyCZoneCtx; #define TracyCZoneEnd(c) #define TracyCZoneText(c,x,y) #define TracyCZoneName(c,x,y) +#define TracyCZoneValue(c,x) #define TracyCAlloc(x,y) #define TracyCFree(x) @@ -90,6 +91,7 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ); TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size ); TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size ); +TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value ); #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK # define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); @@ -107,6 +109,7 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size #define TracyCZoneText( ctx, txt, size ) ___tracy_emit_zone_text( ctx, txt, size ); #define TracyCZoneName( ctx, txt, size ) ___tracy_emit_zone_name( ctx, txt, size ); +#define TracyCZoneValue( ctx, value ) ___tracy_emit_zone_value( ctx, value ); TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index e100f702..1fae4fed 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -3033,6 +3033,23 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size } } +TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value ) +{ + if( !ctx.active ) return; +#ifndef TRACY_NO_VERIFY + { + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); + tracy::MemWrite( &item->zoneValidation.id, ctx.id ); + TracyLfqCommitC; + } +#endif + { + TracyLfqPrepareC( tracy::QueueType::ZoneValue ); + tracy::MemWrite( &item->zoneValue.value, value ); + TracyLfqCommitC; + } +} + TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size ) { tracy::Profiler::MemAlloc( ptr, size ); } TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth ) { tracy::Profiler::MemAllocCallstack( ptr, size, depth ); } TRACY_API void ___tracy_emit_memory_free( const void* ptr ) { tracy::Profiler::MemFree( ptr ); } diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 0497d7ed..57c7d56b 100644 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -90,6 +90,17 @@ public: TracyLfqCommit; } + tracy_force_inline void Value( uint64_t value ) + { + if( !m_active ) return; +#ifdef TRACY_ON_DEMAND + if( GetProfiler().ConnectionId() != m_connectionId ) return; +#endif + TracyLfqPrepare( QueueType::ZoneValue ); + MemWrite( &item->zoneValue.value, value ); + TracyLfqCommit; + } + private: const bool m_active; diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index ce52f57e..6cf94c7b 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 = 31 }; +enum : uint32_t { ProtocolVersion = 32 }; enum : uint32_t { BroadcastVersion = 1 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 77fe34c4..7bc34ed2 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -59,6 +59,7 @@ enum class QueueType : uint8_t Crash, CrashReport, ZoneValidation, + ZoneValue, FrameMarkMsg, FrameMarkMsgStart, FrameMarkMsgEnd, @@ -123,6 +124,11 @@ struct QueueZoneValidation uint32_t id; }; +struct QueueZoneValue +{ + uint64_t value; +}; + struct QueueStringTransfer { uint64_t ptr; @@ -439,6 +445,7 @@ struct QueueItem QueueZoneBeginLean zoneBeginLean; QueueZoneEnd zoneEnd; QueueZoneValidation zoneValidation; + QueueZoneValue zoneValue; QueueStringTransfer stringTransfer; QueueFrameMark frameMark; QueueFrameImage frameImage; @@ -538,6 +545,7 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ), // crash sizeof( QueueHeader ) + sizeof( QueueCrashReport ), sizeof( QueueHeader ) + sizeof( QueueZoneValidation ), + sizeof( QueueHeader ) + sizeof( QueueZoneValue ), sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // continuous frames sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // start sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // end diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 6220074f..ba995837 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -4156,6 +4156,9 @@ bool Worker::Process( const QueueItem& ev ) case QueueType::ZoneName: ProcessZoneName( ev.zoneText ); break; + case QueueType::ZoneValue: + ProcessZoneValue( ev.zoneValue ); + break; case QueueType::LockAnnounce: ProcessLockAnnounce( ev.lockAnnounce ); break; @@ -4758,6 +4761,38 @@ void Worker::ProcessZoneName( const QueueZoneText& ev ) m_pendingCustomStrings.erase( it ); } +void Worker::ProcessZoneValue( const QueueZoneValue& ev ) +{ + char tmp[32]; + const auto tsz = sprintf( tmp, "%" PRIu64, ev.value ); + + auto td = RetrieveThread( m_threadCtx ); + if( !td || td->stack.empty() || td->nextZoneId != td->zoneIdStack.back() ) + { + ZoneTextFailure( m_threadCtx ); + return; + } + + td->nextZoneId = 0; + auto& stack = td->stack; + auto zone = stack.back(); + auto& extra = RequestZoneExtra( *zone ); + if( !extra.text.Active() ) + { + extra.text = StringIdx( StoreString( tmp, tsz ).idx ); + } + else + { + const auto str0 = GetString( extra.text ); + const auto len0 = strlen( str0 ); + char* buf = (char*)alloca( len0+tsz+1 ); + memcpy( buf, str0, len0 ); + buf[len0] = '\n'; + memcpy( buf+len0+1, tmp, tsz ); + extra.text = StringIdx( StoreString( buf, len0+tsz+1 ).idx ); + } +} + void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev ) { auto it = m_data.lockMap.find( ev.id ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 8148bc31..6f02cc3b 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -576,6 +576,7 @@ private: tracy_force_inline void ProcessFrameImage( const QueueFrameImageLean& ev ); tracy_force_inline void ProcessZoneText( const QueueZoneText& ev ); tracy_force_inline void ProcessZoneName( const QueueZoneText& ev ); + tracy_force_inline void ProcessZoneValue( const QueueZoneValue& ev ); tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev ); tracy_force_inline void ProcessLockTerminate( const QueueLockTerminate& ev ); tracy_force_inline void ProcessLockWait( const QueueLockWait& ev );