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

View File

@ -121,6 +121,7 @@ namespace detail
static inline int LuaZoneBegin( lua_State* L ) static inline int LuaZoneBegin( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
const uint32_t color = Color::DeepSkyBlue3; const uint32_t color = Color::DeepSkyBlue3;
lua_Debug dbg; lua_Debug dbg;
@ -163,11 +164,13 @@ static inline int LuaZoneBegin( lua_State* L )
MemWrite( &item->zoneBegin.thread, GetThreadHandle() ); MemWrite( &item->zoneBegin.thread, GetThreadHandle() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)ptr ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }
static inline int LuaZoneBeginN( lua_State* L ) static inline int LuaZoneBeginN( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
const uint32_t color = Color::DeepSkyBlue3; const uint32_t color = Color::DeepSkyBlue3;
lua_Debug dbg; lua_Debug dbg;
@ -214,11 +217,13 @@ static inline int LuaZoneBeginN( lua_State* L )
MemWrite( &item->zoneBegin.thread, GetThreadHandle() ); MemWrite( &item->zoneBegin.thread, GetThreadHandle() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)ptr ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }
static inline int LuaZoneEnd( lua_State* L ) static inline int LuaZoneEnd( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -233,11 +238,13 @@ static inline int LuaZoneEnd( lua_State* L )
#endif #endif
MemWrite( &item->zoneEnd.thread, GetThreadHandle() ); MemWrite( &item->zoneEnd.thread, GetThreadHandle() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }
static inline int LuaZoneText( lua_State* L ) static inline int LuaZoneText( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
@ -252,11 +259,13 @@ static inline int LuaZoneText( lua_State* L )
MemWrite( &item->zoneText.thread, GetThreadHandle() ); MemWrite( &item->zoneText.thread, GetThreadHandle() );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }
static inline int LuaZoneName( lua_State* L ) static inline int LuaZoneName( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
@ -271,11 +280,13 @@ static inline int LuaZoneName( lua_State* L )
MemWrite( &item->zoneText.thread, GetThreadHandle() ); MemWrite( &item->zoneText.thread, GetThreadHandle() );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }
static inline int LuaMessage( lua_State* L ) static inline int LuaMessage( lua_State* L )
{ {
#ifndef TRACY_ON_DEMAND
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
@ -291,6 +302,7 @@ static inline int LuaMessage( lua_State* L )
MemWrite( &item->message.thread, GetThreadHandle() ); MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.text, (uint64_t)ptr ); MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
return 0; return 0;
} }

View File

@ -65,6 +65,7 @@ public:
GLint bits; GLint bits;
glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits ); glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits );
#ifndef TRACY_ON_DEMAND
const float period = 1.f; const float period = 1.f;
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
@ -78,10 +79,12 @@ public:
MemWrite( &item->gpuNewContext.context, m_context ); MemWrite( &item->gpuNewContext.context, m_context );
MemWrite( &item->gpuNewContext.accuracyBits, (uint8_t)bits ); MemWrite( &item->gpuNewContext.accuracyBits, (uint8_t)bits );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
void Collect() void Collect()
{ {
#ifndef TRACY_ON_DEMAND
ZoneScopedC( Color::Red4 ); ZoneScopedC( Color::Red4 );
auto start = m_tail; auto start = m_tail;
@ -122,6 +125,7 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
m_tail = ( m_tail + 1 ) % QueryCount; m_tail = ( m_tail + 1 ) % QueryCount;
} }
#endif
} }
private: private:
@ -157,6 +161,7 @@ class GpuCtxScope
public: public:
tracy_force_inline GpuCtxScope( const SourceLocation* srcloc ) tracy_force_inline GpuCtxScope( const SourceLocation* srcloc )
{ {
#ifndef TRACY_ON_DEMAND
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = s_gpuCtx.ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@ -171,10 +176,12 @@ public:
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, s_gpuCtx.ptr->GetId() ); MemWrite( &item->gpuZoneBegin.context, s_gpuCtx.ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline GpuCtxScope( const SourceLocation* srcloc, int depth ) tracy_force_inline GpuCtxScope( const SourceLocation* srcloc, int depth )
{ {
#ifndef TRACY_ON_DEMAND
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = s_gpuCtx.ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@ -193,10 +200,12 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
s_profiler.SendCallstack( depth, thread ); s_profiler.SendCallstack( depth, thread );
#endif
} }
tracy_force_inline ~GpuCtxScope() tracy_force_inline ~GpuCtxScope()
{ {
#ifndef TRACY_ON_DEMAND
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = s_gpuCtx.ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@ -209,6 +218,7 @@ public:
MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneEnd.context, s_gpuCtx.ptr->GetId() ); MemWrite( &item->gpuZoneEnd.context, s_gpuCtx.ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
}; };

View File

@ -97,6 +97,7 @@ public:
vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE ); vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
vkQueueWaitIdle( queue ); vkQueueWaitIdle( queue );
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -109,6 +110,7 @@ public:
MemWrite( &item->gpuNewContext.context, m_context ); MemWrite( &item->gpuNewContext.context, m_context );
MemWrite( &item->gpuNewContext.accuracyBits, uint8_t( 0 ) ); MemWrite( &item->gpuNewContext.accuracyBits, uint8_t( 0 ) );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
~VkCtx() ~VkCtx()
@ -118,6 +120,7 @@ public:
void Collect( VkCommandBuffer cmdbuf ) void Collect( VkCommandBuffer cmdbuf )
{ {
#ifndef TRACY_ON_DEMAND
ZoneScopedC( Color::Red4 ); ZoneScopedC( Color::Red4 );
if( m_tail == m_head ) return; if( m_tail == m_head ) return;
@ -158,6 +161,7 @@ public:
m_tail += cnt; m_tail += cnt;
if( m_tail == QueryCount ) m_tail = 0; if( m_tail == QueryCount ) m_tail = 0;
#endif
} }
private: private:
@ -192,6 +196,7 @@ public:
tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf ) tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf )
: m_cmdbuf( cmdbuf ) : m_cmdbuf( cmdbuf )
{ {
#ifndef TRACY_ON_DEMAND
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
const auto queryId = ctx->NextQueryId(); const auto queryId = ctx->NextQueryId();
vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId ); vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );
@ -207,11 +212,13 @@ public:
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, ctx->GetId() ); MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf, int depth ) tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf, int depth )
: m_cmdbuf( cmdbuf ) : m_cmdbuf( cmdbuf )
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
@ -231,10 +238,12 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
s_profiler.SendCallstack( depth, thread ); s_profiler.SendCallstack( depth, thread );
#endif
} }
tracy_force_inline ~VkCtxScope() tracy_force_inline ~VkCtxScope()
{ {
#ifndef TRACY_ON_DEMAND
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
const auto queryId = ctx->NextQueryId(); const auto queryId = ctx->NextQueryId();
vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId ); vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );
@ -248,6 +257,7 @@ public:
MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneEnd.context, ctx->GetId() ); MemWrite( &item->gpuZoneEnd.context, ctx->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
private: private:

View File

@ -22,6 +22,7 @@ public:
{ {
assert( m_id != std::numeric_limits<uint32_t>::max() ); assert( m_id != std::numeric_limits<uint32_t>::max() );
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -31,6 +32,7 @@ public:
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
MemWrite( &item->lockAnnounce.type, LockType::Lockable ); MemWrite( &item->lockAnnounce.type, LockType::Lockable );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
Lockable( const Lockable& ) = delete; Lockable( const Lockable& ) = delete;
@ -38,6 +40,7 @@ public:
tracy_force_inline void lock() tracy_force_inline void lock()
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
{ {
Magic magic; Magic magic;
@ -51,9 +54,11 @@ public:
MemWrite( &item->lockWait.type, LockType::Lockable ); MemWrite( &item->lockWait.type, LockType::Lockable );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
m_lockable.lock(); m_lockable.lock();
#ifndef TRACY_ON_DEMAND
{ {
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
@ -65,12 +70,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
} }
tracy_force_inline void unlock() tracy_force_inline void unlock()
{ {
m_lockable.unlock(); m_lockable.unlock();
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -80,11 +87,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() ); MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() ); MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline bool try_lock() tracy_force_inline bool try_lock()
{ {
const auto ret = m_lockable.try_lock(); const auto ret = m_lockable.try_lock();
#ifndef TRACY_ON_DEMAND
if( ret ) if( ret )
{ {
Magic magic; Magic magic;
@ -97,11 +106,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
return ret; return ret;
} }
tracy_force_inline void Mark( const SourceLocation* srcloc ) const tracy_force_inline void Mark( const SourceLocation* srcloc ) const
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -111,6 +122,7 @@ public:
MemWrite( &item->lockMark.thread, GetThreadHandle() ); MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc ); MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
private: private:
@ -128,6 +140,7 @@ public:
{ {
assert( m_id != std::numeric_limits<uint32_t>::max() ); assert( m_id != std::numeric_limits<uint32_t>::max() );
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -137,6 +150,7 @@ public:
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
MemWrite( &item->lockAnnounce.type, LockType::SharedLockable ); MemWrite( &item->lockAnnounce.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
SharedLockable( const SharedLockable& ) = delete; SharedLockable( const SharedLockable& ) = delete;
@ -144,6 +158,7 @@ public:
tracy_force_inline void lock() tracy_force_inline void lock()
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
{ {
Magic magic; Magic magic;
@ -157,9 +172,11 @@ public:
MemWrite( &item->lockWait.type, LockType::SharedLockable ); MemWrite( &item->lockWait.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
m_lockable.lock(); m_lockable.lock();
#ifndef TRACY_ON_DEMAND
{ {
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
@ -171,12 +188,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
} }
tracy_force_inline void unlock() tracy_force_inline void unlock()
{ {
m_lockable.unlock(); m_lockable.unlock();
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -186,11 +205,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() ); MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() ); MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline bool try_lock() tracy_force_inline bool try_lock()
{ {
const auto ret = m_lockable.try_lock(); const auto ret = m_lockable.try_lock();
#ifndef TRACY_ON_DEMAND
if( ret ) if( ret )
{ {
Magic magic; Magic magic;
@ -203,11 +224,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
return ret; return ret;
} }
tracy_force_inline void lock_shared() tracy_force_inline void lock_shared()
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
{ {
Magic magic; Magic magic;
@ -221,9 +244,11 @@ public:
MemWrite( &item->lockWait.type, LockType::SharedLockable ); MemWrite( &item->lockWait.type, LockType::SharedLockable );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
m_lockable.lock_shared(); m_lockable.lock_shared();
#ifndef TRACY_ON_DEMAND
{ {
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
@ -235,12 +260,14 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
} }
tracy_force_inline void unlock_shared() tracy_force_inline void unlock_shared()
{ {
m_lockable.unlock_shared(); m_lockable.unlock_shared();
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -250,11 +277,13 @@ public:
MemWrite( &item->lockRelease.thread, GetThreadHandle() ); MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.time, Profiler::GetTime() ); MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline bool try_lock_shared() tracy_force_inline bool try_lock_shared()
{ {
const auto ret = m_lockable.try_lock_shared(); const auto ret = m_lockable.try_lock_shared();
#ifndef TRACY_ON_DEMAND
if( ret ) if( ret )
{ {
Magic magic; Magic magic;
@ -267,11 +296,13 @@ public:
MemWrite( &item->lockObtain.time, Profiler::GetTime() ); MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
#endif
return ret; return ret;
} }
tracy_force_inline void Mark( const SourceLocation* srcloc ) const tracy_force_inline void Mark( const SourceLocation* srcloc ) const
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -281,6 +312,7 @@ public:
MemWrite( &item->lockMark.thread, GetThreadHandle() ); MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc ); MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
private: private:

View File

@ -118,6 +118,7 @@ public:
static tracy_force_inline void FrameMark() static tracy_force_inline void FrameMark()
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -125,10 +126,12 @@ public:
MemWrite( &item->hdr.type, QueueType::FrameMarkMsg ); MemWrite( &item->hdr.type, QueueType::FrameMarkMsg );
MemWrite( &item->frameMark.time, GetTime() ); MemWrite( &item->frameMark.time, GetTime() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void PlotData( const char* name, int64_t val ) static tracy_force_inline void PlotData( const char* name, int64_t val )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -139,10 +142,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Int ); MemWrite( &item->plotData.type, PlotDataType::Int );
MemWrite( &item->plotData.data.i, val ); MemWrite( &item->plotData.data.i, val );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void PlotData( const char* name, float val ) static tracy_force_inline void PlotData( const char* name, float val )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -153,10 +158,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Float ); MemWrite( &item->plotData.type, PlotDataType::Float );
MemWrite( &item->plotData.data.f, val ); MemWrite( &item->plotData.data.f, val );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void PlotData( const char* name, double val ) static tracy_force_inline void PlotData( const char* name, double val )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -167,10 +174,12 @@ public:
MemWrite( &item->plotData.type, PlotDataType::Double ); MemWrite( &item->plotData.type, PlotDataType::Double );
MemWrite( &item->plotData.data.d, val ); MemWrite( &item->plotData.data.d, val );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void Message( const char* txt, size_t size ) static tracy_force_inline void Message( const char* txt, size_t size )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
@ -183,10 +192,12 @@ public:
MemWrite( &item->message.thread, GetThreadHandle() ); MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.text, (uint64_t)ptr ); MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void Message( const char* txt ) static tracy_force_inline void Message( const char* txt )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -196,29 +207,35 @@ public:
MemWrite( &item->message.thread, GetThreadHandle() ); MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.text, (uint64_t)txt ); MemWrite( &item->message.text, (uint64_t)txt );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) static tracy_force_inline void MemAlloc( const void* ptr, size_t size )
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
s_profiler.m_serialLock.lock(); s_profiler.m_serialLock.lock();
SendMemAlloc( QueueType::MemAlloc, thread, ptr, size ); SendMemAlloc( QueueType::MemAlloc, thread, ptr, size );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
#endif
} }
static tracy_force_inline void MemFree( const void* ptr ) static tracy_force_inline void MemFree( const void* ptr )
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
s_profiler.m_serialLock.lock(); s_profiler.m_serialLock.lock();
SendMemFree( QueueType::MemFree, thread, ptr ); SendMemFree( QueueType::MemFree, thread, ptr );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
#endif
} }
static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth ) static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth )
{ {
#ifdef TRACY_HAS_CALLSTACK #ifdef TRACY_HAS_CALLSTACK
# ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
@ -228,6 +245,7 @@ public:
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size ); SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
SendCallstackMemory( callstack ); SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
# endif
#else #else
MemAlloc( ptr, size ); MemAlloc( ptr, size );
#endif #endif
@ -236,6 +254,7 @@ public:
static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth ) static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth )
{ {
#ifdef TRACY_HAS_CALLSTACK #ifdef TRACY_HAS_CALLSTACK
# ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
@ -245,6 +264,7 @@ public:
SendMemFree( QueueType::MemFreeCallstack, thread, ptr ); SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
SendCallstackMemory( callstack ); SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
# endif
#else #else
MemFree( ptr ); MemFree( ptr );
#endif #endif

View File

@ -17,6 +17,7 @@ class ScopedZone
public: public:
tracy_force_inline ScopedZone( const SourceLocation* srcloc ) tracy_force_inline ScopedZone( const SourceLocation* srcloc )
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
m_thread = thread; m_thread = thread;
Magic magic; Magic magic;
@ -34,10 +35,12 @@ public:
MemWrite( &item->zoneBegin.thread, thread ); MemWrite( &item->zoneBegin.thread, thread );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline ScopedZone( const SourceLocation* srcloc, int depth ) tracy_force_inline ScopedZone( const SourceLocation* srcloc, int depth )
{ {
#ifndef TRACY_ON_DEMAND
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
m_thread = thread; m_thread = thread;
Magic magic; Magic magic;
@ -57,10 +60,12 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
s_profiler.SendCallstack( depth, thread ); s_profiler.SendCallstack( depth, thread );
#endif
} }
tracy_force_inline ~ScopedZone() tracy_force_inline ~ScopedZone()
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto& tail = token->get_tail_index(); auto& tail = token->get_tail_index();
@ -75,10 +80,12 @@ public:
#endif #endif
MemWrite( &item->zoneEnd.thread, m_thread ); MemWrite( &item->zoneEnd.thread, m_thread );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline void Text( const char* txt, size_t size ) tracy_force_inline void Text( const char* txt, size_t size )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
@ -90,10 +97,12 @@ public:
MemWrite( &item->zoneText.thread, m_thread ); MemWrite( &item->zoneText.thread, m_thread );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline void Name( const char* txt, size_t size ) tracy_force_inline void Name( const char* txt, size_t size )
{ {
#ifndef TRACY_ON_DEMAND
Magic magic; Magic magic;
auto& token = s_token.ptr; auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
@ -105,6 +114,7 @@ public:
MemWrite( &item->zoneText.thread, m_thread ); MemWrite( &item->zoneText.thread, m_thread );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
private: private: