From 453d649c1aea0270cb1be273114303864a4d51c8 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Aug 2026 13:05:28 +0200 Subject: [PATCH] Add TRACY_ASSERT for custom assert implementations. --- manual/tracy.md | 3 +- manual/tracy.tex | 1 + public/client/TracyCallstack.cpp | 19 ++-- public/client/TracyCallstack.hpp | 8 +- public/client/TracyDxt1.cpp | 4 +- public/client/TracyFastVector.hpp | 12 +-- public/client/TracyKCore.cpp | 6 +- public/client/TracyLock.hpp | 9 +- public/client/TracyProfiler.cpp | 100 +++++++++---------- public/client/TracyProfiler.hpp | 30 +++--- public/client/TracyRingBuffer.hpp | 8 +- public/client/TracyRocprof.cpp | 9 +- public/client/TracyScoped.hpp | 9 +- public/client/TracySysTrace.cpp | 16 +-- public/common/TracyAssert.hpp | 12 +++ public/common/TracyQueue.hpp | 5 +- public/common/TracySocket.cpp | 26 ++--- public/common/TracyString.hpp | 5 +- public/common/TracyTaggedUserlandAddress.hpp | 4 +- public/tracy/TracyCUDA.hpp | 36 +++---- public/tracy/TracyD3D11.hpp | 4 +- public/tracy/TracyD3D12.hpp | 4 +- public/tracy/TracyLua.hpp | 26 ++--- public/tracy/TracyMetal.hmm | 16 +-- public/tracy/TracyOpenCL.hpp | 10 +- public/tracy/TracyOpenGL.hpp | 8 +- public/tracy/TracyVulkan.hpp | 22 ++-- public/tracy/TracyWebGPU.hpp | 4 +- 28 files changed, 218 insertions(+), 198 deletions(-) create mode 100644 public/common/TracyAssert.hpp diff --git a/manual/tracy.md b/manual/tracy.md index 8b7a0825..8800bc4a 100644 --- a/manual/tracy.md +++ b/manual/tracy.md @@ -11,7 +11,7 @@ The user manual **Bartosz Taudul** [\](mailto:wolf@nereid.pl) -2026-08-15 +2026-08-16 # Quick overview {#quick-overview .unnumbered} @@ -434,6 +434,7 @@ Each enabled option is passed down to your program as a preprocessor macro of th | **Diagnostics** | | | `TRACY_VERBOSE` | Print detailed information about the detected features to the standard error output (section [2.1.12](#troubleshooting)). | | `TRACY_NO_INTERNAL_MESSAGE` | Don't send the profiler's own diagnostic messages to the server (section [2.1.12](#troubleshooting)). | +| `TRACY_ASSERT` | Route the client's internal checks through a custom assert implementation, instead of the standard `assert`. Define `TRACY_ASSERT(condition)` before including any Tracy header; the macro must accept a single condition argument. | _Tracy CMake options_ diff --git a/manual/tracy.tex b/manual/tracy.tex index 8c048e22..04226988 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -564,6 +564,7 @@ Each enabled option is passed down to your program as a preprocessor macro of th \textbf{Diagnostics} & \\ \texttt{TRACY\_VERBOSE} & Print detailed information about the detected features to the standard error output (section~\ref{troubleshooting}). \\ \texttt{TRACY\_NO\_INTERNAL\_MESSAGE} & Don't send the profiler's own diagnostic messages to the server (section~\ref{troubleshooting}). \\ +\texttt{TRACY\_ASSERT} & Route the client's internal checks through a custom assert implementation, instead of the standard \texttt{assert}. Define \texttt{TRACY\_ASSERT(condition)} before including any Tracy header; the macro must accept a single condition argument. \\ \end{longtable} \end{footnotesize} diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index a85d7758..402f4157 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -8,6 +8,7 @@ #include "TracyFastVector.hpp" #include "TracyStringHelpers.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyString.hpp" #include "../common/TracySystem.hpp" @@ -238,7 +239,7 @@ private: if( cache->ContainsImage( startAddress ) ) return 0; const uint32_t headerCount = info->dlpi_phnum; - assert( headerCount > 0 ); + TRACY_ASSERT( headerCount > 0 ); // headers aren't guaranteed to be in address order; find the max uint64_t endAddress = startAddress; @@ -321,7 +322,7 @@ static ImageCache* s_krnlCache; void CreateImageCaches() { - assert( s_imageCache == nullptr && s_krnlCache == nullptr ); + TRACY_ASSERT( s_imageCache == nullptr && s_krnlCache == nullptr ); s_imageCache = new ( tracy_malloc( sizeof( UserlandImageCache ) ) ) UserlandImageCache(); s_krnlCache = new ( tracy_malloc( sizeof( ImageCache ) ) ) ImageCache(); } @@ -677,7 +678,7 @@ void DbgHelpInit() } } - assert( length < sizeof( buffer ) ); + TRACY_ASSERT( length < sizeof( buffer ) ); if( SetEnvironmentVariableA( "_NT_SYMBOL_PATH", buffer ) == FALSE ) SymError( "SetEnvironmentVariableA", GetLastError() ); SymSetOptions( SymGetOptions() | SYMOPT_LOAD_LINES ); @@ -897,7 +898,7 @@ const char* DecodeCallstackPtrFast( uint64_t ptr ) const char* GetKernelModulePath( uint64_t addr ) { - assert( IsKernelAddress( addr ) ); + TRACY_ASSERT( IsKernelAddress( addr ) ); if( !s_krnlCache ) return nullptr; const ImageEntry* imageEntry = s_krnlCache->GetImageForAddress( addr ); if( imageEntry ) return imageEntry->m_path; @@ -1195,9 +1196,9 @@ static void InitKernelSymbols() } else { - assert( false ); + TRACY_ASSERT( false ); } - assert( ( v & ~0xF ) == 0 ); + TRACY_ASSERT( ( v & ~0xF ) == 0 ); addr <<= 4; addr |= v; ptr++; @@ -1257,7 +1258,7 @@ static void InitKernelSymbols() { if( v.name ) *dst++ = v; } - assert( dst == s_kernelSym + validCnt ); + TRACY_ASSERT( dst == s_kernelSym + validCnt ); TracyDebug( "Loaded %zu kernel symbols (%zu code sections)", tmpSym.size(), validCnt ); } @@ -1405,7 +1406,7 @@ int GetDebugInfoDescriptor( const char* buildid_data, size_t buildid_size, const const uint8_t* GetBuildIdForImage( const char* image, size_t& size ) { - assert( image ); + TRACY_ASSERT( image ); for( auto& v : *s_di_known ) { if( strcmp( image, v.filename ) == 0 ) @@ -1827,7 +1828,7 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr ) { cb_num = 0; backtrace_pcinfo( cb_bts, ptr, CallstackDataCb, CallstackErrorCb, nullptr ); - assert( cb_num > 0 ); + TRACY_ASSERT( cb_num > 0 ); backtrace_syminfo( cb_bts, ptr, SymInfoCallback, SymInfoError, nullptr ); } diff --git a/public/client/TracyCallstack.hpp b/public/client/TracyCallstack.hpp index 8f2a0fde..221c9895 100644 --- a/public/client/TracyCallstack.hpp +++ b/public/client/TracyCallstack.hpp @@ -46,10 +46,10 @@ static tracy_force_inline void* Callstack( int32_t /*depth*/ ) { return nullptr; # include #endif -#include #include #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" namespace tracy { @@ -106,7 +106,7 @@ extern "C" static tracy_force_inline void* Callstack( int32_t depth ) { - assert( depth >= 1 && depth < 63 ); + TRACY_ASSERT( depth >= 1 && depth < 63 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); const auto num = ___tracy_RtlWalkFrameChain( (void**)( trace + 1 ), depth, 0 ); *trace = num; @@ -135,7 +135,7 @@ static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, v static tracy_force_inline void* Callstack( int32_t depth ) { - assert( depth >= 1 && depth < 63 ); + TRACY_ASSERT( depth >= 1 && depth < 63 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); BacktraceState state = { (void**)(trace+1), (void**)(trace+1+depth) }; @@ -150,7 +150,7 @@ static tracy_force_inline void* Callstack( int32_t depth ) static tracy_force_inline void* Callstack( int32_t depth ) { - assert( depth >= 1 ); + TRACY_ASSERT( depth >= 1 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + (size_t)depth ) * sizeof( uintptr_t ) ); diff --git a/public/client/TracyDxt1.cpp b/public/client/TracyDxt1.cpp index 930d0982..4c96a4f7 100644 --- a/public/client/TracyDxt1.cpp +++ b/public/client/TracyDxt1.cpp @@ -1,7 +1,7 @@ #include "TracyDxt1.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyForceInline.hpp" -#include #include #include @@ -584,7 +584,7 @@ static tracy_force_inline void ProcessRGB_AVX( const uint8_t* src, char*& dst ) void CompressImageDxt1( const char* src, char* dst, int w, int h ) { - assert( (w % 4) == 0 && (h % 4) == 0 ); + TRACY_ASSERT( (w % 4) == 0 && (h % 4) == 0 ); #ifdef __AVX2__ if( w%8 == 0 ) diff --git a/public/client/TracyFastVector.hpp b/public/client/TracyFastVector.hpp index 38accc92..b94716e4 100644 --- a/public/client/TracyFastVector.hpp +++ b/public/client/TracyFastVector.hpp @@ -1,10 +1,10 @@ #ifndef __TRACYFASTVECTOR_HPP__ #define __TRACYFASTVECTOR_HPP__ -#include #include #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyForceInline.hpp" namespace tracy @@ -22,7 +22,7 @@ public: , m_write( m_ptr ) , m_end( m_ptr + capacity ) { - assert( capacity != 0 ); + TRACY_ASSERT( capacity != 0 ); } FastVector( const FastVector& ) = delete; @@ -47,11 +47,11 @@ public: T* end() { return m_write; } const T* end() const { return m_write; } - T& front() { assert( !empty() ); return m_ptr[0]; } - const T& front() const { assert( !empty() ); return m_ptr[0]; } + T& front() { TRACY_ASSERT( !empty() ); return m_ptr[0]; } + const T& front() const { TRACY_ASSERT( !empty() ); return m_ptr[0]; } - T& back() { assert( !empty() ); return m_write[-1]; } - const T& back() const { assert( !empty() ); return m_write[-1]; } + T& back() { TRACY_ASSERT( !empty() ); return m_write[-1]; } + const T& back() const { TRACY_ASSERT( !empty() ); return m_write[-1]; } T& operator[]( size_t idx ) { return m_ptr[idx]; } const T& operator[]( size_t idx ) const { return m_ptr[idx]; } diff --git a/public/client/TracyKCore.cpp b/public/client/TracyKCore.cpp index b95cf5dd..21d36f22 100644 --- a/public/client/TracyKCore.cpp +++ b/public/client/TracyKCore.cpp @@ -1,7 +1,6 @@ #ifdef __linux__ #include -#include #include #include #include @@ -10,6 +9,7 @@ #include "TracyElf.hpp" #include "TracyKCore.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" namespace tracy @@ -24,7 +24,7 @@ KCore::KCore() elf_ehdr ehdr; if( read( m_fd, &ehdr, sizeof( ehdr ) ) != sizeof( ehdr ) ) goto err; - assert( ehdr.e_phentsize == sizeof( elf_phdr ) ); + TRACY_ASSERT( ehdr.e_phentsize == sizeof( elf_phdr ) ); for( elf_half i=0; i::max)() ); + TRACY_ASSERT( m_id != (std::numeric_limits::max)() ); auto item = Profiler::QueueSerial(); MemWrite( &item->hdr.type, QueueType::LockAnnounce ); @@ -154,7 +155,7 @@ public: tracy_force_inline void CustomName( const char* name, size_t size ) { - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, name, size ); auto item = Profiler::QueueSerial(); @@ -236,7 +237,7 @@ public: , m_active( false ) #endif { - assert( m_id != (std::numeric_limits::max)() ); + TRACY_ASSERT( m_id != (std::numeric_limits::max)() ); auto item = Profiler::QueueSerial(); MemWrite( &item->hdr.type, QueueType::LockAnnounce ); @@ -451,7 +452,7 @@ public: tracy_force_inline void CustomName( const char* name, size_t size ) { - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, name, size ); auto item = Profiler::QueueSerial(); diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 9eaee7c5..97b12a55 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -56,7 +56,6 @@ #endif #include -#include #include #include #include @@ -69,6 +68,7 @@ #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracySocket.hpp" #include "../common/TracySystem.hpp" #include "../common/TracyYield.hpp" @@ -1169,7 +1169,7 @@ TRACY_API void TracyCrashHandler( int signal, siginfo_t* info, void* /*ucontext* #ifdef TRACY_HAS_SYSTEM_TRACING static void StartSystemTracing( int64_t& samplingPeriod ) { - assert( s_sysTraceThread == nullptr ); + TRACY_ASSERT( s_sysTraceThread == nullptr ); // use TRACY_NO_SYS_TRACE=1 to force disabling sys tracing (even if available in the underlying system) // as it can have significant impact on the size of the traces @@ -1184,7 +1184,7 @@ static void StartSystemTracing( int64_t& samplingPeriod ) Thread* sysTraceThread = (Thread*)tracy_malloc( sizeof( Thread ) ); new( sysTraceThread ) Thread( SysTraceWorker, nullptr ); Thread* prev = s_sysTraceThread.exchange( sysTraceThread ); - assert( prev == nullptr ); + TRACY_ASSERT( prev == nullptr ); std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) ); } } @@ -1280,7 +1280,7 @@ TRACY_API void StartupProfiler() } static ProfilerData& GetProfilerData() { - assert( s_profilerData ); + TRACY_ASSERT( s_profilerData ); return *s_profilerData; } TRACY_API void ShutdownProfiler() @@ -1338,13 +1338,13 @@ public: { int val = pthread_key_create(&m_key, sDestructor); static_cast(val); // unused - assert(val == 0); + TRACY_ASSERT(val == 0); } ~ProfilerThreadDataKey() { int val = pthread_key_delete(m_key); static_cast(val); // unused - assert(val == 0); + TRACY_ASSERT(val == 0); } ProfilerThreadData& get() { @@ -1507,7 +1507,7 @@ TRACY_API int32_t NextGpuContextId() if( id > UINT8_MAX ) { Profiler::LogString( MessageSourceType::Tracy, MessageSeverity::Error, 0, 0, "Tracy: more than 256 GPU contexts in this process; gpu context ids are 8-bit" ); - assert( false ); + TRACY_ASSERT( false ); return InvalidGpuContextId; } return int32_t( id ); @@ -1561,7 +1561,7 @@ Profiler::Profiler() , m_crashHandlerInstalled( false ) , m_programName( nullptr ) { - assert( !s_instance ); + TRACY_ASSERT( !s_instance ); s_instance = this; #ifndef TRACY_DELAYED_INIT @@ -1764,7 +1764,7 @@ Profiler::~Profiler() tracy_free( m_broadcast ); } - assert( s_instance ); + TRACY_ASSERT( s_instance ); s_instance = nullptr; } @@ -1990,7 +1990,7 @@ void Profiler::Worker() lastBroadcast = t; const auto ts = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count(); broadcastMsg.activeTime = int32_t( ts - m_epoch ); - assert( broadcastMsg.activeTime >= 0 ); + TRACY_ASSERT( broadcastMsg.activeTime >= 0 ); m_broadcast->Send( broadcastPort, &broadcastMsg, broadcastLen ); } } @@ -2522,7 +2522,7 @@ void Profiler::ClearQueues( moodycamel::ConsumerToken& token ) { for(;;) { - const auto sz = GetQueue().try_dequeue_bulk_single( token, [](const uint64_t&){}, []( QueueItem* item, size_t sz ) { assert( sz > 0 ); while( sz-- > 0 ) FreeAssociatedMemory( *item++ ); } ); + const auto sz = GetQueue().try_dequeue_bulk_single( token, [](const uint64_t&){}, []( QueueItem* item, size_t sz ) { TRACY_ASSERT( sz > 0 ); while( sz-- > 0 ) FreeAssociatedMemory( *item++ ); } ); if( sz == 0 ) break; } @@ -2563,7 +2563,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) { if( connectionLost ) return; InitAllocator(); - assert( sz > 0 ); + TRACY_ASSERT( sz > 0 ); int64_t refThread = m_refTimeThread; int64_t refCtx = m_refTimeCtx; int64_t refGpu = m_refTimeGpu; @@ -2921,7 +2921,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) #endif break; default: - assert( false ); + TRACY_ASSERT( false ); break; } } @@ -2948,7 +2948,7 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con const auto sz = GetQueue().try_dequeue_bulk_single( token, [] ( const uint64_t& ) {}, [this, &timeStop] ( QueueItem* item, size_t sz ) { - assert( sz > 0 ); + TRACY_ASSERT( sz > 0 ); int64_t refCtx = m_refTimeCtx; while( sz-- > 0 ) { @@ -3008,9 +3008,9 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con switch( ThreadCtxCheck( thread ) ) \ { \ case ThreadCtxStatus::Same: break; \ - case ThreadCtxStatus::Changed: assert( m_refTimeThread == 0 ); refThread = 0; break; \ + case ThreadCtxStatus::Changed: TRACY_ASSERT( m_refTimeThread == 0 ); refThread = 0; break; \ case ThreadCtxStatus::ConnectionLost: return DequeueStatus::ConnectionLost; \ - default: assert( false ); break; \ + default: TRACY_ASSERT( false ); break; \ } Profiler::DequeueStatus Profiler::DequeueSerial() @@ -3336,7 +3336,7 @@ Profiler::DequeueStatus Profiler::DequeueSerial() } #endif default: - assert( false ); + TRACY_ASSERT( false ); break; } } @@ -3423,7 +3423,7 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size ) bool success = true; char* buf = m_safeSendBuffer; #ifndef NDEBUG - assert( !m_inUse.exchange(true) ); + TRACY_ASSERT( !m_inUse.exchange(true) ); #endif if( size > SafeSendBufferSize ) buf = (char*)tracy_malloc( size ); @@ -3489,7 +3489,7 @@ bool Profiler::SendData( const char* data, size_t len ) void Profiler::SendString( uint64_t str, const char* ptr, size_t len, QueueType type ) { - assert( type == QueueType::StringData || + TRACY_ASSERT( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::PlotName || type == QueueType::FrameName || @@ -3501,7 +3501,7 @@ void Profiler::SendString( uint64_t str, const char* ptr, size_t len, QueueType MemWrite( &item.hdr.type, type ); MemWrite( &item.stringTransfer.ptr, str ); - assert( len <= std::numeric_limits::max() ); + TRACY_ASSERT( len <= std::numeric_limits::max() ); auto l16 = uint16_t( len ); NeedDataSize( QueueDataSize[(int)type] + sizeof( l16 ) + l16 ); @@ -3516,7 +3516,7 @@ void Profiler::SendSingleString8( const char* ptr, size_t len ) QueueItem item; MemWrite( &item.hdr.type, QueueType::SingleStringData8 ); - assert( len <= std::numeric_limits::max() ); + TRACY_ASSERT( len <= std::numeric_limits::max() ); auto l8 = uint8_t( len ); NeedDataSize( QueueDataSize[(int)QueueType::SingleStringData8] + sizeof( l8 ) + len ); @@ -3531,8 +3531,8 @@ void Profiler::SendSingleString16( const char* ptr, size_t len ) QueueItem item; MemWrite( &item.hdr.type, QueueType::SingleStringData ); - assert( len > std::numeric_limits::max() ); - assert( len <= ProtocolOffset8Bit + std::numeric_limits::max() ); + TRACY_ASSERT( len > std::numeric_limits::max() ); + TRACY_ASSERT( len <= ProtocolOffset8Bit + std::numeric_limits::max() ); auto l16 = uint16_t( len - ProtocolOffset8Bit ); NeedDataSize( QueueDataSize[(int)QueueType::SingleStringData] + sizeof( l16 ) + len ); @@ -3547,7 +3547,7 @@ void Profiler::SendSecondString8( const char* ptr, size_t len ) QueueItem item; MemWrite( &item.hdr.type, QueueType::SecondStringData8 ); - assert( len <= std::numeric_limits::max() ); + TRACY_ASSERT( len <= std::numeric_limits::max() ); auto l8 = uint8_t( len ); NeedDataSize( QueueDataSize[(int)QueueType::SecondStringData8] + sizeof( l8 ) + len ); @@ -3562,8 +3562,8 @@ void Profiler::SendSecondString16( const char* ptr, size_t len ) QueueItem item; MemWrite( &item.hdr.type, QueueType::SecondStringData ); - assert( len > std::numeric_limits::max() ); - assert( len <= ProtocolOffset8Bit + std::numeric_limits::max() ); + TRACY_ASSERT( len > std::numeric_limits::max() ); + TRACY_ASSERT( len <= ProtocolOffset8Bit + std::numeric_limits::max() ); auto l16 = uint16_t( len - ProtocolOffset8Bit ); NeedDataSize( QueueDataSize[(int)QueueType::SecondStringData] + sizeof( l16 ) + len ); @@ -3575,7 +3575,7 @@ void Profiler::SendSecondString16( const char* ptr, size_t len ) void Profiler::SendLongString( uint64_t str, const char* ptr, size_t len, QueueType type ) { - assert( type == QueueType::FrameImageData || + TRACY_ASSERT( type == QueueType::FrameImageData || type == QueueType::SymbolCode || type == QueueType::SourceCode ); @@ -3583,8 +3583,8 @@ void Profiler::SendLongString( uint64_t str, const char* ptr, size_t len, QueueT MemWrite( &item.hdr.type, type ); MemWrite( &item.stringTransfer.ptr, str ); - assert( len <= std::numeric_limits::max() ); - assert( QueueDataSize[(int)type] + sizeof( uint32_t ) + len <= TargetFrameSize ); + TRACY_ASSERT( len <= std::numeric_limits::max() ); + TRACY_ASSERT( QueueDataSize[(int)type] + sizeof( uint32_t ) + len <= TargetFrameSize ); auto l32 = uint32_t( len ); NeedDataSize( QueueDataSize[(int)type] + sizeof( l32 ) + l32 ); @@ -3619,7 +3619,7 @@ void Profiler::SendSourceLocationPayload( uint64_t _ptr ) uint16_t len; memcpy( &len, ptr, sizeof( len ) ); - assert( len > 2 ); + TRACY_ASSERT( len > 2 ); len -= 2; ptr += 2; @@ -3739,7 +3739,7 @@ void Profiler::QueueExternalName( uint64_t ptr ) void Profiler::QueueKernelCode( uint64_t symbol, uint32_t size ) { - assert( symbol >> 63 != 0 ); + TRACY_ASSERT( symbol >> 63 != 0 ); #ifdef TRACY_HAS_CALLSTACK m_symbolQueue.emplace( SymbolQueueItem { SymbolQueueItemType::KernelCode, symbol, size } ); #else @@ -3749,8 +3749,8 @@ void Profiler::QueueKernelCode( uint64_t symbol, uint32_t size ) void Profiler::QueueSourceCodeQuery( uint32_t id ) { - assert( m_exectime != 0 ); - assert( m_queryData ); + TRACY_ASSERT( m_exectime != 0 ); + TRACY_ASSERT( m_queryData ); m_symbolQueue.emplace( SymbolQueueItem { SymbolQueueItemType::SourceCode, uint64_t( m_queryData ), uint64_t( m_queryImage ), id } ); m_queryData = nullptr; m_queryImage = nullptr; @@ -3858,7 +3858,7 @@ void Profiler::HandleSymbolQueueItem( const SymbolQueueItem& si ) HandleSourceCodeQuery( (char*)si.ptr, (char*)si.extra, si.id ); break; default: - assert( false ); + TRACY_ASSERT( false ); break; } } @@ -3993,7 +3993,7 @@ bool Profiler::HandleServerQuery() case ServerQueryDataTransfer: if( m_queryData ) { - assert( !m_queryImage ); + TRACY_ASSERT( !m_queryImage ); m_queryImage = m_queryData; } m_queryDataPtr = m_queryData = (char*)tracy_malloc( ptr + 11 ); @@ -4011,7 +4011,7 @@ bool Profiler::HandleServerQuery() break; #endif default: - assert( false ); + TRACY_ASSERT( false ); break; } @@ -4175,7 +4175,7 @@ void Profiler::ReportTopology() { packageInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( psz ); auto res = _GetLogicalProcessorInformationEx( RelationProcessorPackage, packageInfo, &psz ); - assert( res ); + TRACY_ASSERT( res ); } else { @@ -4188,7 +4188,7 @@ void Profiler::ReportTopology() { dieInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( dsz ); auto res = _GetLogicalProcessorInformationEx( RelationProcessorDie, dieInfo, &dsz ); - assert( res ); + TRACY_ASSERT( res ); } else { @@ -4201,7 +4201,7 @@ void Profiler::ReportTopology() { coreInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( csz ); auto res = _GetLogicalProcessorInformationEx( RelationProcessorCore, coreInfo, &csz ); - assert( res ); + TRACY_ASSERT( res ); } else { @@ -4220,7 +4220,7 @@ void Profiler::ReportTopology() auto ptr = packageInfo; while( (char*)ptr < ((char*)packageInfo) + psz ) { - assert( ptr->Relationship == RelationProcessorPackage ); + TRACY_ASSERT( ptr->Relationship == RelationProcessorPackage ); // FIXME account for GroupCount auto mask = ptr->Processor.GroupMask[0].Mask; int core = 0; @@ -4238,7 +4238,7 @@ void Profiler::ReportTopology() ptr = dieInfo; while( (char*)ptr < ((char*)dieInfo) + dsz ) { - assert( ptr->Relationship == RelationProcessorDie ); + TRACY_ASSERT( ptr->Relationship == RelationProcessorDie ); // FIXME account for GroupCount auto mask = ptr->Processor.GroupMask[0].Mask; int core = 0; @@ -4256,7 +4256,7 @@ void Profiler::ReportTopology() ptr = coreInfo; while( (char*)ptr < ((char*)coreInfo) + csz ) { - assert( ptr->Relationship == RelationProcessorCore ); + TRACY_ASSERT( ptr->Relationship == RelationProcessorCore ); // FIXME account for GroupCount auto mask = ptr->Processor.GroupMask[0].Mask; int core = 0; @@ -4422,7 +4422,7 @@ void Profiler::ProcessSysTime() void Profiler::HandleParameter( uint64_t payload ) { - assert( m_paramCallback ); + TRACY_ASSERT( m_paramCallback ); const auto idx = uint32_t( payload >> 32 ); const auto val = int32_t( payload & 0xFFFFFFFF ); m_paramCallback( m_paramCallbackData, idx, val ); @@ -4740,7 +4740,7 @@ TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ) TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size ) { - assert( size < std::numeric_limits::max() ); + TRACY_ASSERT( size < std::numeric_limits::max() ); if( !ctx.active ) return; #ifdef TRACY_ON_DEMAND if( tracy::GetProfiler().ConnectionId() != ctx.connectionId ) return; @@ -4773,7 +4773,7 @@ TRACY_API void ___tracy_emit_zone_text_fmt( TracyCZoneCtx ctx, const char* fmt, auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy::tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); @@ -4795,7 +4795,7 @@ TRACY_API void ___tracy_emit_zone_text_fmt( TracyCZoneCtx ctx, const char* fmt, TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size ) { - assert( size < std::numeric_limits::max() ); + TRACY_ASSERT( size < std::numeric_limits::max() ); if( !ctx.active ) return; #ifdef TRACY_ON_DEMAND if( tracy::GetProfiler().ConnectionId() != ctx.connectionId ) return; @@ -4828,7 +4828,7 @@ TRACY_API void ___tracy_emit_zone_name_fmt( TracyCZoneCtx ctx, const char* fmt, auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy::tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); @@ -5304,7 +5304,7 @@ TRACY_API struct __tracy_lockable_context_data* ___tracy_announce_lockable_ctx( new(&lockdata->m_lockCount) std::atomic( 0 ); new(&lockdata->m_active) std::atomic( false ); #endif - assert( lockdata->m_id != (std::numeric_limits::max)() ); + TRACY_ASSERT( lockdata->m_id != (std::numeric_limits::max)() ); auto item = tracy::Profiler::QueueSerial(); tracy::MemWrite( &item->hdr.type, tracy::QueueType::LockAnnounce ); @@ -5442,7 +5442,7 @@ TRACY_API void ___tracy_mark_lockable_ctx( struct __tracy_lockable_context_data* TRACY_API void ___tracy_custom_name_lockable_ctx( struct __tracy_lockable_context_data* lockdata, const char* name, size_t nameSz ) { - assert( nameSz < (std::numeric_limits::max)() ); + TRACY_ASSERT( nameSz < (std::numeric_limits::max)() ); auto ptr = (char*)tracy::tracy_malloc( nameSz ); memcpy( ptr, name, nameSz ); auto item = tracy::Profiler::QueueSerial(); @@ -5468,7 +5468,7 @@ TRACY_API struct __tracy_shared_lockable_context_data* ___tracy_announce_shared_ new(&lockdata->m_base.m_lockCount) std::atomic( 0 ); new(&lockdata->m_base.m_active) std::atomic( false ); #endif - assert( lockdata->m_base.m_id != (std::numeric_limits::max)() ); + TRACY_ASSERT( lockdata->m_base.m_id != (std::numeric_limits::max)() ); auto item = tracy::Profiler::QueueSerial(); tracy::MemWrite( &item->hdr.type, tracy::QueueType::LockAnnounce ); diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index d7f3cf39..baa669f4 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -1,7 +1,6 @@ #ifndef __TRACYPROFILER_HPP__ #define __TRACYPROFILER_HPP__ -#include #include #include #include @@ -20,6 +19,7 @@ #include "../common/TracyQueue.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyFormat.h" #include "../common/TracyMutex.hpp" #include "../common/TracyProtocol.hpp" @@ -363,7 +363,7 @@ public: static tracy_force_inline void SendFrameMark( const char* name, QueueType type ) { - assert( type == QueueType::FrameMarkMsgStart || type == QueueType::FrameMarkMsgEnd ); + TRACY_ASSERT( type == QueueType::FrameMarkMsgStart || type == QueueType::FrameMarkMsgEnd ); #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif @@ -378,7 +378,7 @@ public: { #ifndef TRACY_NO_FRAME_IMAGE auto& profiler = GetProfiler(); - assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < (std::numeric_limits::max)() ); + TRACY_ASSERT( profiler.m_frameCount.load( std::memory_order_relaxed ) < (std::numeric_limits::max)() ); # ifdef TRACY_ON_DEMAND if( !profiler.IsConnected() ) return; # endif @@ -458,7 +458,7 @@ public: static tracy_force_inline void LogString( MessageSourceType source, MessageSeverity severity, uint32_t color, int32_t callstack_depth, size_t txtLength, const char* txt ) { - assert( txtLength < (std::numeric_limits::max)() ); + TRACY_ASSERT( txtLength < (std::numeric_limits::max)() ); #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif @@ -526,7 +526,7 @@ public: static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) { - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); TaggedUserlandAddress taggedPtr{ (uint64_t)ptr, MakeMessageMetadata( MessageSourceType::User, MessageSeverity::Info ) }; @@ -756,7 +756,7 @@ public: static tracy_force_inline void ParameterSetup( uint32_t idx, const char* name, uint8_t type, int32_t val ) { - assert( type >= 0 && type <= 2 ); + TRACY_ASSERT( type >= 0 && type <= 2 ); TracyLfqPrepare( QueueType::ParamSetup ); tracy::MemWrite( &item->paramSetup.idx, idx ); tracy::MemWrite( &item->paramSetup.name, (uint64_t)name ); @@ -812,7 +812,7 @@ public: auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return 0; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); @@ -849,7 +849,7 @@ public: auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); @@ -939,7 +939,7 @@ public: static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, uint32_t color = 0 ) { const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz ); - assert( sz32 <= (std::numeric_limits::max)() ); + TRACY_ASSERT( sz32 <= (std::numeric_limits::max)() ); const auto sz = uint16_t( sz32 ); auto ptr = (char*)tracy_malloc( sz ); memcpy( ptr, &sz, 2 ); @@ -994,7 +994,7 @@ private: tracy_force_inline bool NeedDataSize( size_t len ) { - assert( len <= TargetFrameSize ); + TRACY_ASSERT( len <= TargetFrameSize ); bool ret = true; if( m_bufferOffset - m_bufferStart + (int)len > (int)TargetFrameSize ) { @@ -1069,7 +1069,7 @@ private: static tracy_force_inline void SendMemAlloc( QueueType type, const uint32_t thread, const void* ptr, size_t size ) { - assert( type == QueueType::MemAlloc || type == QueueType::MemAllocCallstack || type == QueueType::MemAllocNamed || type == QueueType::MemAllocCallstackNamed ); + TRACY_ASSERT( type == QueueType::MemAlloc || type == QueueType::MemAllocCallstack || type == QueueType::MemAllocNamed || type == QueueType::MemAllocCallstackNamed ); auto item = GetProfiler().m_serialQueue.prepare_next(); MemWrite( &item->hdr.type, type ); @@ -1083,7 +1083,7 @@ private: } else { - assert( sizeof( size ) == 8 ); + TRACY_ASSERT( sizeof( size ) == 8 ); memcpy( &item->memAlloc.size, &size, 4 ); memcpy( ((char*)&item->memAlloc.size)+4, ((char*)&size)+4, 2 ); } @@ -1092,7 +1092,7 @@ private: static tracy_force_inline void SendMemFree( QueueType type, const uint32_t thread, const void* ptr ) { - assert( type == QueueType::MemFree || type == QueueType::MemFreeCallstack || type == QueueType::MemFreeNamed || type == QueueType::MemFreeCallstackNamed ); + TRACY_ASSERT( type == QueueType::MemFree || type == QueueType::MemFreeCallstack || type == QueueType::MemFreeNamed || type == QueueType::MemFreeCallstackNamed ); auto item = GetProfiler().m_serialQueue.prepare_next(); MemWrite( &item->hdr.type, type ); @@ -1104,7 +1104,7 @@ private: static tracy_force_inline void SendMemDiscard( QueueType type, const uint32_t thread, const char* name ) { - assert( type == QueueType::MemDiscard || type == QueueType::MemDiscardCallstack ); + TRACY_ASSERT( type == QueueType::MemDiscard || type == QueueType::MemDiscardCallstack ); auto item = GetProfiler().m_serialQueue.prepare_next(); MemWrite( &item->hdr.type, type ); @@ -1116,7 +1116,7 @@ private: static tracy_force_inline void SendMemName( const char* name ) { - assert( name ); + TRACY_ASSERT( name ); auto item = GetProfiler().m_serialQueue.prepare_next(); MemWrite( &item->hdr.type, QueueType::MemNamePayload ); MemWrite( &item->memName.name, (uint64_t)name ); diff --git a/public/client/TracyRingBuffer.hpp b/public/client/TracyRingBuffer.hpp index 2fda6cae..4ac1e43c 100644 --- a/public/client/TracyRingBuffer.hpp +++ b/public/client/TracyRingBuffer.hpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -9,6 +8,7 @@ #include #include "TracyDebug.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyForceInline.hpp" namespace tracy @@ -25,8 +25,8 @@ public: , m_fd( fd ) { const auto pageSize = uint32_t( getpagesize() ); - assert( size >= pageSize ); - assert( __builtin_popcount( size ) == 1 ); + TRACY_ASSERT( size >= pageSize ); + TRACY_ASSERT( __builtin_popcount( size ) == 1 ); m_mapSize = size + pageSize; auto mapAddr = mmap( nullptr, m_mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if( mapAddr == MAP_FAILED ) @@ -38,7 +38,7 @@ public: return; } m_metadata = (perf_event_mmap_page*)mapAddr; - assert( m_metadata->data_offset == pageSize ); + TRACY_ASSERT( m_metadata->data_offset == pageSize ); m_buffer = ((char*)mapAddr) + pageSize; m_tail = m_metadata->data_tail; } diff --git a/public/client/TracyRocprof.cpp b/public/client/TracyRocprof.cpp index d9f2e749..b8f9b298 100644 --- a/public/client/TracyRocprof.cpp +++ b/public/client/TracyRocprof.cpp @@ -1,3 +1,4 @@ +#include "../common/TracyAssert.hpp" #include "../server/tracy_robin_hood.h" #include "TracyProfiler.hpp" #include "TracyThread.hpp" @@ -238,7 +239,7 @@ void record_callback( rocprofiler_dispatch_counting_service_data_t dispatch_data rocprofiler_record_counter_t* record_data, size_t record_count, rocprofiler_user_data_t /*user_data*/, void* callback_data ) { - assert( callback_data != nullptr ); + TRACY_ASSERT( callback_data != nullptr ); ToolData* data = static_cast( callback_data ); if( !data->init ) return; @@ -257,7 +258,7 @@ void record_callback( rocprofiler_dispatch_counting_service_data_t dispatch_data auto _lk = std::unique_lock{ data->mut }; // An assumption is made here that the counter values are supplied after the dispatch // complete callback. - assert( data->dispatch_data.count( dispatch_data.dispatch_info.dispatch_id ) ); + TRACY_ASSERT( data->dispatch_data.count( dispatch_data.dispatch_info.dispatch_id ) ); DispatchData& ddata = data->dispatch_data[dispatch_data.dispatch_info.dispatch_id]; query_id = ddata.query_id; thread_id = ddata.thread_id; @@ -285,7 +286,7 @@ void dispatch_callback( rocprofiler_dispatch_counting_service_data_t dispatch_da rocprofiler_profile_config_id_t* config, rocprofiler_user_data_t* /*user_data*/, void* callback_data ) { - assert( callback_data != nullptr ); + TRACY_ASSERT( callback_data != nullptr ); ToolData* data = static_cast( callback_data ); if( !data->init ) return; @@ -379,7 +380,7 @@ void dispatch_callback( rocprofiler_dispatch_counting_service_data_t dispatch_da void tool_callback_tracing_callback( rocprofiler_callback_tracing_record_t record, rocprofiler_user_data_t* user_data, void* callback_data ) { - assert( callback_data != nullptr ); + TRACY_ASSERT( callback_data != nullptr ); ToolData* data = static_cast( callback_data ); // Kernel symbol registrations happen at HIP init time, before any Tracy diff --git a/public/client/TracyScoped.hpp b/public/client/TracyScoped.hpp index a05a6ab3..34611acc 100644 --- a/public/client/TracyScoped.hpp +++ b/public/client/TracyScoped.hpp @@ -9,6 +9,7 @@ #include "../common/TracySystem.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyFormat.h" #include "TracyProfiler.hpp" #include "TracyCallstack.hpp" @@ -87,7 +88,7 @@ public: tracy_force_inline void Text( const char* txt, size_t size ) { - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); if( !m_active ) return; #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; @@ -111,7 +112,7 @@ public: auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); @@ -126,7 +127,7 @@ public: tracy_force_inline void Name( const char* txt, size_t size ) { - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); if( !m_active ) return; #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; @@ -150,7 +151,7 @@ public: auto size = vsnprintf( nullptr, 0, fmt, args ); va_end( args ); if( size < 0 ) return; - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); char* ptr = (char*)tracy_malloc( size_t( size ) + 1 ); va_start( args, fmt ); diff --git a/public/client/TracySysTrace.cpp b/public/client/TracySysTrace.cpp index d782a3a5..a99b46cc 100644 --- a/public/client/TracySysTrace.cpp +++ b/public/client/TracySysTrace.cpp @@ -1,6 +1,7 @@ #include "TracyDebug.hpp" #include "TracyStringHelpers.hpp" #include "TracySysTrace.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracySystem.hpp" #ifdef TRACY_HAS_SYSTEM_TRACING @@ -50,7 +51,6 @@ static int SamplingFrequencyToPeriodNs( int samplingHz ) # endif # define INITGUID -# include # include # include # include @@ -160,7 +160,7 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record ) } break; case etw::DxgKrnlGuid.Data1: - assert( hdr.EventDescriptor.Id == etw::VSyncDPC::EventId ); + TRACY_ASSERT( hdr.EventDescriptor.Id == etw::VSyncDPC::EventId ); { const auto vs = (const etw::VSyncDPC*)record->UserData; TracyLfqPrepare( QueueType::FrameVsync ); @@ -1167,11 +1167,11 @@ void SysTraceWorker( void* ptr ) const auto head = ring.LoadHead(); const auto tail = ring.GetTail(); if( head == tail ) continue; - assert( head > tail ); + TRACY_ASSERT( head > tail ); hadData = true; const auto id = ring.GetId(); - assert( id != EventContextSwitch ); + TRACY_ASSERT( id != EventContextSwitch ); const auto end = head - tail; uint64_t pos = 0; if( id == EventCallstack ) @@ -1277,7 +1277,7 @@ void SysTraceWorker( void* ptr ) pos += hdr.size; } } - assert( pos == end ); + TRACY_ASSERT( pos == end ); ring.Advance( end ); } if( !traceActive.load( std::memory_order_relaxed ) ) break; @@ -1302,7 +1302,7 @@ void SysTraceWorker( void* ptr ) ring.Read( time + idx, pos[idx] + sizeof( hdr ), sizeof( int64_t ) ); return true; } - assert( hdr.size > 0 ); + TRACY_ASSERT( hdr.size > 0 ); pos[idx] += hdr.size; } return false; @@ -1351,7 +1351,7 @@ void SysTraceWorker( void* ptr ) // Found any event if( sel >= 0 ) { - assert( pos[sel] < end[sel] ); + TRACY_ASSERT( pos[sel] < end[sel] ); auto& ring = ringArray[ctxBufferIdx + sel]; auto rbPos = pos[sel]; @@ -1472,7 +1472,7 @@ void SysTraceWorker( void* ptr ) } else { - assert( rid == EventVsync ); + TRACY_ASSERT( rid == EventVsync ); // Layout: // u64 time // u32 size diff --git a/public/common/TracyAssert.hpp b/public/common/TracyAssert.hpp new file mode 100644 index 00000000..7421b202 --- /dev/null +++ b/public/common/TracyAssert.hpp @@ -0,0 +1,12 @@ +#ifndef __TRACYASSERT_HPP__ +#define __TRACYASSERT_HPP__ + +// Define TRACY_ASSERT(condition) before including any Tracy header to +// route the internal checks through a custom assert implementation. +// Falls back to the standard assert when not defined. +#ifndef TRACY_ASSERT +# include +# define TRACY_ASSERT(x) assert(x) +#endif + +#endif diff --git a/public/common/TracyQueue.hpp b/public/common/TracyQueue.hpp index 76dde707..db5a70f7 100644 --- a/public/common/TracyQueue.hpp +++ b/public/common/TracyQueue.hpp @@ -3,6 +3,7 @@ #include #include +#include "TracyAssert.hpp" #include "TracyTaggedUserlandAddress.hpp" #include "TracyForceInline.hpp" @@ -439,13 +440,13 @@ tracy_force_inline uint8_t MakeMessageMetadata(MessageSourceType source, Message tracy_force_inline MessageSourceType MessageSourceFromMetadata(uint8_t metadata) { - assert( ( metadata & 0x0F ) < (uint8_t)MessageSourceType::COUNT ); + TRACY_ASSERT( ( metadata & 0x0F ) < (uint8_t)MessageSourceType::COUNT ); return (MessageSourceType)( metadata & 0x0F ); } tracy_force_inline MessageSeverity MessageSeverityFromMetadata(uint8_t metadata) { - assert( ( ( metadata & 0xF0 ) >> 4 ) < (uint8_t)MessageSeverity::COUNT ); + TRACY_ASSERT( ( ( metadata & 0xF0 ) >> 4 ) < (uint8_t)MessageSeverity::COUNT ); return (MessageSeverity)( ( metadata & 0xF0 ) >> 4 ); } diff --git a/public/common/TracySocket.cpp b/public/common/TracySocket.cpp index 895b6f2d..2d0488cf 100644 --- a/public/common/TracySocket.cpp +++ b/public/common/TracySocket.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -7,6 +6,7 @@ #include #include "TracyAlloc.hpp" +#include "TracyAssert.hpp" #include "TracySocket.hpp" #include "TracySystem.hpp" @@ -125,7 +125,7 @@ Socket::~Socket() bool Socket::Connect( const char* addr, uint16_t port ) { - assert( !IsValid() ); + TRACY_ASSERT( !IsValid() ); if( m_ptr ) { @@ -238,8 +238,8 @@ bool Socket::Connect( const char* addr, uint16_t port ) bool Socket::ConnectBlocking( const char* addr, uint16_t port ) { - assert( !IsValid() ); - assert( !m_ptr ); + TRACY_ASSERT( !IsValid() ); + TRACY_ASSERT( !m_ptr ); struct addrinfo hints; struct addrinfo *res, *ptr; @@ -281,7 +281,7 @@ bool Socket::ConnectBlocking( const char* addr, uint16_t port ) void Socket::Close() { const auto sock = m_sock.load( std::memory_order_relaxed ); - assert( sock != -1 ); + TRACY_ASSERT( sock != -1 ); #ifdef _WIN32 closesocket( sock ); #else @@ -294,7 +294,7 @@ int Socket::Send( const void* _buf, int len ) { const auto sock = m_sock.load( std::memory_order_relaxed ); auto buf = (const char*)_buf; - assert( sock != -1 ); + TRACY_ASSERT( sock != -1 ); auto start = buf; while( len > 0 ) { @@ -487,7 +487,7 @@ static int addrinfo_and_socket_for_family( uint16_t port, int ai_family, struct bool ListenSocket::Listen( uint16_t port, int backlog ) { - assert( m_sock == -1 ); + TRACY_ASSERT( m_sock == -1 ); struct addrinfo* res = nullptr; @@ -556,7 +556,7 @@ Socket* ListenSocket::Accept() void ListenSocket::Close() { - assert( m_sock != -1 ); + TRACY_ASSERT( m_sock != -1 ); #ifdef _WIN32 closesocket( m_sock ); #else @@ -580,7 +580,7 @@ UdpBroadcast::~UdpBroadcast() bool UdpBroadcast::Open( const char* addr, uint16_t port ) { - assert( m_sock == -1 ); + TRACY_ASSERT( m_sock == -1 ); struct addrinfo hints; struct addrinfo *res, *ptr; @@ -628,7 +628,7 @@ bool UdpBroadcast::Open( const char* addr, uint16_t port ) void UdpBroadcast::Close() { - assert( m_sock != -1 ); + TRACY_ASSERT( m_sock != -1 ); #ifdef _WIN32 closesocket( m_sock ); #else @@ -639,7 +639,7 @@ void UdpBroadcast::Close() int UdpBroadcast::Send( uint16_t port, const void* data, int len ) { - assert( m_sock != -1 ); + TRACY_ASSERT( m_sock != -1 ); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons( port ); @@ -685,7 +685,7 @@ UdpListen::~UdpListen() bool UdpListen::Listen( uint16_t port ) { - assert( m_sock == -1 ); + TRACY_ASSERT( m_sock == -1 ); int sock; if( ( sock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == -1 ) return false; @@ -738,7 +738,7 @@ bool UdpListen::Listen( uint16_t port ) void UdpListen::Close() { - assert( m_sock != -1 ); + TRACY_ASSERT( m_sock != -1 ); #ifdef _WIN32 closesocket( m_sock ); #else diff --git a/public/common/TracyString.hpp b/public/common/TracyString.hpp index ad3f5cb1..eb963e41 100644 --- a/public/common/TracyString.hpp +++ b/public/common/TracyString.hpp @@ -1,16 +1,17 @@ #ifndef __TRACYSTRING_HPP__ #define __TRACYSTRING_HPP__ -#include #include #include +#include "TracyAssert.hpp" + namespace tracy { static inline size_t strzcpy( char* __restrict dst, const char* __restrict src, size_t dstSize ) { - assert( dstSize > 0 ); + TRACY_ASSERT( dstSize > 0 ); const auto end = (const char*)memchr( src, '\0', dstSize ); if( end != nullptr ) diff --git a/public/common/TracyTaggedUserlandAddress.hpp b/public/common/TracyTaggedUserlandAddress.hpp index 03308db5..3daf45ed 100644 --- a/public/common/TracyTaggedUserlandAddress.hpp +++ b/public/common/TracyTaggedUserlandAddress.hpp @@ -2,8 +2,8 @@ #define __TRACYTAGGEDPTR_HPP__ #include -#include +#include "TracyAssert.hpp" #include "TracyForceInline.hpp" namespace tracy @@ -18,7 +18,7 @@ public: TaggedUserlandAddress() = default; tracy_force_inline explicit TaggedUserlandAddress( uint64_t address, uint8_t tag = 0 ) { - assert( ( address & highBits ) == 0 ); + TRACY_ASSERT( ( address & highBits ) == 0 ); m_storage = ( address << ptrShift ) | tag; } diff --git a/public/tracy/TracyCUDA.hpp b/public/tracy/TracyCUDA.hpp index df578205..4de959b7 100644 --- a/public/tracy/TracyCUDA.hpp +++ b/public/tracy/TracyCUDA.hpp @@ -23,7 +23,6 @@ using CUDACtx = std::nullptr_t; #error "CUDA v12.4 (or later) is required by TracyCUDA.hpp" #endif -#include #include #include #include @@ -40,6 +39,7 @@ using CUDACtx = std::nullptr_t; #include #endif +#include "../common/TracyAssert.hpp" #include "Tracy.hpp" #ifndef UNREFERENCED @@ -121,7 +121,7 @@ TracyTimestamp tracyFromCUpti(CUptiTimestamp cuptiTime) { auto [slope, intercept] = getCachedRegressionParameters(); double y_hat = slope * cuptiTime + intercept; TracyTimestamp tracyTime = TracyTimestamp(y_hat); - assert(tracyTime >= 0); + TRACY_ASSERT(tracyTime >= 0); return tracyTime; } @@ -210,7 +210,7 @@ void tracyEmitMemAlloc(const char* name, const void* ptr, size_t size, TracyTime } else { - assert(sizeof(size) == 8); + TRACY_ASSERT(sizeof(size) == 8); memcpy(&item->memAlloc.size, &size, 4); memcpy(((char *)&item->memAlloc.size) + 4, ((char *)&size) + 4, 2); } @@ -294,7 +294,7 @@ CUptiResult CUptiCallChecked(CUptiResult result, const char* call, const char* f const char* resultMsg = ""; CUPTI_API_CALL(cuptiGetResultString(result, &resultMsg)); // maybe not a good idea to recurse here... fprintf(stderr, "ERROR:\t%s:%d:\n\tfunction '%s' failed with error '%s'.\n", file, line, call, resultMsg); - //assert(result == CUPTI_SUCCESS); + //TRACY_ASSERT(result == CUPTI_SUCCESS); return result; } @@ -304,7 +304,7 @@ CUresult cudaDriverCallChecked(CUresult result, const char* call, const char* fi const char* resultMsg = ""; DRIVER_API_CALL(cuGetErrorString(result, &resultMsg)); // maybe not a good idea to recurse here... fprintf(stderr, "ERROR:\t%s:%d:\n\tfunction '%s' failed with error '%s'.\n", file, line, call, resultMsg); - //assert(result == CUDA_SUCCESS); + //TRACY_ASSERT(result == CUDA_SUCCESS); return result; } @@ -416,7 +416,7 @@ struct StringTable { } memoized = it->second; } - assert(str == memoized); + TRACY_ASSERT(str == memoized); return memoized; } }; @@ -439,8 +439,8 @@ struct SourceLocationMap { tracy::SourceLocationData* add(std::string_view function, std::string_view file, int line, uint32_t color=0) { ZoneNamed(emplace, instrument); - assert(*function.end() == '\0'); - assert(*file.end() == '\0'); + TRACY_ASSERT(*function.end() == '\0'); + TRACY_ASSERT(*file.end() == '\0'); void* bytes = tracyMalloc(sizeof(tracy::SourceLocationData)); auto pSrcLoc = new(bytes)tracy::SourceLocationData{ function.data(), TracyFunction, file.data(), (uint32_t)line, color }; auto [it, inserted] = locations.emplace(function, pSrcLoc); @@ -448,7 +448,7 @@ struct SourceLocationMap { // another thread inserted it while we were trying to: cleanup tracyFree(pSrcLoc); // POD: no destructor to call } - assert(it->second != nullptr); + TRACY_ASSERT(it->second != nullptr); return it->second; } }; @@ -491,8 +491,8 @@ struct SourceLocationLUT { uint32_t tracyTimelineId(uint32_t contextId, uint32_t streamId) { // 0xA7C5 = 42,949 => 42,949 * 100,000 = 4,294,900,000 // 4,294,900,000 + 65,535 = 4,294,965,535 < 4,294,967,295 (max uint32) - assert(contextId <= 0xA7C5); - assert((streamId == CUPTI_INVALID_STREAM_ID) || (streamId < 0xFFFF)); + TRACY_ASSERT(contextId <= 0xA7C5); + TRACY_ASSERT((streamId == CUPTI_INVALID_STREAM_ID) || (streamId < 0xFFFF)); uint32_t packed = (contextId * 100'000) + (streamId & 0x0000'FFFF); return packed; } @@ -508,7 +508,7 @@ namespace tracy auto& s = Singleton::Get(); std::unique_lock lock (s.m); if (s.ref_count == 0) { - assert(s.ctx == nullptr); + TRACY_ASSERT(s.ctx == nullptr); s.ctx = new CUDACtx(s.ctx_id); s.ref_count += 1; s.ctx_id = s.ctx->m_tracyGpuContext; @@ -519,7 +519,7 @@ namespace tracy static void Destroy(CUDACtx* ctx) { auto& s = Singleton::Get(); std::unique_lock lock(s.m); - assert(ctx == s.ctx); + TRACY_ASSERT(ctx == s.ctx); s.ref_count -= 1; if (s.ref_count == 0) { delete s.ctx; @@ -663,7 +663,7 @@ namespace tracy // should return as quickly as possible from these callbacks." *size = 1 * 1024*1024; // 1MB *buffer = (uint8_t*)tracyMalloc(*size); - assert(*buffer != nullptr); + TRACY_ASSERT(*buffer != nullptr); FlushActivityAsync(); } @@ -708,7 +708,7 @@ namespace tracy } size_t dropped = 0; CUPTI_API_CALL(cuptiActivityGetNumDroppedRecords(ctx, streamId, &dropped)); - assert(dropped == 0); + TRACY_ASSERT(dropped == 0); tracyFree(buffer); // Retire cudaGraphCurrentLaunch entries for destroyed exec handles. @@ -924,7 +924,7 @@ namespace tracy cudaCallSiteInfo.emplace(apiInfo->correlationId, APICallInfo{ apiCallStartTime, apiCallStartTime, tgpu, profilerHost }); } auto& entryFlags = *apiInfo->correlationData; - assert(entryFlags == 0); + TRACY_ASSERT(entryFlags == 0); entryFlags |= trackDeviceActivity ? 0x8000 : 0; // On graph exec destruction, record the graphId for deferred @@ -984,7 +984,7 @@ namespace tracy return false; } cudaCallSiteInfo.erase(correlationId); - assert(apiCallInfo.host != nullptr); + TRACY_ASSERT(apiCallInfo.host != nullptr); return true; } @@ -1420,7 +1420,7 @@ namespace tracy } m_tracyGpuContext = NextGpuContextId(); - assert(m_tracyGpuContext != InvalidGpuContextId); + TRACY_ASSERT(m_tracyGpuContext != InvalidGpuContextId); TracyTimestamp tTracy; CUptiTimestamp tCUpti; diff --git a/public/tracy/TracyD3D11.hpp b/public/tracy/TracyD3D11.hpp index a63d6604..af64fea8 100644 --- a/public/tracy/TracyD3D11.hpp +++ b/public/tracy/TracyD3D11.hpp @@ -33,17 +33,17 @@ using TracyD3D11Ctx = void*; #else #include -#include #include #include "Tracy.hpp" #include "../client/TracyProfiler.hpp" #include "../client/TracyCallstack.hpp" +#include "../common/TracyAssert.hpp" #include "../common/TracyYield.hpp" #include -#define TracyD3D11Panic(msg, ...) do { assert(false && "TracyD3D11: " msg); TracyMessageLC("TracyD3D11: " msg, tracy::Color::Red4); __VA_ARGS__; } while(false); +#define TracyD3D11Panic(msg, ...) do { TRACY_ASSERT(false && "TracyD3D11: " msg); TracyMessageLC("TracyD3D11: " msg, tracy::Color::Red4); __VA_ARGS__; } while(false); namespace tracy { diff --git a/public/tracy/TracyD3D12.hpp b/public/tracy/TracyD3D12.hpp index 0865b113..9f2182f0 100644 --- a/public/tracy/TracyD3D12.hpp +++ b/public/tracy/TracyD3D12.hpp @@ -34,12 +34,12 @@ using TracyD3D12Ctx = void*; #include "Tracy.hpp" #include "../client/TracyFastVector.hpp" +#include "../common/TracyAssert.hpp" #include #include #include #include -#include #include #include @@ -62,7 +62,7 @@ using TracyD3D12Ctx = void*; #else # define TracyD3D12Debug(...) # define TracyD3D12Break() -# define TracyD3D12Assert(predicate, ...) assert(predicate); +# define TracyD3D12Assert(predicate, ...) TRACY_ASSERT(predicate); #endif #define TracyD3D12Log(severity, msg) tracy::Profiler::LogString( tracy::MessageSourceType::Tracy, tracy::MessageSeverity::severity, tracy::Color::Red4, 0, msg ); diff --git a/public/tracy/TracyLua.hpp b/public/tracy/TracyLua.hpp index e40c53a3..6deda6f9 100644 --- a/public/tracy/TracyLua.hpp +++ b/public/tracy/TracyLua.hpp @@ -144,9 +144,9 @@ static inline void LuaHook( lua_State* L, lua_Debug* ar ) {} #else -#include #include +#include "../common/TracyAssert.hpp" #include "../common/TracyColor.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyForceInline.hpp" @@ -177,7 +177,7 @@ static inline void LuaShortenSrc( char* dst, const char* src ) #ifdef TRACY_HAS_CALLSTACK static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) { - assert( depth <= 64 ); + TRACY_ASSERT( depth <= 64 ); lua_Debug dbg[64]; const char* func[64]; uint32_t fsz[64]; @@ -204,14 +204,14 @@ static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) { const uint32_t line = dbg[i].currentline; memcpy( dst, &line, 4 ); dst += 4; - assert( fsz[i] <= (std::numeric_limits::max)() ); + TRACY_ASSERT( fsz[i] <= (std::numeric_limits::max)() ); memcpy( dst, fsz+i, 2 ); dst += 2; memcpy( dst, func[i], fsz[i] ); dst += fsz[i]; - assert( ssz[i] <= (std::numeric_limits::max)() ); + TRACY_ASSERT( ssz[i] <= (std::numeric_limits::max)() ); memcpy( dst, ssz+i, 2 ); dst += 2; memcpy( dst, dbg[i].source, ssz[i] ), dst += ssz[i]; } - assert( dst - ptr == spaceNeeded + 2 ); + TRACY_ASSERT( dst - ptr == spaceNeeded + 2 ); TracyQueuePrepare( QueueType::CallstackAlloc ); MemWrite( &item->callstackAllocFat.ptr, (uint64_t)ptr ); @@ -233,7 +233,7 @@ static inline int LuaZoneBeginS( lua_State* L ) #else const auto depth = uint32_t( lua_tointeger( L, 1 ) ); #endif - assert( depth > 0 ); // Would crash later anyway, this is not allowed + TRACY_ASSERT( depth > 0 ); // Would crash later anyway, this is not allowed SendLuaCallstack( L, depth ); lua_Debug dbg; @@ -265,7 +265,7 @@ static inline int LuaZoneBeginNS( lua_State* L ) #else const auto depth = uint32_t( lua_tointeger( L, 2 ) ); #endif - assert( depth > 0 ); // Would crash later anyway, this is not allowed + TRACY_ASSERT( depth > 0 ); // Would crash later anyway, this is not allowed SendLuaCallstack( L, depth ); lua_Debug dbg; @@ -345,7 +345,7 @@ static inline int LuaZoneBeginN( lua_State* L ) static inline int LuaZoneEnd( lua_State* L ) { #ifdef TRACY_ON_DEMAND - assert( GetLuaZoneState().counter != 0 ); + TRACY_ASSERT( GetLuaZoneState().counter != 0 ); GetLuaZoneState().counter--; if( !GetLuaZoneState().active ) return 0; if( !GetProfiler().IsConnected() ) @@ -374,7 +374,7 @@ static inline int LuaZoneText( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -399,7 +399,7 @@ static inline int LuaZoneName( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -419,7 +419,7 @@ static inline int LuaMessage( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -447,7 +447,7 @@ static inline int LuaSectionEnter( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < (std::numeric_limits::max)() ); + TRACY_ASSERT( size < (std::numeric_limits::max)() ); uint16_t category = lua_isnumber( L, 2 ) ? lua_tointeger( L, 2 ) : 0; @@ -543,7 +543,7 @@ static inline void LuaHook( lua_State* L, lua_Debug* ar ) } else if (ar->event == LUA_HOOKRET) { #ifdef TRACY_ON_DEMAND - assert( GetLuaZoneState().counter != 0 ); + TRACY_ASSERT( GetLuaZoneState().counter != 0 ); GetLuaZoneState().counter--; if ( !GetLuaZoneState().active ) return; if ( !GetProfiler().IsConnected() ) diff --git a/public/tracy/TracyMetal.hmm b/public/tracy/TracyMetal.hmm index 7afc1536..214c5aac 100644 --- a/public/tracy/TracyMetal.hmm +++ b/public/tracy/TracyMetal.hmm @@ -58,7 +58,6 @@ using TracyMetalCtx = void; #endif #include -#include #include #include "Tracy.hpp" @@ -66,6 +65,7 @@ using TracyMetalCtx = void; #include "../client/TracyCallstack.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" // ok to import if in obj-c code #import @@ -297,11 +297,11 @@ private: if (m_device == nil) { - TracyMetalPanic({assert(false);} return, "device is nil."); + TracyMetalPanic({TRACY_ASSERT(false);} return, "device is nil."); } if (![m_device supportsCounterSampling:MTLCounterSamplingPointAtStageBoundary]) { - TracyMetalPanic({assert(false);} return, "ERROR: timestamp sampling at pipeline stage boundary is not supported."); + TracyMetalPanic({TRACY_ASSERT(false);} return, "ERROR: timestamp sampling at pipeline stage boundary is not supported."); } if (![m_device supportsCounterSampling:MTLCounterSamplingPointAtDrawBoundary]) { @@ -436,7 +436,7 @@ private: } if (timestampCounterSet == nil) { - TracyMetalPanic({assert(false);} return nil, "ERROR: timestamp counters are not supported on the platform."); + TracyMetalPanic({TRACY_ASSERT(false);} return nil, "ERROR: timestamp counters are not supported on the platform."); } MTLCounterSampleBufferDescriptor* sampleDescriptor = [[MTLCounterSampleBufferDescriptor alloc] init]; @@ -450,7 +450,7 @@ private: if (error != nil) { //NSLog(@"%@ | %@", error.localizedDescription, error.localizedFailureReason); - TracyMetalPanic({assert(false);} return nil, + TracyMetalPanic({TRACY_ASSERT(false);} return nil, "ERROR: unable to create sample buffer for timestamp counters : %s | %s", [error.localizedDescription cString], [error.localizedFailureReason cString]); } @@ -487,7 +487,7 @@ public: #endif { if ( !m_active ) return; - if (desc == nil) TracyMetalPanic({assert(false);} return, "compute pass descriptor is nil."); + if (desc == nil) TracyMetalPanic({TRACY_ASSERT(false);} return, "compute pass descriptor is nil."); m_ctx = ctx; auto& query = m_query = ctx->NextQuery(); @@ -508,7 +508,7 @@ public: #endif { if ( !m_active ) return; - if (desc == nil) TracyMetalPanic({assert(false); }return, "blit pass descriptor is nil."); + if (desc == nil) TracyMetalPanic({TRACY_ASSERT(false); }return, "blit pass descriptor is nil."); m_ctx = ctx; auto& query = m_query = ctx->NextQuery(); @@ -529,7 +529,7 @@ public: #endif { if ( !m_active ) return; - if (desc == nil) TracyMetalPanic({assert(false);} return, "render pass descriptor is nil."); + if (desc == nil) TracyMetalPanic({TRACY_ASSERT(false);} return, "render pass descriptor is nil."); m_ctx = ctx; auto& query = m_query = ctx->NextQuery(); diff --git a/public/tracy/TracyOpenCL.hpp b/public/tracy/TracyOpenCL.hpp index a5a4375f..a99fb448 100644 --- a/public/tracy/TracyOpenCL.hpp +++ b/public/tracy/TracyOpenCL.hpp @@ -36,19 +36,19 @@ using TracyCLCtx = void*; #include #include -#include #include #include "Tracy.hpp" #include "../client/TracyCallstack.hpp" #include "../client/TracyProfiler.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #define TRACY_CL_TO_STRING_INDIRECT(T) #T #define TRACY_CL_TO_STRING(T) TRACY_CL_TO_STRING_INDIRECT(T) #define TRACY_CL_ASSERT(p) if(!(p)) { \ TracyMessageL( "TRACY_CL_ASSERT failed on " TracyFile ":" TRACY_CL_TO_STRING(TracyLine) ); \ - assert(false && "TRACY_CL_ASSERT failed"); \ + TRACY_ASSERT(false && "TRACY_CL_ASSERT failed"); \ } #define TRACY_CL_CHECK_ERROR(err) if(err != CL_SUCCESS) { \ std::ostringstream oss; \ @@ -56,7 +56,7 @@ using TracyCLCtx = void*; << ": error code " << err; \ auto msg = oss.str(); \ TracyMessage(msg.data(), msg.size()); \ - assert(false && "TRACY_CL_CHECK_ERROR failed"); \ + TRACY_ASSERT(false && "TRACY_CL_CHECK_ERROR failed"); \ } namespace tracy { @@ -164,7 +164,7 @@ namespace tracy { if (eventInfo.event == nullptr) { TracyMessageL("A TracyCLZone must be paird with a TracyCLZoneSetEvent, check your code!"); } - assert(false && "clGetEventInfo failed, maybe a TracyCLZone is not paired with TracyCLZoneSetEvent"); + TRACY_ASSERT(false && "clGetEventInfo failed, maybe a TracyCLZone is not paired with TracyCLZoneSetEvent"); continue; } if (eventStatus != CL_COMPLETE) return; @@ -178,7 +178,7 @@ namespace tracy { if (err == CL_PROFILING_INFO_NOT_AVAILABLE) { TracyMessageL("command queue is not created with CL_QUEUE_PROFILING_ENABLE flag, check your code!"); - assert(false && "command queue is not created with CL_QUEUE_PROFILING_ENABLE flag"); + TRACY_ASSERT(false && "command queue is not created with CL_QUEUE_PROFILING_ENABLE flag"); } else TRACY_CL_CHECK_ERROR(err); diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index dba13c06..d36851ad 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -37,7 +37,6 @@ public: #else #include -#include #include #ifdef TRACY_OPENGL_AUTO_CALIBRATION # include @@ -48,6 +47,7 @@ public: #include "../client/TracyCallstack.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #if !defined GL_TIMESTAMP && defined GL_TIMESTAMP_EXT # define GL_TIMESTAMP GL_TIMESTAMP_EXT @@ -121,7 +121,7 @@ public: { ZoneScopedC( Color::Red4 ); - assert( m_context != InvalidGpuContextId ); + TRACY_ASSERT( m_context != InvalidGpuContextId ); if( !CheckFeature( "GL_ARB_timer_query" ) && !CheckFeature( "GL_EXT_disjoint_timer_query" ) ) { @@ -146,7 +146,7 @@ public: Profiler::LogString( MessageSourceType::Tracy, MessageSeverity::Warning, Color::Tomato, 0, "OpenGL driver does not implement GL_TIMESTAMP precision." ); } - assert( bits > 0 ); + TRACY_ASSERT( bits > 0 ); int64_t tgpu; glGetInteger64v( GL_TIMESTAMP, &tgpu ); @@ -320,7 +320,7 @@ private: { const auto id = m_head; m_head = ( m_head + 1 ) % QueryCount; - assert( m_head != m_tail ); + TRACY_ASSERT( m_head != m_tail ); return id; } diff --git a/public/tracy/TracyVulkan.hpp b/public/tracy/TracyVulkan.hpp index 36fc49e2..f137d8bf 100644 --- a/public/tracy/TracyVulkan.hpp +++ b/public/tracy/TracyVulkan.hpp @@ -37,11 +37,11 @@ using TracyVkCtx = void*; # error "You must include Vulkan headers before including TracyVulkan.hpp" #endif -#include #include #include "Tracy.hpp" #include "../client/TracyProfiler.hpp" #include "../client/TracyCallstack.hpp" +#include "../common/TracyAssert.hpp" #include @@ -114,7 +114,7 @@ public: , m_vkGetCalibratedTimestampsEXT( vkGetCalibratedTimestampsEXT ) #endif { - assert( m_context != InvalidGpuContextId ); + TRACY_ASSERT( m_context != InvalidGpuContextId ); #if defined TRACY_VK_USE_SYMBOL_TABLE PopulateSymbolTable(instance, instanceProcAddr, deviceProcAddr); @@ -199,16 +199,16 @@ public: , m_vkGetCalibratedTimestampsEXT( vkGetCalibratedTimestampsEXT ) #endif { - assert( m_context != InvalidGpuContextId); + TRACY_ASSERT( m_context != InvalidGpuContextId); #if defined TRACY_VK_USE_SYMBOL_TABLE PopulateSymbolTable(instance, instanceProcAddr, deviceProcAddr); m_vkGetCalibratedTimestampsEXT = m_symbols.vkGetCalibratedTimestampsEXT; #endif - assert( VK_FUNCTION_WRAPPER( vkResetQueryPool ) != nullptr ); - assert( VK_FUNCTION_WRAPPER( vkGetPhysicalDeviceCalibrateableTimeDomainsEXT ) != nullptr ); - assert( VK_FUNCTION_WRAPPER( vkGetCalibratedTimestampsEXT ) != nullptr ); + TRACY_ASSERT( VK_FUNCTION_WRAPPER( vkResetQueryPool ) != nullptr ); + TRACY_ASSERT( VK_FUNCTION_WRAPPER( vkGetPhysicalDeviceCalibrateableTimeDomainsEXT ) != nullptr ); + TRACY_ASSERT( VK_FUNCTION_WRAPPER( vkGetCalibratedTimestampsEXT ) != nullptr ); FindAvailableTimeDomains( physdev, VK_FUNCTION_WRAPPER( vkGetPhysicalDeviceCalibrateableTimeDomainsEXT ) ); @@ -271,7 +271,7 @@ public: return; } #endif - assert( head > m_tail ); + TRACY_ASSERT( head > m_tail ); const unsigned int wrappedTail = (unsigned int)( m_tail % m_queryCount ); @@ -284,7 +284,7 @@ public: else { cnt = (unsigned int)( head - m_tail ); - assert( cnt <= m_queryCount ); + TRACY_ASSERT( cnt <= m_queryCount ); if( wrappedTail + cnt > m_queryCount ) { cnt = m_queryCount - wrappedTail; @@ -363,15 +363,15 @@ private: #elif defined __linux__ && defined CLOCK_MONOTONIC_RAW return tCpu; #else - assert( false ); + TRACY_ASSERT( false ); return 0; #endif } tracy_force_inline bool GetCalibratedTimestamps( int64_t& tCpu, int64_t& tGpu, uint64_t& tDeviation ) { - assert( m_device ); - assert( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT ); + TRACY_ASSERT( m_device ); + TRACY_ASSERT( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT ); VkCalibratedTimestampInfoEXT spec[2] = { { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, VK_TIME_DOMAIN_DEVICE_EXT }, { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, m_timeDomain }, diff --git a/public/tracy/TracyWebGPU.hpp b/public/tracy/TracyWebGPU.hpp index 928bfc78..10c5a93c 100644 --- a/public/tracy/TracyWebGPU.hpp +++ b/public/tracy/TracyWebGPU.hpp @@ -45,6 +45,7 @@ using TracyWebGPUCtx = void*; #include "../client/TracyCallstack.hpp" #include "../common/TracyAlign.hpp" #include "../common/TracyAlloc.hpp" +#include "../common/TracyAssert.hpp" #include #include @@ -52,7 +53,6 @@ using TracyWebGPUCtx = void*; #include #include #include -#include #include #include @@ -83,7 +83,7 @@ extern "C" int32_t IsDebuggerPresent(void); #else #define TracyWebGPUDebug(...) #define TracyWebGPUBreak() -#define TracyWebGPUAssert(predicate, ...) assert(predicate); +#define TracyWebGPUAssert(predicate, ...) TRACY_ASSERT(predicate); #endif #define TracyWebGPULog(severity, msg) do { char buffer [1024]; int len = snprintf(buffer, sizeof(buffer), "TracyWebGPU: %s", msg); tracy::Profiler::LogString( tracy::MessageSourceType::Tracy, tracy::MessageSeverity::severity, tracy::Color::Red4, 0, len, buffer ); } while(false)