mirror of
https://github.com/wolfpld/tracy
synced 2025-04-28 20:23:51 +00:00
Prevent direct access to s_profiler.
This commit is contained in:
parent
d865d1cc87
commit
2421e05c27
@ -30,7 +30,6 @@ namespace tracy
|
||||
|
||||
DLL_IMPORT void*(*get_rpmalloc())(size_t size);
|
||||
DLL_IMPORT void(*get_rpfree())(void* ptr);
|
||||
DLL_IMPORT Profiler& get_profiler();
|
||||
|
||||
#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6
|
||||
DLL_IMPORT int64_t(*get_GetTimeImpl())();
|
||||
@ -63,8 +62,6 @@ namespace tracy
|
||||
{
|
||||
rpfree_fpt(ptr);
|
||||
}
|
||||
|
||||
Profiler& s_profiler = get_profiler();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
12
TracyLua.hpp
12
TracyLua.hpp
@ -130,7 +130,7 @@ static inline int LuaZoneBegin( lua_State* L )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
const auto zoneCnt = s_luaZoneState.counter++;
|
||||
if( zoneCnt != 0 && !s_luaZoneState.active ) return 0;
|
||||
s_luaZoneState.active = s_profiler.IsConnected();
|
||||
s_luaZoneState.active = GetProfiler().IsConnected();
|
||||
if( !s_luaZoneState.active ) return 0;
|
||||
#endif
|
||||
|
||||
@ -184,7 +184,7 @@ static inline int LuaZoneBeginN( lua_State* L )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
const auto zoneCnt = s_luaZoneState.counter++;
|
||||
if( zoneCnt != 0 && !s_luaZoneState.active ) return 0;
|
||||
s_luaZoneState.active = s_profiler.IsConnected();
|
||||
s_luaZoneState.active = GetProfiler().IsConnected();
|
||||
if( !s_luaZoneState.active ) return 0;
|
||||
#endif
|
||||
|
||||
@ -243,7 +243,7 @@ static inline int LuaZoneEnd( lua_State* L )
|
||||
assert( s_luaZoneState.counter != 0 );
|
||||
s_luaZoneState.counter--;
|
||||
if( !s_luaZoneState.active ) return 0;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
s_luaZoneState.active = false;
|
||||
return 0;
|
||||
@ -271,7 +271,7 @@ static inline int LuaZoneText( lua_State* L )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_luaZoneState.active ) return 0;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
s_luaZoneState.active = false;
|
||||
return 0;
|
||||
@ -299,7 +299,7 @@ static inline int LuaZoneName( lua_State* L )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_luaZoneState.active ) return 0;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
s_luaZoneState.active = false;
|
||||
return 0;
|
||||
@ -326,7 +326,7 @@ static inline int LuaZoneName( lua_State* L )
|
||||
static inline int LuaMessage( lua_State* L )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return 0;
|
||||
if( !GetProfiler().IsConnected() ) return 0;
|
||||
#endif
|
||||
|
||||
auto txt = lua_tostring( L, 1 );
|
||||
|
@ -108,7 +108,7 @@ public:
|
||||
MemWrite( &item->gpuNewContext.accuracyBits, (uint8_t)bits );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -121,7 +121,7 @@ public:
|
||||
if( m_tail == m_head ) return;
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
return;
|
||||
@ -201,7 +201,7 @@ class GpuCtxScope
|
||||
public:
|
||||
tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
: m_active( s_profiler.IsConnected() )
|
||||
: m_active( GetProfiler().IsConnected() )
|
||||
#endif
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
@ -225,7 +225,7 @@ public:
|
||||
|
||||
tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc, int depth )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
: m_active( s_profiler.IsConnected() )
|
||||
: m_active( GetProfiler().IsConnected() )
|
||||
#endif
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
@ -248,7 +248,7 @@ public:
|
||||
MemWrite( &item->gpuZoneBegin.context, s_gpuCtx.ptr->GetId() );
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
|
||||
s_profiler.SendCallstack( depth, thread );
|
||||
GetProfiler().SendCallstack( depth, thread );
|
||||
}
|
||||
|
||||
tracy_force_inline ~GpuCtxScope()
|
||||
|
@ -108,7 +108,7 @@ public:
|
||||
MemWrite( &item->gpuNewContext.accuracyBits, uint8_t( 0 ) );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -126,7 +126,7 @@ public:
|
||||
if( m_tail == m_head ) return;
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount );
|
||||
m_head = m_tail = 0;
|
||||
@ -203,7 +203,7 @@ public:
|
||||
: m_cmdbuf( cmdbuf )
|
||||
, m_ctx( ctx )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
, m_active( s_profiler.IsConnected() )
|
||||
, m_active( GetProfiler().IsConnected() )
|
||||
#endif
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
@ -229,7 +229,7 @@ public:
|
||||
: m_cmdbuf( cmdbuf )
|
||||
, m_ctx( ctx )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
, m_active( s_profiler.IsConnected() )
|
||||
, m_active( GetProfiler().IsConnected() )
|
||||
#endif
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
@ -252,7 +252,7 @@ public:
|
||||
MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
|
||||
s_profiler.SendCallstack( depth, thread );
|
||||
GetProfiler().SendCallstack( depth, thread );
|
||||
}
|
||||
|
||||
tracy_force_inline ~VkCtxScope()
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
MemWrite( &item->lockAnnounce.type, LockType::Lockable );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -58,7 +58,7 @@ public:
|
||||
MemWrite( &item->lockTerminate.type, LockType::Lockable );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -72,7 +72,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -118,7 +118,7 @@ public:
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
m_lockCount.fetch_sub( 1, std::memory_order_relaxed );
|
||||
if( !m_active.load( std::memory_order_relaxed ) ) return;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
m_active.store( false, std::memory_order_relaxed );
|
||||
return;
|
||||
@ -148,7 +148,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -176,7 +176,7 @@ public:
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( !active ) return;
|
||||
const auto connected = s_profiler.IsConnected();
|
||||
const auto connected = GetProfiler().IsConnected();
|
||||
if( !connected )
|
||||
{
|
||||
if( active ) m_active.store( false, std::memory_order_relaxed );
|
||||
@ -230,7 +230,7 @@ public:
|
||||
MemWrite( &item->lockAnnounce.type, LockType::SharedLockable );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -251,7 +251,7 @@ public:
|
||||
MemWrite( &item->lockTerminate.type, LockType::SharedLockable );
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.DeferItem( *item );
|
||||
GetProfiler().DeferItem( *item );
|
||||
#endif
|
||||
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
@ -265,7 +265,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -311,7 +311,7 @@ public:
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
m_lockCount.fetch_sub( 1, std::memory_order_relaxed );
|
||||
if( !m_active.load( std::memory_order_relaxed ) ) return;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
m_active.store( false, std::memory_order_relaxed );
|
||||
return;
|
||||
@ -341,7 +341,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -372,7 +372,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -418,7 +418,7 @@ public:
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
m_lockCount.fetch_sub( 1, std::memory_order_relaxed );
|
||||
if( !m_active.load( std::memory_order_relaxed ) ) return;
|
||||
if( !s_profiler.IsConnected() )
|
||||
if( !GetProfiler().IsConnected() )
|
||||
{
|
||||
m_active.store( false, std::memory_order_relaxed );
|
||||
return;
|
||||
@ -448,7 +448,7 @@ public:
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( locks == 0 || active )
|
||||
{
|
||||
const bool connected = s_profiler.IsConnected();
|
||||
const bool connected = GetProfiler().IsConnected();
|
||||
if( active != connected ) m_active.store( connected, std::memory_order_relaxed );
|
||||
if( connected ) queue = true;
|
||||
}
|
||||
@ -476,7 +476,7 @@ public:
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
const auto active = m_active.load( std::memory_order_relaxed );
|
||||
if( !active ) return;
|
||||
const auto connected = s_profiler.IsConnected();
|
||||
const auto connected = GetProfiler().IsConnected();
|
||||
if( !connected )
|
||||
{
|
||||
if( active ) m_active.store( false, std::memory_order_relaxed );
|
||||
|
@ -438,7 +438,7 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
|
||||
item->crashReport.text = (uint64_t)s_crashText;
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
|
||||
s_profiler.SendCallstack( 60, thread, "KiUserExceptionDispatcher" );
|
||||
GetProfiler().SendCallstack( 60, thread, "KiUserExceptionDispatcher" );
|
||||
}
|
||||
|
||||
HANDLE h = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
|
||||
@ -479,8 +479,8 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
|
||||
s_profiler.RequestShutdown();
|
||||
while( !s_profiler.HasShutdownFinished() ) { std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); };
|
||||
GetProfiler().RequestShutdown();
|
||||
while( !GetProfiler().HasShutdownFinished() ) { std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); };
|
||||
|
||||
TerminateProcess( GetCurrentProcess(), 1 );
|
||||
|
||||
@ -676,7 +676,7 @@ static void CrashHandler( int signal, siginfo_t* info, void* ucontext )
|
||||
item->crashReport.text = (uint64_t)s_crashText;
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
|
||||
s_profiler.SendCallstack( 60, thread, "__kernel_rt_sigreturn" );
|
||||
GetProfiler().SendCallstack( 60, thread, "__kernel_rt_sigreturn" );
|
||||
}
|
||||
|
||||
DIR* dp = opendir( "/proc/self/task" );
|
||||
@ -706,8 +706,8 @@ static void CrashHandler( int signal, siginfo_t* info, void* ucontext )
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
|
||||
s_profiler.RequestShutdown();
|
||||
while( !s_profiler.HasShutdownFinished() ) { std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); };
|
||||
GetProfiler().RequestShutdown();
|
||||
while( !GetProfiler().HasShutdownFinished() ) { std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); };
|
||||
|
||||
abort();
|
||||
}
|
||||
@ -759,8 +759,7 @@ std::atomic<ThreadNameData*>& s_threadNameData = s_threadNameDataInstance;
|
||||
thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false };
|
||||
#endif
|
||||
|
||||
static Profiler init_order(105) s_profilerInstance;
|
||||
Profiler& s_profiler = s_profilerInstance;
|
||||
static Profiler init_order(105) s_profiler;
|
||||
|
||||
#ifdef _WIN32
|
||||
# define DLL_EXPORT __declspec(dllexport)
|
||||
@ -774,6 +773,11 @@ tracy::moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken()
|
||||
return s_token.ptr;
|
||||
}
|
||||
|
||||
Profiler& GetProfiler()
|
||||
{
|
||||
return s_profiler;
|
||||
}
|
||||
|
||||
// DLL exports to enable TracyClientDLL.cpp to retrieve the instances of Tracy objects and functions
|
||||
|
||||
DLL_EXPORT void*(*get_rpmalloc())(size_t size)
|
||||
@ -786,6 +790,7 @@ DLL_EXPORT void(*get_rpfree())(void* ptr)
|
||||
return rpfree;
|
||||
}
|
||||
|
||||
|
||||
#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6
|
||||
DLL_EXPORT int64_t(*get_GetTimeImpl())()
|
||||
{
|
||||
@ -793,11 +798,6 @@ DLL_EXPORT int64_t(*get_GetTimeImpl())()
|
||||
}
|
||||
#endif
|
||||
|
||||
DLL_EXPORT Profiler& get_profiler()
|
||||
{
|
||||
return s_profiler;
|
||||
}
|
||||
|
||||
#ifdef TRACY_COLLECT_THREAD_NAMES
|
||||
DLL_EXPORT std::atomic<ThreadNameData*>& get_threadNameData()
|
||||
{
|
||||
@ -1767,13 +1767,13 @@ TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_da
|
||||
{
|
||||
___tracy_c_zone_context ctx;
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
ctx.active = active && tracy::s_profiler.IsConnected();
|
||||
ctx.active = active && tracy::GetProfiler().IsConnected();
|
||||
#else
|
||||
ctx.active = active;
|
||||
#endif
|
||||
if( !ctx.active ) return ctx;
|
||||
const auto thread = tracy::GetThreadHandle();
|
||||
const auto id = tracy::s_profiler.GetNextZoneId();
|
||||
const auto id = tracy::GetProfiler().GetNextZoneId();
|
||||
ctx.id = id;
|
||||
|
||||
tracy::Magic magic;
|
||||
@ -1809,13 +1809,13 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
|
||||
{
|
||||
___tracy_c_zone_context ctx;
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
ctx.active = active && tracy::s_profiler.IsConnected();
|
||||
ctx.active = active && tracy::GetProfiler().IsConnected();
|
||||
#else
|
||||
ctx.active = active;
|
||||
#endif
|
||||
if( !ctx.active ) return ctx;
|
||||
const auto thread = tracy::GetThreadHandle();
|
||||
const auto id = tracy::s_profiler.GetNextZoneId();
|
||||
const auto id = tracy::GetProfiler().GetNextZoneId();
|
||||
ctx.id = id;
|
||||
|
||||
tracy::Magic magic;
|
||||
@ -1845,7 +1845,7 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
}
|
||||
|
||||
tracy::s_profiler.SendCallstack( depth, thread );
|
||||
tracy::GetProfiler().SendCallstack( depth, thread );
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class Profiler;
|
||||
class Socket;
|
||||
|
||||
struct SourceLocationData
|
||||
@ -52,6 +53,7 @@ struct SourceLocationData
|
||||
};
|
||||
|
||||
tracy::moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken();
|
||||
Profiler& GetProfiler();
|
||||
|
||||
class GpuCtx;
|
||||
struct GpuCtxWrapper
|
||||
@ -73,8 +75,6 @@ using Magic = tracy::moodycamel::ConcurrentQueueDefaultTraits::index_t;
|
||||
extern int64_t (*GetTimeImpl)();
|
||||
#endif
|
||||
|
||||
class Profiler;
|
||||
extern Profiler& s_profiler;
|
||||
|
||||
class Profiler
|
||||
{
|
||||
@ -129,8 +129,8 @@ public:
|
||||
static tracy_force_inline void SendFrameMark()
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
s_profiler.m_frameCount.fetch_add( 1, std::memory_order_relaxed );
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
GetProfiler().m_frameCount.fetch_add( 1, std::memory_order_relaxed );
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -146,7 +146,7 @@ public:
|
||||
{
|
||||
assert( type == QueueType::FrameMarkMsg || type == QueueType::FrameMarkMsgStart || type == QueueType::FrameMarkMsgEnd );
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -161,7 +161,7 @@ public:
|
||||
static tracy_force_inline void PlotData( const char* name, int64_t val )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -178,7 +178,7 @@ public:
|
||||
static tracy_force_inline void PlotData( const char* name, float val )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -195,7 +195,7 @@ public:
|
||||
static tracy_force_inline void PlotData( const char* name, double val )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -212,7 +212,7 @@ public:
|
||||
static tracy_force_inline void Message( const char* txt, size_t size )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -231,7 +231,7 @@ public:
|
||||
static tracy_force_inline void Message( const char* txt )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
Magic magic;
|
||||
auto token = GetToken();
|
||||
@ -247,42 +247,42 @@ public:
|
||||
static tracy_force_inline void MemAlloc( const void* ptr, size_t size )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
s_profiler.m_serialLock.lock();
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendMemAlloc( QueueType::MemAlloc, thread, ptr, size );
|
||||
s_profiler.m_serialLock.unlock();
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
}
|
||||
|
||||
static tracy_force_inline void MemFree( const void* ptr )
|
||||
{
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
s_profiler.m_serialLock.lock();
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendMemFree( QueueType::MemFree, thread, ptr );
|
||||
s_profiler.m_serialLock.unlock();
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
}
|
||||
|
||||
static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth )
|
||||
{
|
||||
#ifdef TRACY_HAS_CALLSTACK
|
||||
# ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
# endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
rpmalloc_thread_initialize();
|
||||
auto callstack = Callstack( depth );
|
||||
|
||||
s_profiler.m_serialLock.lock();
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
|
||||
SendCallstackMemory( callstack );
|
||||
s_profiler.m_serialLock.unlock();
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
#else
|
||||
MemAlloc( ptr, size );
|
||||
#endif
|
||||
@ -292,17 +292,17 @@ public:
|
||||
{
|
||||
#ifdef TRACY_HAS_CALLSTACK
|
||||
# ifdef TRACY_ON_DEMAND
|
||||
if( !s_profiler.IsConnected() ) return;
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
# endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
rpmalloc_thread_initialize();
|
||||
auto callstack = Callstack( depth );
|
||||
|
||||
s_profiler.m_serialLock.lock();
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
|
||||
SendCallstackMemory( callstack );
|
||||
s_profiler.m_serialLock.unlock();
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
#else
|
||||
MemFree( ptr );
|
||||
#endif
|
||||
@ -379,10 +379,10 @@ private:
|
||||
static tracy_force_inline void SendCallstackMemory( void* ptr )
|
||||
{
|
||||
#ifdef TRACY_HAS_CALLSTACK
|
||||
auto item = s_profiler.m_serialQueue.prepare_next();
|
||||
auto item = GetProfiler().m_serialQueue.prepare_next();
|
||||
MemWrite( &item->hdr.type, QueueType::CallstackMemory );
|
||||
MemWrite( &item->callstackMemory.ptr, (uint64_t)ptr );
|
||||
s_profiler.m_serialQueue.commit_next();
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ private:
|
||||
{
|
||||
assert( type == QueueType::MemAlloc || type == QueueType::MemAllocCallstack );
|
||||
|
||||
auto item = s_profiler.m_serialQueue.prepare_next();
|
||||
auto item = GetProfiler().m_serialQueue.prepare_next();
|
||||
MemWrite( &item->hdr.type, type );
|
||||
MemWrite( &item->memAlloc.time, GetTime() );
|
||||
MemWrite( &item->memAlloc.thread, thread );
|
||||
@ -405,19 +405,19 @@ private:
|
||||
assert( sizeof( size ) == 8 );
|
||||
memcpy( &item->memAlloc.size, &size, 6 );
|
||||
}
|
||||
s_profiler.m_serialQueue.commit_next();
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendMemFree( QueueType type, const uint64_t thread, const void* ptr )
|
||||
{
|
||||
assert( type == QueueType::MemFree || type == QueueType::MemFreeCallstack );
|
||||
|
||||
auto item = s_profiler.m_serialQueue.prepare_next();
|
||||
auto item = GetProfiler().m_serialQueue.prepare_next();
|
||||
MemWrite( &item->hdr.type, type );
|
||||
MemWrite( &item->memFree.time, GetTime() );
|
||||
MemWrite( &item->memFree.thread, thread );
|
||||
MemWrite( &item->memFree.ptr, (uint64_t)ptr );
|
||||
s_profiler.m_serialQueue.commit_next();
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
}
|
||||
|
||||
double m_timerMul;
|
||||
|
@ -17,7 +17,7 @@ class ScopedZone
|
||||
public:
|
||||
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
: m_active( is_active && s_profiler.IsConnected() )
|
||||
: m_active( is_active && GetProfiler().IsConnected() )
|
||||
#else
|
||||
: m_active( is_active )
|
||||
#endif
|
||||
@ -44,7 +44,7 @@ public:
|
||||
|
||||
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
: m_active( is_active && s_profiler.IsConnected() )
|
||||
: m_active( is_active && GetProfiler().IsConnected() )
|
||||
#else
|
||||
: m_active( is_active )
|
||||
#endif
|
||||
@ -68,7 +68,7 @@ public:
|
||||
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
||||
tail.store( magic + 1, std::memory_order_release );
|
||||
|
||||
s_profiler.SendCallstack( depth, thread );
|
||||
GetProfiler().SendCallstack( depth, thread );
|
||||
}
|
||||
|
||||
tracy_force_inline ~ScopedZone()
|
||||
|
Loading…
x
Reference in New Issue
Block a user