From da5e58682f5098dec8dba74f4663985bbdc7ec5e Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Tue, 7 Jul 2020 00:39:09 -0700 Subject: [PATCH 01/13] Adding manual lifetime management to aid multi-DLL usecase --- client/TracyProfiler.cpp | 47 +++++++++++++++++++++++++++++++++++++++- client/TracyProfiler.hpp | 6 +++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 8d2da1a8..471ffcdb 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -913,6 +913,24 @@ struct ProfilerThreadData # endif }; +#ifdef TRACY_MANUAL_LIFETIME +ProfilerData* s_profilerData = nullptr; +TRACY_API void startupProfiler() +{ + s_profilerData = new ProfilerData; + s_profilerData->profiler.SpawnWorkerThreads(); +} +static ProfilerData& GetProfilerData() +{ + while (!s_profilerData); + return *s_profilerData; +} +TRACY_API void shutdownProfiler() +{ + delete s_profilerData; + s_profilerData = nullptr; +} +#else static std::atomic profilerDataLock { 0 }; static std::atomic profilerData { nullptr }; @@ -934,6 +952,7 @@ static ProfilerData& GetProfilerData() } return *ptr; } +#endif static ProfilerThreadData& GetProfilerThreadData() { @@ -955,10 +974,13 @@ std::atomic& GetThreadNameData() { return GetProfilerData().thr TRACY_API LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; } # endif +#ifdef TRACY_MANUAL_LIFETIME +#else namespace { const auto& __profiler_init = GetProfiler(); } +#endif #else TRACY_API void InitRPMallocThread() @@ -1000,10 +1022,25 @@ std::atomic& s_threadNameData = s_threadNameDataInstance; thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; # endif +#ifdef TRACY_MANUAL_LIFETIME +Profiler* s_profiler = nullptr; + +TRACY_API void startupProfiler() +{ + s_profiler = new Profiler; +} +TRACY_API void shutdownProfiler() +{ + delete s_profiler; + s_profiler = nullptr; +} +TRACY_API Profiler& GetProfiler() { return *s_profiler; } +#else static Profiler init_order(105) s_profiler; +TRACY_API Profiler& GetProfiler() { return s_profiler; } +#endif TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } -TRACY_API Profiler& GetProfiler() { return s_profiler; } TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } TRACY_API int64_t GetInitTime() { return s_initTime.val; } TRACY_API std::atomic& GetLockCounter() { return s_lockCounter; } @@ -1083,6 +1120,14 @@ Profiler::Profiler() m_userPort = atoi( userPort ); } +#ifdef TRACY_MANUAL_LIFETIME +#else + SpawnWorkerThreads(); +#endif +} + +void Profiler::SpawnWorkerThreads() +{ s_thread = (Thread*)tracy_malloc( sizeof( Thread ) ); new(s_thread) Thread( LaunchWorker, this ); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 1507418f..61f350ca 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -41,6 +41,10 @@ namespace tracy { +#ifdef TRACY_MANUAL_LIFETIME +void startupProfiler(); +void shutdownProfiler(); +#endif class GpuCtx; class Profiler; @@ -118,6 +122,8 @@ public: Profiler(); ~Profiler(); + void SpawnWorkerThreads(); + static tracy_force_inline int64_t GetTime() { #ifdef TRACY_HW_TIMER From 6a7256098905a408f0f81ff61dbe4e997aef0011 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Tue, 7 Jul 2020 03:12:02 -0700 Subject: [PATCH 02/13] Fixing functions case to match the source capitalization rules --- client/TracyProfiler.cpp | 8 ++++---- client/TracyProfiler.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 471ffcdb..ec5e9b5a 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -915,7 +915,7 @@ struct ProfilerThreadData #ifdef TRACY_MANUAL_LIFETIME ProfilerData* s_profilerData = nullptr; -TRACY_API void startupProfiler() +TRACY_API void StartupProfiler() { s_profilerData = new ProfilerData; s_profilerData->profiler.SpawnWorkerThreads(); @@ -925,7 +925,7 @@ static ProfilerData& GetProfilerData() while (!s_profilerData); return *s_profilerData; } -TRACY_API void shutdownProfiler() +TRACY_API void ShutdownProfiler() { delete s_profilerData; s_profilerData = nullptr; @@ -1025,11 +1025,11 @@ thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; #ifdef TRACY_MANUAL_LIFETIME Profiler* s_profiler = nullptr; -TRACY_API void startupProfiler() +TRACY_API void StartupProfiler() { s_profiler = new Profiler; } -TRACY_API void shutdownProfiler() +TRACY_API void ShutdownProfiler() { delete s_profiler; s_profiler = nullptr; diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 61f350ca..0ead2c29 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -42,8 +42,8 @@ namespace tracy { #ifdef TRACY_MANUAL_LIFETIME -void startupProfiler(); -void shutdownProfiler(); +void StartupProfiler(); +void ShutdownProfiler(); #endif class GpuCtx; From 71ca0683d67eec9c4ddb54ade8c031d2e5b7d70f Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Wed, 8 Jul 2020 03:48:37 -0700 Subject: [PATCH 03/13] Fixing preprocessor formatting --- client/TracyProfiler.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index ec5e9b5a..272278d4 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -913,7 +913,7 @@ struct ProfilerThreadData # endif }; -#ifdef TRACY_MANUAL_LIFETIME +# ifdef TRACY_MANUAL_LIFETIME ProfilerData* s_profilerData = nullptr; TRACY_API void StartupProfiler() { @@ -930,7 +930,7 @@ TRACY_API void ShutdownProfiler() delete s_profilerData; s_profilerData = nullptr; } -#else +# else static std::atomic profilerDataLock { 0 }; static std::atomic profilerData { nullptr }; @@ -952,7 +952,7 @@ static ProfilerData& GetProfilerData() } return *ptr; } -#endif +# endif static ProfilerThreadData& GetProfilerThreadData() { @@ -974,13 +974,13 @@ std::atomic& GetThreadNameData() { return GetProfilerData().thr TRACY_API LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; } # endif -#ifdef TRACY_MANUAL_LIFETIME -#else +# ifdef TRACY_MANUAL_LIFETIME +# else namespace { const auto& __profiler_init = GetProfiler(); } -#endif +# endif #else TRACY_API void InitRPMallocThread() @@ -1022,7 +1022,7 @@ std::atomic& s_threadNameData = s_threadNameDataInstance; thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; # endif -#ifdef TRACY_MANUAL_LIFETIME +# ifdef TRACY_MANUAL_LIFETIME Profiler* s_profiler = nullptr; TRACY_API void StartupProfiler() @@ -1035,10 +1035,10 @@ TRACY_API void ShutdownProfiler() s_profiler = nullptr; } TRACY_API Profiler& GetProfiler() { return *s_profiler; } -#else +# else static Profiler init_order(105) s_profiler; TRACY_API Profiler& GetProfiler() { return s_profiler; } -#endif +# endif TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } From 199dc46e7d80ea104187eaa39b206ad1403e0a62 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Wed, 8 Jul 2020 03:50:25 -0700 Subject: [PATCH 04/13] Fixing crash on exit due to RP malloc not being deinitialized --- client/TracyProfiler.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 272278d4..334573db 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -929,6 +929,7 @@ TRACY_API void ShutdownProfiler() { delete s_profilerData; s_profilerData = nullptr; + rpmalloc_finalize(); } # else static std::atomic profilerDataLock { 0 }; @@ -1033,6 +1034,7 @@ TRACY_API void ShutdownProfiler() { delete s_profiler; s_profiler = nullptr; + rpmalloc_finalize(); } TRACY_API Profiler& GetProfiler() { return *s_profiler; } # else @@ -1213,12 +1215,25 @@ bool Profiler::ShouldExit() return s_instance->m_shutdown.load( std::memory_order_relaxed ); } +class ThreadExitHandler +{ +public: + ~ThreadExitHandler() + { +#ifdef TRACY_MANUAL_LIFETIME + rpmalloc_thread_finalize(); +#endif + } +}; + void Profiler::Worker() { #ifdef __linux__ s_profilerTid = syscall( SYS_gettid ); #endif + ThreadExitHandler threadExitHandler; + SetThreadName( "Tracy Profiler" ); #ifdef TRACY_DATA_PORT @@ -1639,6 +1654,8 @@ void Profiler::Worker() void Profiler::CompressWorker() { + ThreadExitHandler threadExitHandler; + SetThreadName( "Tracy DXT1" ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); rpmalloc_thread_initialize(); From 4d505f507b6914681d373e05d337af2b50c6883b Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Wed, 8 Jul 2020 03:52:00 -0700 Subject: [PATCH 05/13] Fixed rogue TAB indentation --- client/TracyProfiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 334573db..3d31cb0b 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -927,7 +927,7 @@ static ProfilerData& GetProfilerData() } TRACY_API void ShutdownProfiler() { - delete s_profilerData; + delete s_profilerData; s_profilerData = nullptr; rpmalloc_finalize(); } From 6b790d778d96f711243180d46138e9810d6ea3f4 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sun, 12 Jul 2020 10:04:07 -0700 Subject: [PATCH 06/13] Replacing removing spinlock that is not needed anymore, making `TRACY_MANUAL_LIFETIME` a sub-option of `TRACY_DELAYED_INIT`, and addressing feedback --- client/TracyProfiler.cpp | 26 ++++---------------------- client/TracyProfiler.hpp | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 3d31cb0b..ad31dda3 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -922,7 +922,7 @@ TRACY_API void StartupProfiler() } static ProfilerData& GetProfilerData() { - while (!s_profilerData); + assert(s_profilerData); return *s_profilerData; } TRACY_API void ShutdownProfiler() @@ -975,8 +975,7 @@ std::atomic& GetThreadNameData() { return GetProfilerData().thr TRACY_API LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; } # endif -# ifdef TRACY_MANUAL_LIFETIME -# else +# ifndef TRACY_MANUAL_LIFETIME namespace { const auto& __profiler_init = GetProfiler(); @@ -1023,27 +1022,11 @@ std::atomic& s_threadNameData = s_threadNameDataInstance; thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; # endif -# ifdef TRACY_MANUAL_LIFETIME -Profiler* s_profiler = nullptr; - -TRACY_API void StartupProfiler() -{ - s_profiler = new Profiler; -} -TRACY_API void ShutdownProfiler() -{ - delete s_profiler; - s_profiler = nullptr; - rpmalloc_finalize(); -} -TRACY_API Profiler& GetProfiler() { return *s_profiler; } -# else static Profiler init_order(105) s_profiler; -TRACY_API Profiler& GetProfiler() { return s_profiler; } -# endif TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } +TRACY_API Profiler& GetProfiler() { return s_profiler; } TRACY_API int64_t GetInitTime() { return s_initTime.val; } TRACY_API std::atomic& GetLockCounter() { return s_lockCounter; } TRACY_API std::atomic& GetGpuCtxCounter() { return s_gpuCtxCounter; } @@ -1122,8 +1105,7 @@ Profiler::Profiler() m_userPort = atoi( userPort ); } -#ifdef TRACY_MANUAL_LIFETIME -#else +#if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_NONSTATIC_PROFILER) SpawnWorkerThreads(); #endif } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 0ead2c29..0a9a16ee 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -41,7 +41,7 @@ namespace tracy { -#ifdef TRACY_MANUAL_LIFETIME +#if defined(TRACY_DELAYED_INIT) && defined(TRACY_NONSTATIC_PROFILER) void StartupProfiler(); void ShutdownProfiler(); #endif From a758de2f037025db1de8db29ed133c999ccc6b49 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sun, 12 Jul 2020 10:06:09 -0700 Subject: [PATCH 07/13] Moving `GetProfiler` back to the original place --- client/TracyProfiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index ad31dda3..fc0eaf12 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -962,8 +962,8 @@ static ProfilerThreadData& GetProfilerThreadData() } TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return GetProfilerThreadData().token.ptr; } -TRACY_API Profiler& GetProfiler() { return GetProfilerData().profiler; } TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return GetProfilerData().queue; } +TRACY_API Profiler& GetProfiler() { return GetProfilerData().profiler; } TRACY_API int64_t GetInitTime() { return GetProfilerData().initTime; } TRACY_API std::atomic& GetLockCounter() { return GetProfilerData().lockCounter; } TRACY_API std::atomic& GetGpuCtxCounter() { return GetProfilerData().gpuCtxCounter; } From 3ae84647c421d60d3f2a65942ea3fbfc4ad811e6 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sun, 12 Jul 2020 10:10:09 -0700 Subject: [PATCH 08/13] Moving `GetProfiler` back to the original place --- client/TracyProfiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index fc0eaf12..ad31dda3 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -962,8 +962,8 @@ static ProfilerThreadData& GetProfilerThreadData() } TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return GetProfilerThreadData().token.ptr; } -TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return GetProfilerData().queue; } TRACY_API Profiler& GetProfiler() { return GetProfilerData().profiler; } +TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return GetProfilerData().queue; } TRACY_API int64_t GetInitTime() { return GetProfilerData().initTime; } TRACY_API std::atomic& GetLockCounter() { return GetProfilerData().lockCounter; } TRACY_API std::atomic& GetGpuCtxCounter() { return GetProfilerData().gpuCtxCounter; } From 4c397ebe1e7806d0e710711926dae951653f4f94 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sun, 12 Jul 2020 10:12:50 -0700 Subject: [PATCH 09/13] Fixing some of the copy-paste errors --- client/TracyProfiler.cpp | 4 ++-- client/TracyProfiler.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index ad31dda3..f52db989 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1025,8 +1025,8 @@ thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; static Profiler init_order(105) s_profiler; TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } -TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } TRACY_API Profiler& GetProfiler() { return s_profiler; } +TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } TRACY_API int64_t GetInitTime() { return s_initTime.val; } TRACY_API std::atomic& GetLockCounter() { return s_lockCounter; } TRACY_API std::atomic& GetGpuCtxCounter() { return s_gpuCtxCounter; } @@ -1105,7 +1105,7 @@ Profiler::Profiler() m_userPort = atoi( userPort ); } -#if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_NONSTATIC_PROFILER) +#if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_MANUAL_LIFETIME) SpawnWorkerThreads(); #endif } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 0a9a16ee..87c4c098 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -41,7 +41,7 @@ namespace tracy { -#if defined(TRACY_DELAYED_INIT) && defined(TRACY_NONSTATIC_PROFILER) +#if defined(TRACY_DELAYED_INIT) && defined(TRACY_MANUAL_LIFETIME) void StartupProfiler(); void ShutdownProfiler(); #endif From bd5d965023d2d0364787519df833a3f65214ac28 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Mon, 13 Jul 2020 01:41:25 -0700 Subject: [PATCH 10/13] Updating manual and AUTHORS --- AUTHORS | 1 + manual/tracy.tex | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index 7320b73b..1d06c4b5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ Michał Cichoń (OSX call stack decoding b Thales Sabino (OpenCL support) Andrew Depke (Direct3D 12 support) Simonas Kazlauskas (OSX CI, external bindings) +Andrey Voroshilov (multi-DLL fixes) diff --git a/manual/tracy.tex b/manual/tracy.tex index 5e85ea0d..00123503 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -426,6 +426,10 @@ For that you need a \emph{profiler DLL} to which your executable and the other D If you are targeting Windows with Microsoft Visual Studio or MinGW, add the \texttt{TRACY\_IMPORTS} define to your application. +If you are experiencing crashes or freezes when manually loading/unloading a separate DLL with Tracy integration, you might want to try defining both \texttt{TRACY\_DELAYED\_INIT} and \texttt{TRACY\_MANUAL\_LIFETIME} macros. + +\texttt{TRACY\_DELAYED\_INIT} enables a path where profiler data is gathered into one structure and initialized on the first request rather than statically at the DLL load at the expense of atomic load on each request to the profiler data. \texttt{TRACY\_MANUAL\_LIFETIME} flag augments this behavior to provide manual \texttt{StartupProfiler} and \texttt{ShutdownProfiler} functions that allow you to manually create and destroy the profiler data, removing the need to do an atomic load on each call, as well as letting you define an appropriate place to free the resources. + \subsubsection{Problematic platforms} Some OS vendors think that \emph{they} own and control the devices \emph{you} have paid for. This results in restricting usage of APIs that might 'confuse' you, or denying you access to information about what your computer is doing. From 47683d3b907466af25d7f3e7b303158500437441 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Mon, 13 Jul 2020 08:13:42 -0700 Subject: [PATCH 11/13] Added `TRACY_MANUAL_LIFETIME` test compile --- .github/workflows/gcc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 7a71bfef..bfbf351a 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -40,3 +40,4 @@ jobs: make -j -C test make -j -C test clean make -j -C test TRACYFLAGS=-DTRACY_ON_DEMAND + make -j -C test TRACYFLAGS="-DTRACY_DELAYED_INIT -DTRACY_MANUAL_LIFETIME" From 416259fdb7580eea9fbabeb14483a3f935f35c03 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sat, 18 Jul 2020 18:20:49 -0700 Subject: [PATCH 12/13] Adding clean run for the TRACY_MANUAL_LIFETIME testing target --- .github/workflows/gcc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index bfbf351a..91fe6740 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -40,4 +40,5 @@ jobs: make -j -C test make -j -C test clean make -j -C test TRACYFLAGS=-DTRACY_ON_DEMAND + make -j -C test clean make -j -C test TRACYFLAGS="-DTRACY_DELAYED_INIT -DTRACY_MANUAL_LIFETIME" From 175ec3e3d8c84fb14cd5d980e0b2f84b98aaf564 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Sat, 18 Jul 2020 18:24:49 -0700 Subject: [PATCH 13/13] Moving ThreadExitHandler to a commonly accessible space, adding thread handler usage to SysTrace worker threads --- client/TracyProfiler.cpp | 11 ----------- client/TracySysTrace.cpp | 4 ++++ client/TracyThread.hpp | 11 +++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index d61ea061..857bd5e7 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1208,17 +1208,6 @@ bool Profiler::ShouldExit() return s_instance->m_shutdown.load( std::memory_order_relaxed ); } -class ThreadExitHandler -{ -public: - ~ThreadExitHandler() - { -#ifdef TRACY_MANUAL_LIFETIME - rpmalloc_thread_finalize(); -#endif - } -}; - void Profiler::Worker() { #ifdef __linux__ diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 68652886..653ada21 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -321,6 +321,7 @@ static void SetupVsync() s_threadVsync = (Thread*)tracy_malloc( sizeof( Thread ) ); new(s_threadVsync) Thread( [] (void*) { + ThreadExitHandler threadExitHandler; SetThreadName( "Tracy Vsync" ); ProcessTrace( &s_traceHandleVsync2, 1, nullptr, nullptr ); }, nullptr ); @@ -455,6 +456,7 @@ void SysTraceStop() void SysTraceWorker( void* ptr ) { + ThreadExitHandler threadExitHandler; SetThreadName( "Tracy SysTrace" ); ProcessTrace( &s_traceHandle2, 1, 0, 0 ); ControlTrace( 0, KERNEL_LOGGER_NAME, s_prop, EVENT_TRACE_CONTROL_STOP ); @@ -955,6 +957,7 @@ static void ProcessTraceLines( int fd ) void SysTraceWorker( void* ptr ) { + ThreadExitHandler threadExitHandler; SetThreadName( "Tracy SysTrace" ); int pipefd[2]; if( pipe( pipefd ) == 0 ) @@ -1028,6 +1031,7 @@ static void ProcessTraceLines( int fd ) void SysTraceWorker( void* ptr ) { + ThreadExitHandler threadExitHandler; SetThreadName( "Tracy SysTrace" ); char tmp[256]; memcpy( tmp, BasePath, sizeof( BasePath ) - 1 ); diff --git a/client/TracyThread.hpp b/client/TracyThread.hpp index 7fca497b..28c64c54 100644 --- a/client/TracyThread.hpp +++ b/client/TracyThread.hpp @@ -10,6 +10,17 @@ namespace tracy { +class ThreadExitHandler +{ +public: + ~ThreadExitHandler() + { +#ifdef TRACY_MANUAL_LIFETIME + rpmalloc_thread_finalize(); +#endif + } +}; + #if defined _WIN32 || defined __CYGWIN__ class Thread