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