1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-07 15:33:52 +00:00

Adding manual lifetime management to aid multi-DLL usecase

This commit is contained in:
Andrey Voroshilov 2020-07-07 00:39:09 -07:00
parent 384e2e3fa1
commit da5e58682f
2 changed files with 52 additions and 1 deletions

View File

@ -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<int> profilerDataLock { 0 };
static std::atomic<ProfilerData*> profilerData { nullptr };
@ -934,6 +952,7 @@ static ProfilerData& GetProfilerData()
}
return *ptr;
}
#endif
static ProfilerThreadData& GetProfilerThreadData()
{
@ -955,10 +974,13 @@ std::atomic<ThreadNameData*>& 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<ThreadNameData*>& 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<QueueItem>::ExplicitProducer* GetToken() { return s_token.ptr; }
TRACY_API Profiler& GetProfiler() { return s_profiler; }
TRACY_API moodycamel::ConcurrentQueue<QueueItem>& GetQueue() { return s_queue; }
TRACY_API int64_t GetInitTime() { return s_initTime.val; }
TRACY_API std::atomic<uint32_t>& 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 );

View File

@ -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