mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Merge pull request #74 from avoroshilov/manual-lifetime
Manual lifetime management for Multi-DLL
This commit is contained in:
@@ -924,6 +924,25 @@ 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()
|
||||
{
|
||||
assert(s_profilerData);
|
||||
return *s_profilerData;
|
||||
}
|
||||
TRACY_API void ShutdownProfiler()
|
||||
{
|
||||
delete s_profilerData;
|
||||
s_profilerData = nullptr;
|
||||
rpmalloc_finalize();
|
||||
}
|
||||
# else
|
||||
static std::atomic<int> profilerDataLock { 0 };
|
||||
static std::atomic<ProfilerData*> profilerData { nullptr };
|
||||
|
||||
@@ -945,6 +964,7 @@ static ProfilerData& GetProfilerData()
|
||||
}
|
||||
return *ptr;
|
||||
}
|
||||
# endif
|
||||
|
||||
static ProfilerThreadData& GetProfilerThreadData()
|
||||
{
|
||||
@@ -966,10 +986,12 @@ std::atomic<ThreadNameData*>& GetThreadNameData() { return GetProfilerData().thr
|
||||
TRACY_API LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; }
|
||||
# endif
|
||||
|
||||
# ifndef TRACY_MANUAL_LIFETIME
|
||||
namespace
|
||||
{
|
||||
const auto& __profiler_init = GetProfiler();
|
||||
}
|
||||
# endif
|
||||
|
||||
#else
|
||||
TRACY_API void InitRPMallocThread()
|
||||
@@ -1094,6 +1116,13 @@ Profiler::Profiler()
|
||||
m_userPort = atoi( userPort );
|
||||
}
|
||||
|
||||
#if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_MANUAL_LIFETIME)
|
||||
SpawnWorkerThreads();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Profiler::SpawnWorkerThreads()
|
||||
{
|
||||
s_thread = (Thread*)tracy_malloc( sizeof( Thread ) );
|
||||
new(s_thread) Thread( LaunchWorker, this );
|
||||
|
||||
@@ -1185,6 +1214,8 @@ void Profiler::Worker()
|
||||
s_profilerTid = syscall( SYS_gettid );
|
||||
#endif
|
||||
|
||||
ThreadExitHandler threadExitHandler;
|
||||
|
||||
SetThreadName( "Tracy Profiler" );
|
||||
|
||||
#ifdef TRACY_DATA_PORT
|
||||
@@ -1605,6 +1636,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();
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
#if defined(TRACY_DELAYED_INIT) && defined(TRACY_MANUAL_LIFETIME)
|
||||
void StartupProfiler();
|
||||
void ShutdownProfiler();
|
||||
#endif
|
||||
|
||||
class GpuCtx;
|
||||
class Profiler;
|
||||
@@ -119,6 +123,8 @@ public:
|
||||
Profiler();
|
||||
~Profiler();
|
||||
|
||||
void SpawnWorkerThreads();
|
||||
|
||||
static tracy_force_inline int64_t GetTime()
|
||||
{
|
||||
#ifdef TRACY_HW_TIMER
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user