Hide async queue setup/commit behind macros.

This commit is contained in:
Bartosz Taudul 2020-01-19 15:06:11 +01:00
parent 77a6039e54
commit 55d03cb03e
7 changed files with 154 additions and 402 deletions

View File

@ -179,14 +179,10 @@ static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth )
} }
assert( dst - ptr == spaceNeeded + 4 ); assert( dst - ptr == spaceNeeded + 4 );
Magic magic; TracyLfqPrepare( QueueType::CallstackAlloc );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::CallstackAlloc );
MemWrite( &item->callstackAlloc.ptr, (uint64_t)ptr ); MemWrite( &item->callstackAlloc.ptr, (uint64_t)ptr );
MemWrite( &item->callstackAlloc.nativePtr, (uint64_t)Callstack( depth ) ); MemWrite( &item->callstackAlloc.nativePtr, (uint64_t)Callstack( depth ) );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
static inline int LuaZoneBeginS( lua_State* L ) static inline int LuaZoneBeginS( lua_State* L )
@ -203,14 +199,10 @@ static inline int LuaZoneBeginS( lua_State* L )
lua_getinfo( L, "Snl", &dbg ); lua_getinfo( L, "Snl", &dbg );
const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src );
Magic magic; TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLocCallstack );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, srcloc ); MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
#ifdef TRACY_CALLSTACK #ifdef TRACY_CALLSTACK
const uint32_t depth = TRACY_CALLSTACK; const uint32_t depth = TRACY_CALLSTACK;
@ -238,14 +230,10 @@ static inline int LuaZoneBeginNS( lua_State* L )
const auto name = lua_tolstring( L, 1, &nsz ); const auto name = lua_tolstring( L, 1, &nsz );
const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz );
Magic magic; TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLocCallstack );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, srcloc ); MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
#ifdef TRACY_CALLSTACK #ifdef TRACY_CALLSTACK
const uint32_t depth = TRACY_CALLSTACK; const uint32_t depth = TRACY_CALLSTACK;
@ -275,14 +263,10 @@ static inline int LuaZoneBegin( lua_State* L )
lua_getinfo( L, "Snl", &dbg ); lua_getinfo( L, "Snl", &dbg );
const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src );
Magic magic; TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLoc );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, srcloc ); MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
#endif #endif
} }
@ -306,14 +290,10 @@ static inline int LuaZoneBeginN( lua_State* L )
const auto name = lua_tolstring( L, 1, &nsz ); const auto name = lua_tolstring( L, 1, &nsz );
const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz );
Magic magic; TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLoc );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, srcloc ); MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
#endif #endif
} }
@ -331,13 +311,9 @@ static inline int LuaZoneEnd( lua_State* L )
} }
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::ZoneEnd );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneEnd );
MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
} }
@ -355,16 +331,12 @@ static inline int LuaZoneText( lua_State* L )
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::ZoneText );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneText );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
} }
@ -382,16 +354,12 @@ static inline int LuaZoneName( lua_State* L )
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::ZoneName );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneName );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
} }
@ -404,17 +372,13 @@ static inline int LuaMessage( lua_State* L )
auto txt = lua_tostring( L, 1 ); auto txt = lua_tostring( L, 1 );
const auto size = strlen( txt ); const auto size = strlen( txt );
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::Message );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::Message );
MemWrite( &item->message.time, Profiler::GetTime() ); MemWrite( &item->message.time, Profiler::GetTime() );
MemWrite( &item->message.text, (uint64_t)ptr ); MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
return 0; return 0;
} }

View File

@ -101,12 +101,8 @@ public:
glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits ); glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits );
const float period = 1.f; const float period = 1.f;
Magic magic;
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto token = GetToken(); TracyLfqPrepare( QueueType::GpuNewContext );
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::GpuNewContext );
MemWrite( &item->gpuNewContext.cpuTime, tcpu ); MemWrite( &item->gpuNewContext.cpuTime, tcpu );
MemWrite( &item->gpuNewContext.gpuTime, tgpu ); MemWrite( &item->gpuNewContext.gpuTime, tgpu );
MemWrite( &item->gpuNewContext.thread, thread ); MemWrite( &item->gpuNewContext.thread, thread );
@ -118,7 +114,7 @@ public:
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
void Collect() void Collect()
@ -135,10 +131,6 @@ public:
} }
#endif #endif
Magic magic;
auto token = GetToken();
auto& tail = token->get_tail_index();
while( m_tail != m_head ) while( m_tail != m_head )
{ {
GLint available; GLint available;
@ -148,12 +140,11 @@ public:
uint64_t time; uint64_t time;
glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time );
auto item = token->enqueue_begin( magic ); TracyLfqPrepare( QueueType::GpuTime );
MemWrite( &item->hdr.type, QueueType::GpuTime );
MemWrite( &item->gpuTime.gpuTime, (int64_t)time ); MemWrite( &item->gpuTime.gpuTime, (int64_t)time );
MemWrite( &item->gpuTime.queryId, (uint16_t)m_tail ); MemWrite( &item->gpuTime.queryId, (uint16_t)m_tail );
MemWrite( &item->gpuTime.context, m_context ); MemWrite( &item->gpuTime.context, m_context );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
m_tail = ( m_tail + 1 ) % QueryCount; m_tail = ( m_tail + 1 ) % QueryCount;
} }
@ -199,17 +190,13 @@ public:
const auto queryId = GetGpuCtx().ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
Magic magic; TracyLfqPrepare( QueueType::GpuZoneBegin );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::GpuZoneBegin );
MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) ); memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) );
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc, int depth ) tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc, int depth )
@ -223,18 +210,14 @@ public:
const auto queryId = GetGpuCtx().ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
Magic magic;
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto token = GetToken(); TracyLfqPrepare( QueueType::GpuZoneBeginCallstack );
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstack );
MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
MemWrite( &item->gpuZoneBegin.thread, thread ); MemWrite( &item->gpuZoneBegin.thread, thread );
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
GetProfiler().SendCallstack( depth ); GetProfiler().SendCallstack( depth );
} }
@ -247,16 +230,12 @@ public:
const auto queryId = GetGpuCtx().ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
Magic magic; TracyLfqPrepare( QueueType::GpuZoneEnd );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::GpuZoneEnd );
MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() );
memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) ); memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) );
MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneEnd.context, GetGpuCtx().ptr->GetId() ); MemWrite( &item->gpuZoneEnd.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
private: private:

View File

@ -23,11 +23,7 @@ public:
{ {
assert( m_id != std::numeric_limits<uint32_t>::max() ); assert( m_id != std::numeric_limits<uint32_t>::max() );
Magic magic; TracyLfqPrepare( QueueType::LockAnnounce );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::LockAnnounce );
MemWrite( &item->lockAnnounce.id, m_id ); MemWrite( &item->lockAnnounce.id, m_id );
MemWrite( &item->lockAnnounce.time, Profiler::GetTime() ); MemWrite( &item->lockAnnounce.time, Profiler::GetTime() );
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
@ -35,7 +31,7 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
LockableCtx( const LockableCtx& ) = delete; LockableCtx( const LockableCtx& ) = delete;
@ -43,18 +39,14 @@ public:
tracy_force_inline ~LockableCtx() tracy_force_inline ~LockableCtx()
{ {
Magic magic; TracyLfqPrepare( QueueType::LockTerminate );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::LockTerminate );
MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.id, m_id );
MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() );
MemWrite( &item->lockTerminate.type, LockType::Lockable ); MemWrite( &item->lockTerminate.type, LockType::Lockable );
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline bool BeforeLock() tracy_force_inline bool BeforeLock()
@ -225,11 +217,7 @@ public:
{ {
assert( m_id != std::numeric_limits<uint32_t>::max() ); assert( m_id != std::numeric_limits<uint32_t>::max() );
Magic magic; TracyLfqPrepare( QueueType::LockAnnounce );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::LockAnnounce );
MemWrite( &item->lockAnnounce.id, m_id ); MemWrite( &item->lockAnnounce.id, m_id );
MemWrite( &item->lockAnnounce.time, Profiler::GetTime() ); MemWrite( &item->lockAnnounce.time, Profiler::GetTime() );
MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc );
@ -239,7 +227,7 @@ public:
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
SharedLockableCtx( const SharedLockableCtx& ) = delete; SharedLockableCtx( const SharedLockableCtx& ) = delete;
@ -247,11 +235,7 @@ public:
tracy_force_inline ~SharedLockableCtx() tracy_force_inline ~SharedLockableCtx()
{ {
Magic magic; TracyLfqPrepare( QueueType::LockTerminate );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::LockTerminate );
MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.id, m_id );
MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() );
MemWrite( &item->lockTerminate.type, LockType::SharedLockable ); MemWrite( &item->lockTerminate.type, LockType::SharedLockable );
@ -260,7 +244,7 @@ public:
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline bool BeforeLock() tracy_force_inline bool BeforeLock()

View File

@ -587,14 +587,10 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
} }
{ {
Magic magic; TracyLfqPrepare( QueueType::CrashReport );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::CrashReport );
item->crashReport.time = Profiler::GetTime(); item->crashReport.time = Profiler::GetTime();
item->crashReport.text = (uint64_t)s_crashText; item->crashReport.text = (uint64_t)s_crashText;
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
GetProfiler().SendCallstack( 60, "KiUserExceptionDispatcher" ); GetProfiler().SendCallstack( 60, "KiUserExceptionDispatcher" );
} }
@ -628,12 +624,8 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
CloseHandle( h ); CloseHandle( h );
{ {
Magic magic; TracyLfqPrepare( QueueType::Crash );
auto token = GetToken(); TracyLfqCommit;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::Crash );
tail.store( magic + 1, std::memory_order_release );
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
@ -823,14 +815,10 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
} }
{ {
Magic magic; TracyLfqPrepare( QueueType::CrashReport );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::CrashReport );
item->crashReport.time = Profiler::GetTime(); item->crashReport.time = Profiler::GetTime();
item->crashReport.text = (uint64_t)s_crashText; item->crashReport.text = (uint64_t)s_crashText;
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
GetProfiler().SendCallstack( 60, "__kernel_rt_sigreturn" ); GetProfiler().SendCallstack( 60, "__kernel_rt_sigreturn" );
} }
@ -853,12 +841,8 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
closedir( dp ); closedir( dp );
{ {
Magic magic; TracyLfqPrepare( QueueType::Crash );
auto token = GetToken(); TracyLfqCommit;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::Crash );
tail.store( magic + 1, std::memory_order_release );
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
@ -1565,18 +1549,14 @@ void Profiler::CompressWorker()
CompressImageDxt1( (const char*)fi->image, etc1buf, w, h ); CompressImageDxt1( (const char*)fi->image, etc1buf, w, h );
tracy_free( fi->image ); tracy_free( fi->image );
Magic magic; TracyLfqPrepare( QueueType::FrameImage );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::FrameImage );
MemWrite( &item->frameImage.image, (uint64_t)etc1buf ); MemWrite( &item->frameImage.image, (uint64_t)etc1buf );
MemWrite( &item->frameImage.frame, fi->frame ); MemWrite( &item->frameImage.frame, fi->frame );
MemWrite( &item->frameImage.w, w ); MemWrite( &item->frameImage.w, w );
MemWrite( &item->frameImage.h, h ); MemWrite( &item->frameImage.h, h );
uint8_t flip = fi->flip; uint8_t flip = fi->flip;
MemWrite( &item->frameImage.flip, flip ); MemWrite( &item->frameImage.flip, flip );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
fi++; fi++;
} }
@ -2413,21 +2393,15 @@ void Profiler::CalibrateDelay()
for( int i=0; i<Iterations; i++ ) for( int i=0; i<Iterations; i++ )
{ {
{ {
Magic magic; TracyLfqPrepare( QueueType::ZoneBegin );
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBegin );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)&__tracy_source_location ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)&__tracy_source_location );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
{ {
Magic magic; TracyLfqPrepare( QueueType::ZoneEnd );
auto& tail = ptoken->get_tail_index();
auto item = ptoken->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneEnd );
MemWrite( &item->zoneEnd.time, GetTime() ); MemWrite( &item->zoneEnd.time, GetTime() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
} }
const auto t1 = GetTime(); const auto t1 = GetTime();
@ -2522,15 +2496,11 @@ void Profiler::ReportTopology()
idx++; idx++;
} }
Magic magic;
auto token = GetToken();
for( uint32_t i=0; i<numcpus; i++ ) for( uint32_t i=0; i<numcpus; i++ )
{ {
auto& data = cpuData[i]; auto& data = cpuData[i];
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::CpuTopology );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::CpuTopology );
MemWrite( &item->cpuTopology.package, data.package ); MemWrite( &item->cpuTopology.package, data.package );
MemWrite( &item->cpuTopology.core, data.core ); MemWrite( &item->cpuTopology.core, data.core );
MemWrite( &item->cpuTopology.thread, data.thread ); MemWrite( &item->cpuTopology.thread, data.thread );
@ -2539,7 +2509,7 @@ void Profiler::ReportTopology()
DeferItem( *item ); DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_free( cpuData ); tracy_free( cpuData );
@ -2571,15 +2541,11 @@ void Profiler::ReportTopology()
cpuData[i].core = uint32_t( atoi( buf ) ); cpuData[i].core = uint32_t( atoi( buf ) );
} }
Magic magic;
auto token = GetToken();
for( uint32_t i=0; i<numcpus; i++ ) for( uint32_t i=0; i<numcpus; i++ )
{ {
auto& data = cpuData[i]; auto& data = cpuData[i];
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::CpuTopology );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::CpuTopology );
MemWrite( &item->cpuTopology.package, data.package ); MemWrite( &item->cpuTopology.package, data.package );
MemWrite( &item->cpuTopology.core, data.core ); MemWrite( &item->cpuTopology.core, data.core );
MemWrite( &item->cpuTopology.thread, data.thread ); MemWrite( &item->cpuTopology.thread, data.thread );
@ -2588,7 +2554,7 @@ void Profiler::ReportTopology()
DeferItem( *item ); DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_free( cpuData ); tracy_free( cpuData );
@ -2602,13 +2568,9 @@ void Profiler::SendCallstack( int depth, const char* skipBefore )
auto ptr = Callstack( depth ); auto ptr = Callstack( depth );
CutCallstack( ptr, skipBefore ); CutCallstack( ptr, skipBefore );
Magic magic; TracyLfqPrepare( QueueType::Callstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::Callstack );
MemWrite( &item->callstack.ptr, ptr ); MemWrite( &item->callstack.ptr, ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
#endif #endif
} }
@ -2649,14 +2611,10 @@ void Profiler::ProcessSysTime()
{ {
m_sysTimeLast = t; m_sysTimeLast = t;
Magic magic; TracyLfqPrepare( QueueType::SysTimeReport );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::SysTimeReport );
MemWrite( &item->sysTime.time, GetTime() ); MemWrite( &item->sysTime.time, GetTime() );
MemWrite( &item->sysTime.sysTime, sysTime ); MemWrite( &item->sysTime.sysTime, sysTime );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
} }
} }
@ -2664,11 +2622,7 @@ void Profiler::ProcessSysTime()
void Profiler::ParameterSetup( uint32_t idx, const char* name, bool isBool, int32_t val ) void Profiler::ParameterSetup( uint32_t idx, const char* name, bool isBool, int32_t val )
{ {
tracy::Magic magic; TracyLfqPrepare( QueueType::ParamSetup );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ParamSetup );
tracy::MemWrite( &item->paramSetup.idx, idx ); tracy::MemWrite( &item->paramSetup.idx, idx );
tracy::MemWrite( &item->paramSetup.name, (uint64_t)name ); tracy::MemWrite( &item->paramSetup.name, (uint64_t)name );
tracy::MemWrite( &item->paramSetup.isBool, (uint8_t)isBool ); tracy::MemWrite( &item->paramSetup.isBool, (uint8_t)isBool );
@ -2678,7 +2632,7 @@ void Profiler::ParameterSetup( uint32_t idx, const char* name, bool isBool, int3
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
void Profiler::HandleParameter( uint64_t payload ) void Profiler::HandleParameter( uint64_t payload )
@ -2709,24 +2663,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_l
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id ); tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneBegin );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBegin );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
return ctx; return ctx;
} }
@ -2745,24 +2691,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id ); tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneBeginCallstack );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
tracy::GetProfiler().SendCallstack( depth ); tracy::GetProfiler().SendCallstack( depth );
@ -2787,24 +2725,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int act
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id ); tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneBeginAllocSrcLoc );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLoc );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc ); tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
return ctx; return ctx;
} }
@ -2827,24 +2757,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id ); tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneBeginAllocSrcLocCallstack );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLocCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc ); tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
tracy::GetProfiler().SendCallstack( depth ); tracy::GetProfiler().SendCallstack( depth );
@ -2856,23 +2778,15 @@ TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
if( !ctx.active ) return; if( !ctx.active ) return;
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, ctx.id ); tracy::MemWrite( &item->zoneValidation.id, ctx.id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneEnd );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneEnd );
tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
} }
@ -2884,23 +2798,15 @@ TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size
ptr[size] = '\0'; ptr[size] = '\0';
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, ctx.id ); tracy::MemWrite( &item->zoneValidation.id, ctx.id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneText );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneText );
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr ); tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
} }
@ -2912,23 +2818,15 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size
ptr[size] = '\0'; ptr[size] = '\0';
#ifndef TRACY_NO_VERIFY #ifndef TRACY_NO_VERIFY
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, ctx.id ); tracy::MemWrite( &item->zoneValidation.id, ctx.id );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
#endif #endif
{ {
tracy::Magic magic; TracyLfqPrepareC( tracy::QueueType::ZoneName );
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneName );
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr ); tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommitC;
} }
} }

View File

@ -77,7 +77,26 @@ struct LuaZoneState
}; };
#endif #endif
using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t;
#define TracyLfqPrepare( _type ) \
moodycamel::ConcurrentQueueDefaultTraits::index_t __magic; \
auto __token = GetToken(); \
auto& __tail = __token->get_tail_index(); \
auto item = __token->enqueue_begin( __magic ); \
MemWrite( &item->hdr.type, _type );
#define TracyLfqCommit \
__tail.store( __magic + 1, std::memory_order_release );
#define TracyLfqPrepareC( _type ) \
tracy::moodycamel::ConcurrentQueueDefaultTraits::index_t __magic; \
auto __token = tracy::GetToken(); \
auto& __tail = __token->get_tail_index(); \
auto item = __token->enqueue_begin( __magic ); \
tracy::MemWrite( &item->hdr.type, _type );
#define TracyLfqCommitC \
__tail.store( __magic + 1, std::memory_order_release );
typedef void(*ParameterCallback)( uint32_t idx, int32_t val ); typedef void(*ParameterCallback)( uint32_t idx, int32_t val );
@ -152,14 +171,10 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::FrameMarkMsg );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::FrameMarkMsg );
MemWrite( &item->frameMark.time, GetTime() ); MemWrite( &item->frameMark.time, GetTime() );
MemWrite( &item->frameMark.name, uint64_t( name ) ); MemWrite( &item->frameMark.name, uint64_t( name ) );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
static tracy_force_inline void SendFrameMark( const char* name, QueueType type ) static tracy_force_inline void SendFrameMark( const char* name, QueueType type )
@ -201,16 +216,12 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::PlotData );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::PlotData );
MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.name, (uint64_t)name );
MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.time, GetTime() );
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 ); TracyLfqCommit;
} }
static tracy_force_inline void PlotData( const char* name, float val ) static tracy_force_inline void PlotData( const char* name, float val )
@ -218,16 +229,12 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::PlotData );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::PlotData );
MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.name, (uint64_t)name );
MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.time, GetTime() );
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 ); TracyLfqCommit;
} }
static tracy_force_inline void PlotData( const char* name, double val ) static tracy_force_inline void PlotData( const char* name, double val )
@ -235,25 +242,17 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::PlotData );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::PlotData );
MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.name, (uint64_t)name );
MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.time, GetTime() );
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 ); TracyLfqCommit;
} }
static tracy_force_inline void ConfigurePlot( const char* name, PlotFormatType type ) static tracy_force_inline void ConfigurePlot( const char* name, PlotFormatType type )
{ {
Magic magic; TracyLfqPrepare( QueueType::PlotConfig );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::PlotConfig );
MemWrite( &item->plotConfig.name, (uint64_t)name ); MemWrite( &item->plotConfig.name, (uint64_t)name );
MemWrite( &item->plotConfig.type, (uint8_t)type ); MemWrite( &item->plotConfig.type, (uint8_t)type );
@ -261,7 +260,7 @@ public:
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
static tracy_force_inline void Message( const char* txt, size_t size, int callstack ) static tracy_force_inline void Message( const char* txt, size_t size, int callstack )
@ -269,17 +268,13 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( callstack == 0 ? QueueType::Message : QueueType::MessageCallstack );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, callstack == 0 ? QueueType::Message : QueueType::MessageCallstack );
MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.text, (uint64_t)ptr ); MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );
} }
@ -289,14 +284,10 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack );
MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.text, (uint64_t)txt ); MemWrite( &item->message.text, (uint64_t)txt );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );
} }
@ -306,20 +297,16 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack );
MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.time, GetTime() );
MemWrite( &item->messageColor.text, (uint64_t)ptr ); MemWrite( &item->messageColor.text, (uint64_t)ptr );
MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );
} }
@ -329,31 +316,23 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return; if( !GetProfiler().IsConnected() ) return;
#endif #endif
Magic magic; TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack );
MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.time, GetTime() );
MemWrite( &item->messageColor.text, (uint64_t)txt ); MemWrite( &item->messageColor.text, (uint64_t)txt );
MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack );
} }
static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) static tracy_force_inline void MessageAppInfo( const char* txt, size_t size )
{ {
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::MessageAppInfo );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::MessageAppInfo );
MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.text, (uint64_t)ptr ); MemWrite( &item->message.text, (uint64_t)ptr );
@ -361,7 +340,7 @@ public:
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) static tracy_force_inline void MemAlloc( const void* ptr, size_t size )
@ -434,13 +413,9 @@ public:
{ {
#ifdef TRACY_HAS_CALLSTACK #ifdef TRACY_HAS_CALLSTACK
auto ptr = Callstack( depth ); auto ptr = Callstack( depth );
Magic magic; TracyLfqPrepare( QueueType::Callstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::Callstack );
MemWrite( &item->callstack.ptr, ptr ); MemWrite( &item->callstack.ptr, ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
#endif #endif
} }

View File

@ -24,14 +24,10 @@ public:
#endif #endif
{ {
if( !m_active ) return; if( !m_active ) return;
Magic magic; TracyLfqPrepare( QueueType::ZoneBegin );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBegin );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true ) tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
@ -43,14 +39,10 @@ public:
#endif #endif
{ {
if( !m_active ) return; if( !m_active ) return;
Magic magic; TracyLfqPrepare( QueueType::ZoneBeginCallstack );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneBeginCallstack );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
GetProfiler().SendCallstack( depth ); GetProfiler().SendCallstack( depth );
} }
@ -61,13 +53,9 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return; if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif #endif
Magic magic; TracyLfqPrepare( QueueType::ZoneEnd );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneEnd );
MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline void Text( const char* txt, size_t size ) tracy_force_inline void Text( const char* txt, size_t size )
@ -76,16 +64,12 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return; if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif #endif
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::ZoneText );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneText );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
tracy_force_inline void Name( const char* txt, size_t size ) tracy_force_inline void Name( const char* txt, size_t size )
@ -94,16 +78,12 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return; if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif #endif
Magic magic;
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 ); auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size ); memcpy( ptr, txt, size );
ptr[size] = '\0'; ptr[size] = '\0';
auto& tail = token->get_tail_index(); TracyLfqPrepare( QueueType::ZoneName );
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ZoneName );
MemWrite( &item->zoneText.text, (uint64_t)ptr ); MemWrite( &item->zoneText.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
private: private:

View File

@ -79,11 +79,7 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
{ {
const auto cswitch = (const CSwitch*)record->UserData; const auto cswitch = (const CSwitch*)record->UserData;
Magic magic; TracyLfqPrepare( QueueType::ContextSwitch );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ContextSwitch );
MemWrite( &item->contextSwitch.time, hdr.TimeStamp.QuadPart ); MemWrite( &item->contextSwitch.time, hdr.TimeStamp.QuadPart );
memcpy( &item->contextSwitch.oldThread, &cswitch->oldThreadId, sizeof( cswitch->oldThreadId ) ); memcpy( &item->contextSwitch.oldThread, &cswitch->oldThreadId, sizeof( cswitch->oldThreadId ) );
memcpy( &item->contextSwitch.newThread, &cswitch->newThreadId, sizeof( cswitch->newThreadId ) ); memcpy( &item->contextSwitch.newThread, &cswitch->newThreadId, sizeof( cswitch->newThreadId ) );
@ -92,21 +88,17 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
MemWrite( &item->contextSwitch.cpu, record->BufferContext.ProcessorNumber ); MemWrite( &item->contextSwitch.cpu, record->BufferContext.ProcessorNumber );
MemWrite( &item->contextSwitch.reason, cswitch->oldThreadWaitReason ); MemWrite( &item->contextSwitch.reason, cswitch->oldThreadWaitReason );
MemWrite( &item->contextSwitch.state, cswitch->oldThreadState ); MemWrite( &item->contextSwitch.state, cswitch->oldThreadState );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
else if( hdr.EventDescriptor.Opcode == 50 ) else if( hdr.EventDescriptor.Opcode == 50 )
{ {
const auto rt = (const ReadyThread*)record->UserData; const auto rt = (const ReadyThread*)record->UserData;
Magic magic; TracyLfqPrepare( QueueType::ThreadWakeup );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ThreadWakeup );
MemWrite( &item->threadWakeup.time, hdr.TimeStamp.QuadPart ); MemWrite( &item->threadWakeup.time, hdr.TimeStamp.QuadPart );
memcpy( &item->threadWakeup.thread, &rt->threadId, sizeof( rt->threadId ) ); memcpy( &item->threadWakeup.thread, &rt->threadId, sizeof( rt->threadId ) );
memset( ((char*)&item->threadWakeup.thread)+4, 0, 4 ); memset( ((char*)&item->threadWakeup.thread)+4, 0, 4 );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
else if( hdr.EventDescriptor.Opcode == 1 || hdr.EventDescriptor.Opcode == 3 ) else if( hdr.EventDescriptor.Opcode == 1 || hdr.EventDescriptor.Opcode == 3 )
{ {
@ -115,14 +107,10 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
uint64_t tid = tt->threadId; uint64_t tid = tt->threadId;
if( tid == 0 ) return; if( tid == 0 ) return;
uint64_t pid = tt->processId; uint64_t pid = tt->processId;
Magic magic; TracyLfqPrepare( QueueType::TidToPid );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::TidToPid );
MemWrite( &item->tidToPid.tid, tid ); MemWrite( &item->tidToPid.tid, tid );
MemWrite( &item->tidToPid.pid, pid ); MemWrite( &item->tidToPid.pid, pid );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
} }
@ -309,14 +297,10 @@ void SysTraceSendExternalName( uint64_t thread )
{ {
{ {
uint64_t _pid = pid; uint64_t _pid = pid;
Magic magic; TracyLfqPrepare( QueueType::TidToPid );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::TidToPid );
MemWrite( &item->tidToPid.tid, thread ); MemWrite( &item->tidToPid.tid, thread );
MemWrite( &item->tidToPid.pid, _pid ); MemWrite( &item->tidToPid.pid, _pid );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
if( pid == 4 ) if( pid == 4 )
{ {
@ -637,18 +621,14 @@ static void HandleTraceLine( const char* line )
uint8_t reason = 100; uint8_t reason = 100;
Magic magic; TracyLfqPrepare( QueueType::ContextSwitch );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ContextSwitch );
MemWrite( &item->contextSwitch.time, time ); MemWrite( &item->contextSwitch.time, time );
MemWrite( &item->contextSwitch.oldThread, oldPid ); MemWrite( &item->contextSwitch.oldThread, oldPid );
MemWrite( &item->contextSwitch.newThread, newPid ); MemWrite( &item->contextSwitch.newThread, newPid );
MemWrite( &item->contextSwitch.cpu, cpu ); MemWrite( &item->contextSwitch.cpu, cpu );
MemWrite( &item->contextSwitch.reason, reason ); MemWrite( &item->contextSwitch.reason, reason );
MemWrite( &item->contextSwitch.state, oldState ); MemWrite( &item->contextSwitch.state, oldState );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
else if( memcmp( line, "sched_wakeup", 12 ) == 0 ) else if( memcmp( line, "sched_wakeup", 12 ) == 0 )
{ {
@ -659,14 +639,10 @@ static void HandleTraceLine( const char* line )
const auto pid = ReadNumber( line ); const auto pid = ReadNumber( line );
Magic magic; TracyLfqPrepare( QueueType::ThreadWakeup );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::ThreadWakeup );
MemWrite( &item->threadWakeup.time, time ); MemWrite( &item->threadWakeup.time, time );
MemWrite( &item->threadWakeup.thread, pid ); MemWrite( &item->threadWakeup.thread, pid );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
} }
@ -860,14 +836,10 @@ void SysTraceSendExternalName( uint64_t thread )
{ {
{ {
uint64_t _pid = pid; uint64_t _pid = pid;
Magic magic; TracyLfqPrepare( QueueType::TidToPid );
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
MemWrite( &item->hdr.type, QueueType::TidToPid );
MemWrite( &item->tidToPid.tid, thread ); MemWrite( &item->tidToPid.tid, thread );
MemWrite( &item->tidToPid.pid, _pid ); MemWrite( &item->tidToPid.pid, _pid );
tail.store( magic + 1, std::memory_order_release ); TracyLfqCommit;
} }
sprintf( fn, "/proc/%i/comm", pid ); sprintf( fn, "/proc/%i/comm", pid );
f = fopen( fn, "rb" ); f = fopen( fn, "rb" );