1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 12:23:53 +00:00

Replace #ifdef TRACT_HAS_CALLSTACK with constexpr call

This commit is contained in:
Igor S. Gerasimov 2024-12-27 10:12:55 +01:00
parent cf912bbb19
commit e9eecbb2c6

View File

@ -513,23 +513,22 @@ public:
static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth, bool secure ) static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth, bool secure )
{ {
if( secure && !ProfilerAvailable() ) return; if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
auto& profiler = GetProfiler(); auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND # ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return; if( !profiler.IsConnected() ) return;
# endif # endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto callstack = Callstack( depth ); auto callstack = Callstack( depth );
profiler.m_serialLock.lock(); profiler.m_serialLock.lock();
SendCallstackSerial( callstack ); SendCallstackSerial( callstack );
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size ); SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
profiler.m_serialLock.unlock(); profiler.m_serialLock.unlock();
#else } else {
static_cast<void>(depth); // unused MemAlloc( ptr, size, secure );
MemAlloc( ptr, size, secure ); }
#endif
} }
static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth, bool secure ) static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth, bool secure )
@ -540,23 +539,22 @@ public:
MemFree( ptr, secure ); MemFree( ptr, secure );
return; return;
} }
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
auto& profiler = GetProfiler(); auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND # ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return; if( !profiler.IsConnected() ) return;
# endif # endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto callstack = Callstack( depth ); auto callstack = Callstack( depth );
profiler.m_serialLock.lock(); profiler.m_serialLock.lock();
SendCallstackSerial( callstack ); SendCallstackSerial( callstack );
SendMemFree( QueueType::MemFreeCallstack, thread, ptr ); SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
profiler.m_serialLock.unlock(); profiler.m_serialLock.unlock();
#else } else {
static_cast<void>(depth); // unused MemFree( ptr, secure );
MemFree( ptr, secure ); }
#endif
} }
static tracy_force_inline void MemAllocNamed( const void* ptr, size_t size, bool secure, const char* name ) static tracy_force_inline void MemAllocNamed( const void* ptr, size_t size, bool secure, const char* name )
@ -590,47 +588,45 @@ public:
static tracy_force_inline void MemAllocCallstackNamed( const void* ptr, size_t size, int depth, bool secure, const char* name ) static tracy_force_inline void MemAllocCallstackNamed( const void* ptr, size_t size, int depth, bool secure, const char* name )
{ {
if( secure && !ProfilerAvailable() ) return; if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
auto& profiler = GetProfiler(); auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND # ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return; if( !profiler.IsConnected() ) return;
# endif # endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto callstack = Callstack( depth ); auto callstack = Callstack( depth );
profiler.m_serialLock.lock(); profiler.m_serialLock.lock();
SendCallstackSerial( callstack ); SendCallstackSerial( callstack );
SendMemName( name ); SendMemName( name );
SendMemAlloc( QueueType::MemAllocCallstackNamed, thread, ptr, size ); SendMemAlloc( QueueType::MemAllocCallstackNamed, thread, ptr, size );
profiler.m_serialLock.unlock(); profiler.m_serialLock.unlock();
#else } else {
static_cast<void>(depth); // unused MemAllocNamed( ptr, size, secure, name );
MemAllocNamed( ptr, size, secure, name ); }
#endif
} }
static tracy_force_inline void MemFreeCallstackNamed( const void* ptr, int depth, bool secure, const char* name ) static tracy_force_inline void MemFreeCallstackNamed( const void* ptr, int depth, bool secure, const char* name )
{ {
if( secure && !ProfilerAvailable() ) return; if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
auto& profiler = GetProfiler(); auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND # ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return; if( !profiler.IsConnected() ) return;
# endif # endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto callstack = Callstack( depth ); auto callstack = Callstack( depth );
profiler.m_serialLock.lock(); profiler.m_serialLock.lock();
SendCallstackSerial( callstack ); SendCallstackSerial( callstack );
SendMemName( name ); SendMemName( name );
SendMemFree( QueueType::MemFreeCallstackNamed, thread, ptr ); SendMemFree( QueueType::MemFreeCallstackNamed, thread, ptr );
profiler.m_serialLock.unlock(); profiler.m_serialLock.unlock();
#else } else {
static_cast<void>(depth); // unused MemFreeNamed( ptr, secure, name );
MemFreeNamed( ptr, secure, name ); }
#endif
} }
static tracy_force_inline void MemDiscard( const char* name, bool secure ) static tracy_force_inline void MemDiscard( const char* name, bool secure )
@ -649,34 +645,31 @@ public:
static tracy_force_inline void MemDiscardCallstack( const char* name, bool secure, int depth ) static tracy_force_inline void MemDiscardCallstack( const char* name, bool secure, int depth )
{ {
if( secure && !ProfilerAvailable() ) return; if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
# ifdef TRACY_ON_DEMAND # ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
# endif # endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto callstack = Callstack( depth ); auto callstack = Callstack( depth );
GetProfiler().m_serialLock.lock(); GetProfiler().m_serialLock.lock();
SendCallstackSerial( callstack ); SendCallstackSerial( callstack );
SendMemDiscard( QueueType::MemDiscard, thread, name ); SendMemDiscard( QueueType::MemDiscard, thread, name );
GetProfiler().m_serialLock.unlock(); GetProfiler().m_serialLock.unlock();
#else } else {
static_cast<void>(depth); // unused MemDiscard( name, secure );
MemDiscard( name, secure ); }
#endif
} }
static tracy_force_inline void SendCallstack( int depth ) static tracy_force_inline void SendCallstack( int depth )
{ {
#ifdef TRACY_HAS_CALLSTACK if (depth > 0 && has_stacktrace()) {
auto ptr = Callstack( depth ); auto ptr = Callstack( depth );
TracyQueuePrepare( QueueType::Callstack ); TracyQueuePrepare( QueueType::Callstack );
MemWrite( &item->callstackFat.ptr, (uint64_t)ptr ); MemWrite( &item->callstackFat.ptr, (uint64_t)ptr );
TracyQueueCommit( callstackFatThread ); TracyQueueCommit( callstackFatThread );
#else }
static_cast<void>(depth); // unused
#endif
} }
static tracy_force_inline void ParameterRegister( ParameterCallback cb, void* data ) static tracy_force_inline void ParameterRegister( ParameterCallback cb, void* data )
@ -834,7 +827,7 @@ private:
void InstallCrashHandler(); void InstallCrashHandler();
void RemoveCrashHandler(); void RemoveCrashHandler();
void ClearQueues( tracy::moodycamel::ConsumerToken& token ); void ClearQueues( tracy::moodycamel::ConsumerToken& token );
void ClearSerial(); void ClearSerial();
DequeueStatus Dequeue( tracy::moodycamel::ConsumerToken& token ); DequeueStatus Dequeue( tracy::moodycamel::ConsumerToken& token );
@ -911,14 +904,12 @@ private:
static tracy_force_inline void SendCallstackSerial( void* ptr ) static tracy_force_inline void SendCallstackSerial( void* ptr )
{ {
#ifdef TRACY_HAS_CALLSTACK if (has_stacktrace()) {
auto item = GetProfiler().m_serialQueue.prepare_next(); auto item = GetProfiler().m_serialQueue.prepare_next();
MemWrite( &item->hdr.type, QueueType::CallstackSerial ); MemWrite( &item->hdr.type, QueueType::CallstackSerial );
MemWrite( &item->callstackFat.ptr, (uint64_t)ptr ); MemWrite( &item->callstackFat.ptr, (uint64_t)ptr );
GetProfiler().m_serialQueue.commit_next(); GetProfiler().m_serialQueue.commit_next();
#else }
static_cast<void>(ptr); // unused
#endif
} }
static tracy_force_inline void SendMemAlloc( QueueType type, const uint32_t thread, const void* ptr, size_t size ) static tracy_force_inline void SendMemAlloc( QueueType type, const uint32_t thread, const void* ptr, size_t size )