diff --git a/TracyD3D12.hpp b/TracyD3D12.hpp index e6eee170..dc215a3d 100644 --- a/TracyD3D12.hpp +++ b/TracyD3D12.hpp @@ -311,6 +311,10 @@ namespace tracy m_queryId = ctx->NextQueryId(); cmdList->EndQuery(ctx->m_queryHeap.Get(), D3D12_QUERY_TYPE_TIMESTAMP, m_queryId); +#if defined(TRACY_HAS_CALLSTACK) && defined(TRACY_CALLSTACK) + GetProfiler().SendCallstack(TRACY_CALLSTACK); +#endif + auto* item = Profiler::QueueSerial(); #if defined(TRACY_HAS_CALLSTACK) && defined(TRACY_CALLSTACK) MemWrite(&item->hdr.type, QueueType::GpuZoneBeginCallstackSerial); @@ -324,10 +328,6 @@ namespace tracy MemWrite(&item->gpuZoneBegin.context, ctx->GetId()); Profiler::QueueSerialFinish(); - -#if defined(TRACY_HAS_CALLSTACK) && defined(TRACY_CALLSTACK) - GetProfiler().SendCallstack(TRACY_CALLSTACK); -#endif } tracy_force_inline ~D3D12ZoneScope() diff --git a/TracyLua.hpp b/TracyLua.hpp index 68e21cff..a9a95c96 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -197,6 +197,13 @@ static inline int LuaZoneBeginS( lua_State* L ) if( !GetLuaZoneState().active ) return 0; #endif +#ifdef TRACY_CALLSTACK + const uint32_t depth = TRACY_CALLSTACK; +#else + const auto depth = uint32_t( lua_tointeger( L, 1 ) ); +#endif + SendLuaCallstack( L, depth ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); @@ -206,13 +213,6 @@ static inline int LuaZoneBeginS( lua_State* L ) MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; -#ifdef TRACY_CALLSTACK - const uint32_t depth = TRACY_CALLSTACK; -#else - const auto depth = uint32_t( lua_tointeger( L, 1 ) ); -#endif - SendLuaCallstack( L, depth ); - return 0; } @@ -225,6 +225,13 @@ static inline int LuaZoneBeginNS( lua_State* L ) if( !GetLuaZoneState().active ) return 0; #endif +#ifdef TRACY_CALLSTACK + const uint32_t depth = TRACY_CALLSTACK; +#else + const auto depth = uint32_t( lua_tointeger( L, 2 ) ); +#endif + SendLuaCallstack( L, depth ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); lua_Debug dbg; lua_getstack( L, 1, &dbg ); @@ -236,13 +243,6 @@ static inline int LuaZoneBeginNS( lua_State* L ) MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; -#ifdef TRACY_CALLSTACK - const uint32_t depth = TRACY_CALLSTACK; -#else - const auto depth = uint32_t( lua_tointeger( L, 2 ) ); -#endif - SendLuaCallstack( L, depth ); - return 0; } #endif diff --git a/TracyOpenCL.hpp b/TracyOpenCL.hpp index 0e46db89..8f344c91 100644 --- a/TracyOpenCL.hpp +++ b/TracyOpenCL.hpp @@ -246,6 +246,8 @@ namespace tracy { m_beginQueryId = ctx->NextQueryId(EventInfo{ nullptr, EventPhase::Begin }); + GetProfiler().SendCallstack(depth); + auto item = Profiler::QueueSerial(); MemWrite(&item->hdr.type, QueueType::GpuZoneBeginCallstackSerial); MemWrite(&item->gpuZoneBegin.cpuTime, Profiler::GetTime()); @@ -254,8 +256,6 @@ namespace tracy { MemWrite(&item->gpuZoneBegin.queryId, (uint16_t)m_beginQueryId); MemWrite(&item->gpuZoneBegin.context, ctx->GetId()); Profiler::QueueSerialFinish(); - - GetProfiler().SendCallstack(depth); } tracy_force_inline void SetEvent(cl_event event) diff --git a/TracyOpenGL.hpp b/TracyOpenGL.hpp index 69c3135b..cfa057a3 100644 --- a/TracyOpenGL.hpp +++ b/TracyOpenGL.hpp @@ -215,6 +215,8 @@ public: const auto queryId = GetGpuCtx().ptr->NextQueryId(); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); + GetProfiler().SendCallstack( depth ); + const auto thread = GetThreadHandle(); TracyLfqPrepare( QueueType::GpuZoneBeginCallstack ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); @@ -223,8 +225,6 @@ public: MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); TracyLfqCommit; - - GetProfiler().SendCallstack( depth ); } tracy_force_inline ~GpuCtxScope() diff --git a/TracyVulkan.hpp b/TracyVulkan.hpp index 6f1f80a9..48942dd0 100644 --- a/TracyVulkan.hpp +++ b/TracyVulkan.hpp @@ -342,6 +342,8 @@ public: const auto queryId = ctx->NextQueryId(); vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->m_query, queryId ); + GetProfiler().SendCallstack( depth ); + auto item = Profiler::QueueSerial(); MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstackSerial ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); @@ -350,8 +352,6 @@ public: MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.context, ctx->GetId() ); Profiler::QueueSerialFinish(); - - GetProfiler().SendCallstack( depth ); } tracy_force_inline ~VkCtxScope() diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 57dc828d..24847549 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -594,12 +594,12 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp ) } { + GetProfiler().SendCallstack( 60, "KiUserExceptionDispatcher" ); + TracyLfqPrepare( QueueType::CrashReport ); item->crashReport.time = Profiler::GetTime(); item->crashReport.text = (uint64_t)s_crashText; TracyLfqCommit; - - GetProfiler().SendCallstack( 60, "KiUserExceptionDispatcher" ); } HANDLE h = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); @@ -826,12 +826,12 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ ) } { + GetProfiler().SendCallstack( 60, "__kernel_rt_sigreturn" ); + TracyLfqPrepare( QueueType::CrashReport ); item->crashReport.time = Profiler::GetTime(); item->crashReport.text = (uint64_t)s_crashText; TracyLfqCommit; - - GetProfiler().SendCallstack( 60, "__kernel_rt_sigreturn" ); } DIR* dp = opendir( "/proc/self/task" ); @@ -2992,14 +2992,13 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac TracyLfqCommitC; } #endif + tracy::GetProfiler().SendCallstack( depth ); { TracyLfqPrepareC( tracy::QueueType::ZoneBeginCallstack ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); TracyLfqCommitC; } - - tracy::GetProfiler().SendCallstack( depth ); return ctx; } @@ -3058,14 +3057,13 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo TracyLfqCommitC; } #endif + tracy::GetProfiler().SendCallstack( depth ); { TracyLfqPrepareC( tracy::QueueType::ZoneBeginAllocSrcLocCallstack ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommitC; } - - tracy::GetProfiler().SendCallstack( depth ); return ctx; } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index d9ccd4cb..cd7ba790 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -283,6 +283,8 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::Message : QueueType::MessageCallstack ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -290,8 +292,6 @@ public: MemWrite( &item->messageFat.text, (uint64_t)ptr ); MemWrite( &item->messageFat.size, (uint16_t)size ); TracyLfqCommit; - - if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } static tracy_force_inline void Message( const char* txt, int callstack ) @@ -299,12 +299,12 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack ); MemWrite( &item->messageLiteral.time, GetTime() ); MemWrite( &item->messageLiteral.text, (uint64_t)txt ); TracyLfqCommit; - - if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color, int callstack ) @@ -313,6 +313,8 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -323,8 +325,6 @@ public: MemWrite( &item->messageColorFat.b, uint8_t( ( color >> 16 ) & 0xFF ) ); MemWrite( &item->messageColorFat.size, (uint16_t)size ); TracyLfqCommit; - - if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } static tracy_force_inline void MessageColor( const char* txt, uint32_t color, int callstack ) @@ -332,6 +332,8 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif + if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack ); MemWrite( &item->messageColorLiteral.time, GetTime() ); MemWrite( &item->messageColorLiteral.text, (uint64_t)txt ); @@ -339,8 +341,6 @@ public: MemWrite( &item->messageColorLiteral.g, uint8_t( ( color >> 8 ) & 0xFF ) ); MemWrite( &item->messageColorLiteral.b, uint8_t( ( color >> 16 ) & 0xFF ) ); TracyLfqCommit; - - if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) @@ -401,8 +401,8 @@ public: auto callstack = Callstack( depth ); profiler.m_serialLock.lock(); - SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size ); SendCallstackMemory( callstack ); + SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size ); profiler.m_serialLock.unlock(); #else MemAlloc( ptr, size, secure ); @@ -423,8 +423,8 @@ public: auto callstack = Callstack( depth ); profiler.m_serialLock.lock(); - SendMemFree( QueueType::MemFreeCallstack, thread, ptr ); SendCallstackMemory( callstack ); + SendMemFree( QueueType::MemFreeCallstack, thread, ptr ); profiler.m_serialLock.unlock(); #else MemFree( ptr, secure ); @@ -473,9 +473,9 @@ public: auto callstack = Callstack( depth ); profiler.m_serialLock.lock(); + SendCallstackMemory( callstack ); SendMemName( name ); SendMemAlloc( QueueType::MemAllocCallstackNamed, thread, ptr, size ); - SendCallstackMemory( callstack ); profiler.m_serialLock.unlock(); #else MemAlloc( ptr, size, secure ); @@ -496,9 +496,9 @@ public: auto callstack = Callstack( depth ); profiler.m_serialLock.lock(); + SendCallstackMemory( callstack ); SendMemName( name ); SendMemFree( QueueType::MemFreeCallstackNamed, thread, ptr ); - SendCallstackMemory( callstack ); profiler.m_serialLock.unlock(); #else MemFree( ptr, secure ); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 2e0a4a6a..78005e62 100644 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -49,12 +49,12 @@ public: #ifdef TRACY_ON_DEMAND m_connectionId = GetProfiler().ConnectionId(); #endif + GetProfiler().SendCallstack( depth ); + TracyLfqPrepare( QueueType::ZoneBeginCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); TracyLfqCommit; - - GetProfiler().SendCallstack( depth ); } tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, bool is_active = true ) @@ -86,13 +86,13 @@ public: #ifdef TRACY_ON_DEMAND m_connectionId = GetProfiler().ConnectionId(); #endif + GetProfiler().SendCallstack( depth ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); TracyLfqCommit; - - GetProfiler().SendCallstack( depth ); } tracy_force_inline ~ScopedZone() diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 60a69224..a24d05da 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 = 41 }; +enum : uint32_t { ProtocolVersion = 42 }; enum : uint16_t { BroadcastVersion = 2 }; using lz4sz_t = uint32_t;