1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Disable all tracing if TRACY_ON_DEMAND is defined.

This commit is contained in:
Bartosz Taudul
2018-07-10 20:42:30 +02:00
parent a5381337f6
commit e5b133073c
6 changed files with 94 additions and 0 deletions
+32
View File
@@ -22,6 +22,7 @@ public:
{
assert( m_id != std::numeric_limits<uint32_t>::max() );
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -31,6 +32,7 @@ public:
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
MemWrite( &item->lockAnnounce.type, LockType::Lockable );
tail.store( magic + 1, std::memory_order_release );
#endif
}
Lockable( const Lockable& ) = delete;
@@ -38,6 +40,7 @@ public:
tracy_force_inline void lock()
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
{
Magic magic;
@@ -51,9 +54,11 @@ public:
MemWrite( &item->lockWait.type, LockType::Lockable );
tail.store( magic + 1, std::memory_order_release );
}
#endif
m_lockable.lock();
#ifndef TRACY_ON_DEMAND
{
Magic magic;
auto& token = s_token.ptr;
@@ -65,12 +70,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
}
tracy_force_inline void unlock()
{
m_lockable.unlock();
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -80,11 +87,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline bool try_lock()
{
const auto ret = m_lockable.try_lock();
#ifndef TRACY_ON_DEMAND
if( ret )
{
Magic magic;
@@ -97,11 +106,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
return ret;
}
tracy_force_inline void Mark( const SourceLocation* srcloc ) const
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -111,6 +122,7 @@ public:
MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release );
#endif
}
private:
@@ -128,6 +140,7 @@ public:
{
assert( m_id != std::numeric_limits<uint32_t>::max() );
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -137,6 +150,7 @@ public:
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
MemWrite( &item->lockAnnounce.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release );
#endif
}
SharedLockable( const SharedLockable& ) = delete;
@@ -144,6 +158,7 @@ public:
tracy_force_inline void lock()
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
{
Magic magic;
@@ -157,9 +172,11 @@ public:
MemWrite( &item->lockWait.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release );
}
#endif
m_lockable.lock();
#ifndef TRACY_ON_DEMAND
{
Magic magic;
auto& token = s_token.ptr;
@@ -171,12 +188,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
}
tracy_force_inline void unlock()
{
m_lockable.unlock();
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -186,11 +205,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline bool try_lock()
{
const auto ret = m_lockable.try_lock();
#ifndef TRACY_ON_DEMAND
if( ret )
{
Magic magic;
@@ -203,11 +224,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
return ret;
}
tracy_force_inline void lock_shared()
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
{
Magic magic;
@@ -221,9 +244,11 @@ public:
MemWrite( &item->lockWait.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release );
}
#endif
m_lockable.lock_shared();
#ifndef TRACY_ON_DEMAND
{
Magic magic;
auto& token = s_token.ptr;
@@ -235,12 +260,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
}
tracy_force_inline void unlock_shared()
{
m_lockable.unlock_shared();
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -250,11 +277,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline bool try_lock_shared()
{
const auto ret = m_lockable.try_lock_shared();
#ifndef TRACY_ON_DEMAND
if( ret )
{
Magic magic;
@@ -267,11 +296,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
#endif
return ret;
}
tracy_force_inline void Mark( const SourceLocation* srcloc ) const
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -281,6 +312,7 @@ public:
MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release );
#endif
}
private:
+20
View File
@@ -118,6 +118,7 @@ public:
static tracy_force_inline void FrameMark()
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -125,10 +126,12 @@ public:
MemWrite( &item->hdr.type, QueueType::FrameMarkMsg );
MemWrite( &item->frameMark.time, GetTime() );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void PlotData( const char* name, int64_t val )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -139,10 +142,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Int );
MemWrite( &item->plotData.data.i, val );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void PlotData( const char* name, float val )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -153,10 +158,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Float );
MemWrite( &item->plotData.data.f, val );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void PlotData( const char* name, double val )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -167,10 +174,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Double );
MemWrite( &item->plotData.data.d, val );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void Message( const char* txt, size_t size )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
@@ -183,10 +192,12 @@ public:
MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void Message( const char* txt )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -196,29 +207,35 @@ public:
MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.text, (uint64_t)txt );
tail.store( magic + 1, std::memory_order_release );
#endif
}
static tracy_force_inline void MemAlloc( const void* ptr, size_t size )
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
s_profiler.m_serialLock.lock();
SendMemAlloc( QueueType::MemAlloc, thread, ptr, size );
s_profiler.m_serialLock.unlock();
#endif
}
static tracy_force_inline void MemFree( const void* ptr )
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
s_profiler.m_serialLock.lock();
SendMemFree( QueueType::MemFree, thread, ptr );
s_profiler.m_serialLock.unlock();
#endif
}
static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth )
{
#ifdef TRACY_HAS_CALLSTACK
# ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
rpmalloc_thread_initialize();
@@ -228,6 +245,7 @@ public:
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock();
# endif
#else
MemAlloc( ptr, size );
#endif
@@ -236,6 +254,7 @@ public:
static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth )
{
#ifdef TRACY_HAS_CALLSTACK
# ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
rpmalloc_thread_initialize();
@@ -245,6 +264,7 @@ public:
SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock();
# endif
#else
MemFree( ptr );
#endif
+10
View File
@@ -17,6 +17,7 @@ class ScopedZone
public:
tracy_force_inline ScopedZone( const SourceLocation* srcloc )
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
m_thread = thread;
Magic magic;
@@ -34,10 +35,12 @@ public:
MemWrite( &item->zoneBegin.thread, thread );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline ScopedZone( const SourceLocation* srcloc, int depth )
{
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle();
m_thread = thread;
Magic magic;
@@ -57,10 +60,12 @@ public:
tail.store( magic + 1, std::memory_order_release );
s_profiler.SendCallstack( depth, thread );
#endif
}
tracy_force_inline ~ScopedZone()
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@@ -75,10 +80,12 @@ public:
#endif
MemWrite( &item->zoneEnd.thread, m_thread );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline void Text( const char* txt, size_t size )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
@@ -90,10 +97,12 @@ public:
MemWrite( &item->zoneText.thread, m_thread );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release );
#endif
}
tracy_force_inline void Name( const char* txt, size_t size )
{
#ifndef TRACY_ON_DEMAND
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
@@ -105,6 +114,7 @@ public:
MemWrite( &item->zoneText.thread, m_thread );
MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release );
#endif
}
private: