diff --git a/TracyLua.hpp b/TracyLua.hpp index fd0f3822..6d27c814 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -179,14 +179,10 @@ static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) } assert( dst - ptr == spaceNeeded + 4 ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::CallstackAlloc ); + TracyLfqPrepare( QueueType::CallstackAlloc ); MemWrite( &item->callstackAlloc.ptr, (uint64_t)ptr ); MemWrite( &item->callstackAlloc.nativePtr, (uint64_t)Callstack( depth ) ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } static inline int LuaZoneBeginS( lua_State* L ) @@ -203,14 +199,10 @@ static inline int LuaZoneBeginS( lua_State* L ) lua_getinfo( L, "Snl", &dbg ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLocCallstack ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; #ifdef 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 srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLocCallstack ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; #ifdef TRACY_CALLSTACK const uint32_t depth = TRACY_CALLSTACK; @@ -275,14 +263,10 @@ static inline int LuaZoneBegin( lua_State* L ) lua_getinfo( L, "Snl", &dbg ); const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLoc ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; #endif } @@ -306,14 +290,10 @@ static inline int LuaZoneBeginN( lua_State* L ) 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 ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBeginAllocSrcLoc ); + TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; #endif } @@ -331,13 +311,9 @@ static inline int LuaZoneEnd( lua_State* L ) } #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneEnd ); + TracyLfqPrepare( QueueType::ZoneEnd ); MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; } @@ -355,16 +331,12 @@ static inline int LuaZoneText( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneText ); + TracyLfqPrepare( QueueType::ZoneText ); MemWrite( &item->zoneText.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; } @@ -382,16 +354,12 @@ static inline int LuaZoneName( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneName ); + TracyLfqPrepare( QueueType::ZoneName ); MemWrite( &item->zoneText.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; } @@ -404,17 +372,13 @@ static inline int LuaMessage( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::Message ); + TracyLfqPrepare( QueueType::Message ); MemWrite( &item->message.time, Profiler::GetTime() ); MemWrite( &item->message.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; return 0; } diff --git a/TracyOpenGL.hpp b/TracyOpenGL.hpp index c081c75c..d5ad6ae0 100644 --- a/TracyOpenGL.hpp +++ b/TracyOpenGL.hpp @@ -101,12 +101,8 @@ public: glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits ); const float period = 1.f; - Magic magic; const auto thread = GetThreadHandle(); - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::GpuNewContext ); + TracyLfqPrepare( QueueType::GpuNewContext ); MemWrite( &item->gpuNewContext.cpuTime, tcpu ); MemWrite( &item->gpuNewContext.gpuTime, tgpu ); MemWrite( &item->gpuNewContext.thread, thread ); @@ -118,7 +114,7 @@ public: GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } void Collect() @@ -135,10 +131,6 @@ public: } #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - while( m_tail != m_head ) { GLint available; @@ -148,12 +140,11 @@ public: uint64_t time; glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::GpuTime ); + TracyLfqPrepare( QueueType::GpuTime ); MemWrite( &item->gpuTime.gpuTime, (int64_t)time ); MemWrite( &item->gpuTime.queryId, (uint16_t)m_tail ); MemWrite( &item->gpuTime.context, m_context ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; m_tail = ( m_tail + 1 ) % QueryCount; } @@ -199,17 +190,13 @@ public: const auto queryId = GetGpuCtx().ptr->NextQueryId(); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::GpuZoneBegin ); + TracyLfqPrepare( QueueType::GpuZoneBegin ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); 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 ) @@ -223,18 +210,14 @@ public: const auto queryId = GetGpuCtx().ptr->NextQueryId(); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); - Magic magic; const auto thread = GetThreadHandle(); - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstack ); + TracyLfqPrepare( QueueType::GpuZoneBeginCallstack ); MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->gpuZoneBegin.thread, thread ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; GetProfiler().SendCallstack( depth ); } @@ -247,16 +230,12 @@ public: const auto queryId = GetGpuCtx().ptr->NextQueryId(); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::GpuZoneEnd ); + TracyLfqPrepare( QueueType::GpuZoneEnd ); MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.context, GetGpuCtx().ptr->GetId() ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } private: diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index 2bf265a8..16d69b0c 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -23,11 +23,7 @@ public: { assert( m_id != std::numeric_limits::max() ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::LockAnnounce ); + TracyLfqPrepare( QueueType::LockAnnounce ); MemWrite( &item->lockAnnounce.id, m_id ); MemWrite( &item->lockAnnounce.time, Profiler::GetTime() ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); @@ -35,7 +31,7 @@ public: #ifdef TRACY_ON_DEMAND GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } LockableCtx( const LockableCtx& ) = delete; @@ -43,18 +39,14 @@ public: tracy_force_inline ~LockableCtx() { - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::LockTerminate ); + TracyLfqPrepare( QueueType::LockTerminate ); MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.type, LockType::Lockable ); #ifdef TRACY_ON_DEMAND GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } tracy_force_inline bool BeforeLock() @@ -225,11 +217,7 @@ public: { assert( m_id != std::numeric_limits::max() ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::LockAnnounce ); + TracyLfqPrepare( QueueType::LockAnnounce ); MemWrite( &item->lockAnnounce.id, m_id ); MemWrite( &item->lockAnnounce.time, Profiler::GetTime() ); MemWrite( &item->lockAnnounce.lckloc, (uint64_t)srcloc ); @@ -239,7 +227,7 @@ public: GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } SharedLockableCtx( const SharedLockableCtx& ) = delete; @@ -247,11 +235,7 @@ public: tracy_force_inline ~SharedLockableCtx() { - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::LockTerminate ); + TracyLfqPrepare( QueueType::LockTerminate ); MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.type, LockType::SharedLockable ); @@ -260,7 +244,7 @@ public: GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } tracy_force_inline bool BeforeLock() diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 71dc4c20..e9023a03 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -587,14 +587,10 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp ) } { - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::CrashReport ); + TracyLfqPrepare( QueueType::CrashReport ); item->crashReport.time = Profiler::GetTime(); item->crashReport.text = (uint64_t)s_crashText; - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; GetProfiler().SendCallstack( 60, "KiUserExceptionDispatcher" ); } @@ -628,12 +624,8 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp ) CloseHandle( h ); { - Magic magic; - auto token = GetToken(); - 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 ); + TracyLfqPrepare( QueueType::Crash ); + TracyLfqCommit; } 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; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::CrashReport ); + TracyLfqPrepare( QueueType::CrashReport ); item->crashReport.time = Profiler::GetTime(); item->crashReport.text = (uint64_t)s_crashText; - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; GetProfiler().SendCallstack( 60, "__kernel_rt_sigreturn" ); } @@ -853,12 +841,8 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ ) closedir( dp ); { - Magic magic; - auto token = GetToken(); - 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 ); + TracyLfqPrepare( QueueType::Crash ); + TracyLfqCommit; } std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) ); @@ -1565,18 +1549,14 @@ void Profiler::CompressWorker() CompressImageDxt1( (const char*)fi->image, etc1buf, w, h ); tracy_free( fi->image ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::FrameImage ); + TracyLfqPrepare( QueueType::FrameImage ); MemWrite( &item->frameImage.image, (uint64_t)etc1buf ); MemWrite( &item->frameImage.frame, fi->frame ); MemWrite( &item->frameImage.w, w ); MemWrite( &item->frameImage.h, h ); uint8_t flip = fi->flip; MemWrite( &item->frameImage.flip, flip ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; fi++; } @@ -2413,21 +2393,15 @@ void Profiler::CalibrateDelay() for( int i=0; iget_tail_index(); - auto item = ptoken->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBegin ); + TracyLfqPrepare( QueueType::ZoneBegin ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)&__tracy_source_location ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } { - Magic magic; - auto& tail = ptoken->get_tail_index(); - auto item = ptoken->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneEnd ); + TracyLfqPrepare( QueueType::ZoneEnd ); MemWrite( &item->zoneEnd.time, GetTime() ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } } const auto t1 = GetTime(); @@ -2522,15 +2496,11 @@ void Profiler::ReportTopology() idx++; } - Magic magic; - auto token = GetToken(); for( uint32_t i=0; iget_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::CpuTopology ); + TracyLfqPrepare( QueueType::CpuTopology ); MemWrite( &item->cpuTopology.package, data.package ); MemWrite( &item->cpuTopology.core, data.core ); MemWrite( &item->cpuTopology.thread, data.thread ); @@ -2539,7 +2509,7 @@ void Profiler::ReportTopology() DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } tracy_free( cpuData ); @@ -2571,15 +2541,11 @@ void Profiler::ReportTopology() cpuData[i].core = uint32_t( atoi( buf ) ); } - Magic magic; - auto token = GetToken(); for( uint32_t i=0; iget_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::CpuTopology ); + TracyLfqPrepare( QueueType::CpuTopology ); MemWrite( &item->cpuTopology.package, data.package ); MemWrite( &item->cpuTopology.core, data.core ); MemWrite( &item->cpuTopology.thread, data.thread ); @@ -2588,7 +2554,7 @@ void Profiler::ReportTopology() DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } tracy_free( cpuData ); @@ -2602,13 +2568,9 @@ void Profiler::SendCallstack( int depth, const char* skipBefore ) auto ptr = Callstack( depth ); CutCallstack( ptr, skipBefore ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::Callstack ); + TracyLfqPrepare( QueueType::Callstack ); MemWrite( &item->callstack.ptr, ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; #endif } @@ -2649,14 +2611,10 @@ void Profiler::ProcessSysTime() { m_sysTimeLast = t; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::SysTimeReport ); + TracyLfqPrepare( QueueType::SysTimeReport ); MemWrite( &item->sysTime.time, GetTime() ); 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 ) { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ParamSetup ); + TracyLfqPrepare( QueueType::ParamSetup ); tracy::MemWrite( &item->paramSetup.idx, idx ); tracy::MemWrite( &item->paramSetup.name, (uint64_t)name ); 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 ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } 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 { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBegin ); + TracyLfqPrepareC( tracy::QueueType::ZoneBegin ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } return ctx; } @@ -2745,24 +2691,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac #ifndef TRACY_NO_VERIFY { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginCallstack ); + TracyLfqPrepareC( tracy::QueueType::ZoneBeginCallstack ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } 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 { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLoc ); + TracyLfqPrepareC( tracy::QueueType::ZoneBeginAllocSrcLoc ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } return ctx; } @@ -2827,24 +2757,16 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo #ifndef TRACY_NO_VERIFY { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLocCallstack ); + TracyLfqPrepareC( tracy::QueueType::ZoneBeginAllocSrcLocCallstack ); tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() ); tracy::MemWrite( &item->zoneBegin.srcloc, srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } tracy::GetProfiler().SendCallstack( depth ); @@ -2856,23 +2778,15 @@ TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ) if( !ctx.active ) return; #ifndef TRACY_NO_VERIFY { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, ctx.id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneEnd ); + TracyLfqPrepareC( tracy::QueueType::ZoneEnd ); 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'; #ifndef TRACY_NO_VERIFY { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, ctx.id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneText ); + TracyLfqPrepareC( tracy::QueueType::ZoneText ); 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'; #ifndef TRACY_NO_VERIFY { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation ); + TracyLfqPrepareC( tracy::QueueType::ZoneValidation ); tracy::MemWrite( &item->zoneValidation.id, ctx.id ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } #endif { - tracy::Magic magic; - auto token = tracy::GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneName ); + TracyLfqPrepareC( tracy::QueueType::ZoneName ); tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommitC; } } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index b36a36d7..f2294e6d 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -77,7 +77,26 @@ struct LuaZoneState }; #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 ); @@ -152,14 +171,10 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::FrameMarkMsg ); + TracyLfqPrepare( QueueType::FrameMarkMsg ); MemWrite( &item->frameMark.time, GetTime() ); 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 ) @@ -201,16 +216,12 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::PlotData ); + TracyLfqPrepare( QueueType::PlotData ); MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.type, PlotDataType::Int ); 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 ) @@ -218,16 +229,12 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::PlotData ); + TracyLfqPrepare( QueueType::PlotData ); MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.type, PlotDataType::Float ); 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 ) @@ -235,25 +242,17 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::PlotData ); + TracyLfqPrepare( QueueType::PlotData ); MemWrite( &item->plotData.name, (uint64_t)name ); MemWrite( &item->plotData.time, GetTime() ); MemWrite( &item->plotData.type, PlotDataType::Double ); 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 ) { - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::PlotConfig ); + TracyLfqPrepare( QueueType::PlotConfig ); MemWrite( &item->plotConfig.name, (uint64_t)name ); MemWrite( &item->plotConfig.type, (uint8_t)type ); @@ -261,7 +260,7 @@ public: GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } static tracy_force_inline void Message( const char* txt, size_t size, int callstack ) @@ -269,17 +268,13 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, callstack == 0 ? QueueType::Message : QueueType::MessageCallstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::Message : QueueType::MessageCallstack ); MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } @@ -289,14 +284,10 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - 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 ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack ); MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.text, (uint64_t)txt ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; if( callstack != 0 ) tracy::GetProfiler().SendCallstack( callstack ); } @@ -306,20 +297,16 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack ); MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.text, (uint64_t)ptr ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 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 ); } @@ -329,31 +316,23 @@ public: #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif - Magic magic; - 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 ); + TracyLfqPrepare( callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack ); MemWrite( &item->messageColor.time, GetTime() ); MemWrite( &item->messageColor.text, (uint64_t)txt ); MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 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 ); } static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) { - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::MessageAppInfo ); + TracyLfqPrepare( QueueType::MessageAppInfo ); MemWrite( &item->message.time, GetTime() ); MemWrite( &item->message.text, (uint64_t)ptr ); @@ -361,7 +340,7 @@ public: GetProfiler().DeferItem( *item ); #endif - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) @@ -434,13 +413,9 @@ public: { #ifdef TRACY_HAS_CALLSTACK auto ptr = Callstack( depth ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::Callstack ); + TracyLfqPrepare( QueueType::Callstack ); MemWrite( &item->callstack.ptr, ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; #endif } diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 16255ceb..461b8add 100644 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -24,14 +24,10 @@ public: #endif { if( !m_active ) return; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBegin ); + TracyLfqPrepare( QueueType::ZoneBegin ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 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 ) @@ -43,14 +39,10 @@ public: #endif { if( !m_active ) return; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneBeginCallstack ); + TracyLfqPrepare( QueueType::ZoneBeginCallstack ); MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; GetProfiler().SendCallstack( depth ); } @@ -61,13 +53,9 @@ public: #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; #endif - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneEnd ); + TracyLfqPrepare( QueueType::ZoneEnd ); 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 ) @@ -76,16 +64,12 @@ public: #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; #endif - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneText ); + TracyLfqPrepare( QueueType::ZoneText ); 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 ) @@ -94,16 +78,12 @@ public: #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; #endif - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( size+1 ); memcpy( ptr, txt, size ); ptr[size] = '\0'; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ZoneName ); + TracyLfqPrepare( QueueType::ZoneName ); MemWrite( &item->zoneText.text, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } private: diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index a590e3c8..8a3e5e4c 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -79,11 +79,7 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record ) { const auto cswitch = (const CSwitch*)record->UserData; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ContextSwitch ); + TracyLfqPrepare( QueueType::ContextSwitch ); MemWrite( &item->contextSwitch.time, hdr.TimeStamp.QuadPart ); memcpy( &item->contextSwitch.oldThread, &cswitch->oldThreadId, sizeof( cswitch->oldThreadId ) ); 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.reason, cswitch->oldThreadWaitReason ); MemWrite( &item->contextSwitch.state, cswitch->oldThreadState ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } else if( hdr.EventDescriptor.Opcode == 50 ) { const auto rt = (const ReadyThread*)record->UserData; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ThreadWakeup ); + TracyLfqPrepare( QueueType::ThreadWakeup ); MemWrite( &item->threadWakeup.time, hdr.TimeStamp.QuadPart ); memcpy( &item->threadWakeup.thread, &rt->threadId, sizeof( rt->threadId ) ); 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 ) { @@ -115,14 +107,10 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record ) uint64_t tid = tt->threadId; if( tid == 0 ) return; uint64_t pid = tt->processId; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::TidToPid ); + TracyLfqPrepare( QueueType::TidToPid ); MemWrite( &item->tidToPid.tid, tid ); 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; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::TidToPid ); + TracyLfqPrepare( QueueType::TidToPid ); MemWrite( &item->tidToPid.tid, thread ); MemWrite( &item->tidToPid.pid, _pid ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } if( pid == 4 ) { @@ -637,18 +621,14 @@ static void HandleTraceLine( const char* line ) uint8_t reason = 100; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ContextSwitch ); + TracyLfqPrepare( QueueType::ContextSwitch ); MemWrite( &item->contextSwitch.time, time ); MemWrite( &item->contextSwitch.oldThread, oldPid ); MemWrite( &item->contextSwitch.newThread, newPid ); MemWrite( &item->contextSwitch.cpu, cpu ); MemWrite( &item->contextSwitch.reason, reason ); MemWrite( &item->contextSwitch.state, oldState ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } else if( memcmp( line, "sched_wakeup", 12 ) == 0 ) { @@ -659,14 +639,10 @@ static void HandleTraceLine( const char* line ) const auto pid = ReadNumber( line ); - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::ThreadWakeup ); + TracyLfqPrepare( QueueType::ThreadWakeup ); MemWrite( &item->threadWakeup.time, time ); 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; - Magic magic; - auto token = GetToken(); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::TidToPid ); + TracyLfqPrepare( QueueType::TidToPid ); MemWrite( &item->tidToPid.tid, thread ); MemWrite( &item->tidToPid.pid, _pid ); - tail.store( magic + 1, std::memory_order_release ); + TracyLfqCommit; } sprintf( fn, "/proc/%i/comm", pid ); f = fopen( fn, "rb" );