1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +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,7 +513,7 @@ 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;
@ -526,10 +526,9 @@ public:
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,7 +539,7 @@ 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;
@ -553,10 +552,9 @@ public:
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,7 +588,7 @@ 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;
@ -604,16 +602,15 @@ public:
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;
@ -627,10 +624,9 @@ public:
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,7 +645,7 @@ 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
@ -661,22 +657,19 @@ public:
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 )
@ -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 )