Update tracy to 0.12.0

This commit is contained in:
2025-06-02 19:59:55 +03:00
parent 7c5628d47e
commit 6c63c2f650
18 changed files with 832 additions and 467 deletions

View File

@@ -78,6 +78,9 @@
#include "TracyArmCpuTable.hpp"
#include "TracySysTrace.hpp"
#if defined TRACY_MANUAL_LIFETIME && !defined(TRACY_DELAYED_INIT)
# error "TRACY_MANUAL_LIFETIME requires enabled TRACY_DELAYED_INIT"
#endif
#ifdef TRACY_PORT
# ifndef TRACY_DATA_PORT
@@ -104,9 +107,12 @@
# include <lmcons.h>
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
extern "C" typedef BOOL (WINAPI *t_GetLogicalProcessorInformationEx)( LOGICAL_PROCESSOR_RELATIONSHIP, PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD );
extern "C" typedef char* (WINAPI *t_WineGetVersion)();
extern "C" typedef char* (WINAPI *t_WineGetBuildId)();
#else
# include <unistd.h>
# include <limits.h>
# include <fcntl.h>
#endif
#if defined __linux__
# include <sys/sysinfo.h>
@@ -528,7 +534,16 @@ static const char* GetHostInfo()
# ifdef __MINGW32__
ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber );
# else
ptr += sprintf( ptr, "OS: Windows %lu.%lu.%lu\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
auto WineGetVersion = (t_WineGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "wine_get_version" );
auto WineGetBuildId = (t_WineGetBuildId)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "wine_get_build_id" );
if( WineGetVersion && WineGetBuildId )
{
ptr += sprintf( ptr, "OS: Windows %lu.%lu.%lu (Wine %s [%s])\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, WineGetVersion(), WineGetBuildId() );
}
else
{
ptr += sprintf( ptr, "OS: Windows %lu.%lu.%lu\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
}
# endif
}
#elif defined __linux__
@@ -1388,6 +1403,8 @@ TRACY_API LuaZoneState& GetLuaZoneState() { return s_luaZoneState; }
TRACY_API bool ProfilerAvailable() { return s_instance != nullptr; }
TRACY_API bool ProfilerAllocatorAvailable() { return !RpThreadShutdown; }
constexpr static size_t SafeSendBufferSize = 65536;
Profiler::Profiler()
: m_timeBegin( 0 )
, m_mainThread( detail::GetThreadHandleImpl() )
@@ -1461,6 +1478,21 @@ Profiler::Profiler()
m_userPort = atoi( userPort );
}
m_safeSendBuffer = (char*)tracy_malloc( SafeSendBufferSize );
#ifndef _WIN32
pipe(m_pipe);
# if defined __APPLE__ || defined BSD
// FreeBSD/XNU don't have F_SETPIPE_SZ, so use the default
m_pipeBufSize = 16384;
# else
m_pipeBufSize = (int)(ptrdiff_t)SafeSendBufferSize;
while( fcntl( m_pipe[0], F_SETPIPE_SZ, m_pipeBufSize ) < 0 && errno == EPERM ) m_pipeBufSize /= 2; // too big; reduce
m_pipeBufSize = fcntl( m_pipe[0], F_GETPIPE_SZ );
# endif
fcntl( m_pipe[1], F_SETFL, O_NONBLOCK );
#endif
#if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_MANUAL_LIFETIME)
SpawnWorkerThreads();
#endif
@@ -1486,7 +1518,9 @@ void Profiler::InstallCrashHandler()
#endif
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
m_exceptionHandler = AddVectoredExceptionHandler( 1, CrashFilter );
// We cannot use Vectored Exception handling because it catches application-wide frame-based SEH blocks. We only
// want to catch unhandled exceptions.
m_prevHandler = SetUnhandledExceptionFilter( CrashFilter );
#endif
#ifndef TRACY_NO_CRASH_HANDLER
@@ -1497,20 +1531,29 @@ void Profiler::InstallCrashHandler()
void Profiler::RemoveCrashHandler()
{
#if defined _WIN32 && !defined TRACY_UWP
if( m_crashHandlerInstalled ) RemoveVectoredExceptionHandler( m_exceptionHandler );
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
if( m_crashHandlerInstalled )
{
auto prev = SetUnhandledExceptionFilter( (LPTOP_LEVEL_EXCEPTION_FILTER)m_prevHandler );
if( prev != CrashFilter ) SetUnhandledExceptionFilter( prev ); // A different exception filter was installed over ours => put it back
}
#endif
#if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER
if( m_crashHandlerInstalled )
{
sigaction( TRACY_CRASH_SIGNAL, &m_prevSignal.pwr, nullptr );
sigaction( SIGILL, &m_prevSignal.ill, nullptr );
sigaction( SIGFPE, &m_prevSignal.fpe, nullptr );
sigaction( SIGSEGV, &m_prevSignal.segv, nullptr );
sigaction( SIGPIPE, &m_prevSignal.pipe, nullptr );
sigaction( SIGBUS, &m_prevSignal.bus, nullptr );
sigaction( SIGABRT, &m_prevSignal.abrt, nullptr );
auto restore = []( int signum, struct sigaction* prev ) {
struct sigaction old;
sigaction( signum, prev, &old );
if( old.sa_sigaction != CrashHandler ) sigaction( signum, &old, nullptr ); // A different signal handler was installed over ours => put it back
};
restore( TRACY_CRASH_SIGNAL, &m_prevSignal.pwr );
restore( SIGILL, &m_prevSignal.ill );
restore( SIGFPE, &m_prevSignal.fpe );
restore( SIGSEGV, &m_prevSignal.segv );
restore( SIGPIPE, &m_prevSignal.pipe );
restore( SIGBUS, &m_prevSignal.bus );
restore( SIGABRT, &m_prevSignal.abrt );
}
#endif
m_crashHandlerInstalled = false;
@@ -1599,6 +1642,12 @@ Profiler::~Profiler()
tracy_free( m_kcore );
#endif
#ifndef _WIN32
close( m_pipe[0] );
close( m_pipe[1] );
#endif
tracy_free( m_safeSendBuffer );
tracy_free( m_lz4Buf );
tracy_free( m_buffer );
LZ4_freeStream( (LZ4_stream_t*)m_stream );
@@ -2826,6 +2875,15 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
MemWrite( &item->memFree.time, dt );
break;
}
case QueueType::MemDiscard:
case QueueType::MemDiscardCallstack:
{
int64_t t = MemRead<int64_t>( &item->memDiscard.time );
int64_t dt = t - refSerial;
refSerial = t;
MemWrite( &item->memDiscard.time, dt );
break;
}
case QueueType::GpuZoneBeginSerial:
case QueueType::GpuZoneBeginCallstackSerial:
{
@@ -3062,6 +3120,62 @@ bool Profiler::CommitData()
return ret;
}
char* Profiler::SafeCopyProlog( const char* data, size_t size )
{
bool success = true;
char* buf = m_safeSendBuffer;
#ifndef NDEBUG
assert( !m_inUse.exchange(true) );
#endif
if( size > SafeSendBufferSize ) buf = (char*)tracy_malloc( size );
#ifdef _WIN32
__try
{
memcpy( buf, data, size );
}
__except( 1 /*EXCEPTION_EXECUTE_HANDLER*/ )
{
success = false;
}
#else
// Send through the pipe to ensure safe reads
for( size_t offset = 0; offset != size; /*in loop*/ )
{
size_t sendsize = size - offset;
ssize_t result1, result2;
while( ( result1 = write( m_pipe[1], data + offset, sendsize ) ) < 0 && errno == EINTR ) { /* retry */ }
if( result1 < 0 )
{
success = false;
break;
}
while( ( result2 = read( m_pipe[0], buf + offset, result1 ) ) < 0 && errno == EINTR ) { /* retry */ }
if( result2 != result1 )
{
success = false;
break;
}
offset += result1;
}
#endif
if( success ) return buf;
SafeCopyEpilog( buf );
return nullptr;
}
void Profiler::SafeCopyEpilog( char* buf )
{
if( buf != m_safeSendBuffer ) tracy_free( buf );
#ifndef NDEBUG
m_inUse.store( false );
#endif
}
bool Profiler::SendData( const char* data, size_t len )
{
const lz4sz_t lz4sz = LZ4_compress_fast_continue( (LZ4_stream_t*)m_stream, data, m_lz4Buf + sizeof( lz4sz_t ), (int)len, LZ4Size, 1 );
@@ -3750,17 +3864,48 @@ void Profiler::ReportTopology()
# endif
if( !_GetLogicalProcessorInformationEx ) return;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* packageInfo = nullptr;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* dieInfo = nullptr;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* coreInfo = nullptr;
DWORD psz = 0;
_GetLogicalProcessorInformationEx( RelationProcessorPackage, nullptr, &psz );
auto packageInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( psz );
auto res = _GetLogicalProcessorInformationEx( RelationProcessorPackage, packageInfo, &psz );
assert( res );
if( GetLastError() == ERROR_INSUFFICIENT_BUFFER )
{
packageInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( psz );
auto res = _GetLogicalProcessorInformationEx( RelationProcessorPackage, packageInfo, &psz );
assert( res );
}
else
{
psz = 0;
}
DWORD dsz = 0;
_GetLogicalProcessorInformationEx( RelationProcessorDie, nullptr, &dsz );
if( GetLastError() == ERROR_INSUFFICIENT_BUFFER )
{
dieInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( dsz );
auto res = _GetLogicalProcessorInformationEx( RelationProcessorDie, dieInfo, &dsz );
assert( res );
}
else
{
dsz = 0;
}
DWORD csz = 0;
_GetLogicalProcessorInformationEx( RelationProcessorCore, nullptr, &csz );
auto coreInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( csz );
res = _GetLogicalProcessorInformationEx( RelationProcessorCore, coreInfo, &csz );
assert( res );
if( GetLastError() == ERROR_INSUFFICIENT_BUFFER )
{
coreInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)tracy_malloc( csz );
auto res = _GetLogicalProcessorInformationEx( RelationProcessorCore, coreInfo, &csz );
assert( res );
}
else
{
csz = 0;
}
SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );
@@ -3788,6 +3933,24 @@ void Profiler::ReportTopology()
idx++;
}
idx = 0;
ptr = dieInfo;
while( (char*)ptr < ((char*)dieInfo) + dsz )
{
assert( ptr->Relationship == RelationProcessorDie );
// FIXME account for GroupCount
auto mask = ptr->Processor.GroupMask[0].Mask;
int core = 0;
while( mask != 0 )
{
if( mask & 1 ) cpuData[core].die = idx;
core++;
mask >>= 1;
}
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((char*)ptr) + ptr->Size);
idx++;
}
idx = 0;
ptr = coreInfo;
while( (char*)ptr < ((char*)coreInfo) + csz )
@@ -3848,12 +4011,26 @@ void Profiler::ReportTopology()
fclose( f );
cpuData[i].package = uint32_t( atoi( buf ) );
cpuData[i].thread = i;
sprintf( path, "%s%i/topology/core_id", basePath, i );
f = fopen( path, "rb" );
read = fread( buf, 1, 1024, f );
buf[read] = '\0';
fclose( f );
cpuData[i].core = uint32_t( atoi( buf ) );
if( f )
{
read = fread( buf, 1, 1024, f );
buf[read] = '\0';
fclose( f );
cpuData[i].core = uint32_t( atoi( buf ) );
}
sprintf( path, "%s%i/topology/die_id", basePath, i );
f = fopen( path, "rb" );
if( f )
{
read = fread( buf, 1, 1024, f );
buf[read] = '\0';
fclose( f );
cpuData[i].die = uint32_t( atoi( buf ) );
}
}
for( int i=0; i<numcpus; i++ )
@@ -3986,58 +4163,58 @@ void Profiler::ConfigurePlot( const char* name, PlotFormatType type, bool step,
TracyLfqCommit;
}
void Profiler::Message( const char* txt, size_t size, int callstack )
void Profiler::Message( const char* txt, size_t size, int32_t callstack_depth )
{
assert( size < (std::numeric_limits<uint16_t>::max)() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
if( callstack != 0 )
if( callstack_depth != 0 && has_callstack() )
{
tracy::GetProfiler().SendCallstack( callstack );
tracy::GetProfiler().SendCallstack( callstack_depth );
}
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
TracyQueuePrepare( callstack == 0 ? QueueType::Message : QueueType::MessageCallstack );
TracyQueuePrepare( callstack_depth == 0 ? QueueType::Message : QueueType::MessageCallstack );
MemWrite( &item->messageFat.time, GetTime() );
MemWrite( &item->messageFat.text, (uint64_t)ptr );
MemWrite( &item->messageFat.size, (uint16_t)size );
TracyQueueCommit( messageFatThread );
}
void Profiler::Message( const char* txt, int callstack )
void Profiler::Message( const char* txt, int32_t callstack_depth )
{
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
if( callstack != 0 )
if( callstack_depth != 0 && has_callstack() )
{
tracy::GetProfiler().SendCallstack( callstack );
tracy::GetProfiler().SendCallstack( callstack_depth );
}
TracyQueuePrepare( callstack == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack );
TracyQueuePrepare( callstack_depth == 0 ? QueueType::MessageLiteral : QueueType::MessageLiteralCallstack );
MemWrite( &item->messageLiteral.time, GetTime() );
MemWrite( &item->messageLiteral.text, (uint64_t)txt );
TracyQueueCommit( messageLiteralThread );
}
void Profiler::MessageColor( const char* txt, size_t size, uint32_t color, int callstack )
void Profiler::MessageColor( const char* txt, size_t size, uint32_t color, int32_t callstack_depth )
{
assert( size < (std::numeric_limits<uint16_t>::max)() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
if( callstack != 0 )
if( callstack_depth != 0 && has_callstack() )
{
tracy::GetProfiler().SendCallstack( callstack );
tracy::GetProfiler().SendCallstack( callstack_depth );
}
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
TracyQueuePrepare( callstack == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack );
TracyQueuePrepare( callstack_depth == 0 ? QueueType::MessageColor : QueueType::MessageColorCallstack );
MemWrite( &item->messageColorFat.time, GetTime() );
MemWrite( &item->messageColorFat.text, (uint64_t)ptr );
MemWrite( &item->messageColorFat.b, uint8_t( ( color ) & 0xFF ) );
@@ -4047,17 +4224,17 @@ void Profiler::MessageColor( const char* txt, size_t size, uint32_t color, int c
TracyQueueCommit( messageColorFatThread );
}
void Profiler::MessageColor( const char* txt, uint32_t color, int callstack )
void Profiler::MessageColor( const char* txt, uint32_t color, int32_t callstack_depth )
{
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
if( callstack != 0 )
if( callstack_depth != 0 && has_callstack() )
{
tracy::GetProfiler().SendCallstack( callstack );
tracy::GetProfiler().SendCallstack( callstack_depth );
}
TracyQueuePrepare( callstack == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack );
TracyQueuePrepare( callstack_depth == 0 ? QueueType::MessageLiteralColor : QueueType::MessageLiteralColorCallstack );
MemWrite( &item->messageColorLiteral.time, GetTime() );
MemWrite( &item->messageColorLiteral.text, (uint64_t)txt );
MemWrite( &item->messageColorLiteral.b, uint8_t( ( color ) & 0xFF ) );
@@ -4112,23 +4289,25 @@ void Profiler::MemFree( const void* ptr, bool secure )
void Profiler::MemAllocCallstack( const void* ptr, size_t size, int depth, bool secure )
{
if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK
auto& profiler = GetProfiler();
if( depth > 0 && has_callstack() )
{
auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return;
if( !profiler.IsConnected() ) return;
# endif
const auto thread = GetThreadHandle();
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
auto callstack = Callstack( depth );
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
profiler.m_serialLock.unlock();
#else
static_cast<void>(depth); // unused
MemAlloc( ptr, size, secure );
#endif
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
profiler.m_serialLock.unlock();
}
else
{
MemAlloc( ptr, size, secure );
}
}
void Profiler::MemFreeCallstack( const void* ptr, int depth, bool secure )
@@ -4139,23 +4318,25 @@ void Profiler::MemFreeCallstack( const void* ptr, int depth, bool secure )
MemFree( ptr, secure );
return;
}
#ifdef TRACY_HAS_CALLSTACK
auto& profiler = GetProfiler();
if( depth > 0 && has_callstack() )
{
auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return;
if( !profiler.IsConnected() ) return;
# endif
const auto thread = GetThreadHandle();
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
auto callstack = Callstack( depth );
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
profiler.m_serialLock.unlock();
#else
static_cast<void>(depth); // unused
MemFree( ptr, secure );
#endif
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
profiler.m_serialLock.unlock();
}
else
{
MemFree( ptr, secure );
}
}
void Profiler::MemAllocNamed( const void* ptr, size_t size, bool secure, const char* name )
@@ -4189,59 +4370,98 @@ void Profiler::MemFreeNamed( const void* ptr, bool secure, const char* name )
void Profiler::MemAllocCallstackNamed( const void* ptr, size_t size, int depth, bool secure, const char* name )
{
if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK
auto& profiler = GetProfiler();
if( depth > 0 && has_callstack() )
{
auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return;
if( !profiler.IsConnected() ) return;
# endif
const auto thread = GetThreadHandle();
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
auto callstack = Callstack( depth );
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemName( name );
SendMemAlloc( QueueType::MemAllocCallstackNamed, thread, ptr, size );
profiler.m_serialLock.unlock();
#else
static_cast<void>(depth); // unused
MemAllocNamed( ptr, size, secure, name );
#endif
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemName( name );
SendMemAlloc( QueueType::MemAllocCallstackNamed, thread, ptr, size );
profiler.m_serialLock.unlock();
}
else
{
MemAllocNamed( ptr, size, secure, name );
}
}
void Profiler::MemFreeCallstackNamed( const void* ptr, int depth, bool secure, const char* name )
{
if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_HAS_CALLSTACK
auto& profiler = GetProfiler();
if( depth > 0 && has_callstack() )
{
auto& profiler = GetProfiler();
# ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return;
if( !profiler.IsConnected() ) return;
# endif
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemName( name );
SendMemFree( QueueType::MemFreeCallstackNamed, thread, ptr );
profiler.m_serialLock.unlock();
}
else
{
MemFreeNamed( ptr, secure, name );
}
}
void Profiler::MemDiscard( const char* name, bool secure )
{
if( secure && !ProfilerAvailable() ) return;
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
GetProfiler().m_serialLock.lock();
SendMemDiscard( QueueType::MemDiscard, thread, name );
GetProfiler().m_serialLock.unlock();
}
profiler.m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemName( name );
SendMemFree( QueueType::MemFreeCallstackNamed, thread, ptr );
profiler.m_serialLock.unlock();
#else
static_cast<void>(depth); // unused
MemFreeNamed( ptr, secure, name );
#endif
void Profiler::MemDiscardCallstack( const char* name, bool secure, int32_t depth )
{
if( secure && !ProfilerAvailable() ) return;
if( depth > 0 && has_callstack() )
{
# ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
# endif
const auto thread = GetThreadHandle();
auto callstack = Callstack( depth );
GetProfiler().m_serialLock.lock();
SendCallstackSerial( callstack );
SendMemDiscard( QueueType::MemDiscard, thread, name );
GetProfiler().m_serialLock.unlock();
}
else
{
MemDiscard( name, secure );
}
}
void Profiler::SendCallstack( int depth )
{
#ifdef TRACY_HAS_CALLSTACK
auto ptr = Callstack( depth );
TracyQueuePrepare( QueueType::Callstack );
MemWrite( &item->callstackFat.ptr, (uint64_t)ptr );
TracyQueueCommit( callstackFatThread );
#else
static_cast<void>(depth); // unused
#endif
if( depth > 0 && has_callstack() )
{
auto ptr = Callstack( depth );
TracyQueuePrepare( QueueType::Callstack );
MemWrite( &item->callstackFat.ptr, (uint64_t)ptr );
TracyQueueCommit( callstackFatThread );
}
}
void Profiler::ParameterRegister( ParameterCallback cb, void* data )
@@ -4266,7 +4486,7 @@ void Profiler::ParameterSetup( uint32_t idx, const char* name, bool isBool, int3
TracyLfqCommit;
}
void Profiler::SendCallstack( int depth, const char* skipBefore )
void Profiler::SendCallstack( int32_t depth, const char* skipBefore )
{
#ifdef TRACY_HAS_CALLSTACK
auto ptr = Callstack( depth );
@@ -4341,13 +4561,12 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
}
else
{
if( !EnsureReadable( symbol ) )
{
AckSymbolCodeNotAvailable();
return;
}
auto&& lambda = [ this, symbol ]( const char* buf, size_t size ) {
SendLongString( symbol, buf, size, QueueType::SymbolCode );
};
SendLongString( symbol, (const char*)symbol, size, QueueType::SymbolCode );
// 'symbol' may have come from a module that has since unloaded, perform a safe copy before sending
if( !WithSafeCopy( (const char*)symbol, size, lambda ) ) AckSymbolCodeNotAvailable();
}
}
@@ -4471,7 +4690,7 @@ int64_t Profiler::GetTimeQpc()
extern "C" {
#endif
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active )
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int32_t active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
@@ -4499,7 +4718,7 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_l
return ctx;
}
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active )
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int32_t depth, int32_t active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
@@ -4518,17 +4737,21 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac
TracyQueueCommitC( zoneValidationThread );
}
#endif
tracy::GetProfiler().SendCallstack( depth );
auto zoneQueue = tracy::QueueType::ZoneBegin;
if( depth > 0 && tracy::has_callstack() )
{
TracyQueuePrepareC( tracy::QueueType::ZoneBeginCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
TracyQueueCommitC( zoneBeginThread );
tracy::GetProfiler().SendCallstack( depth );
zoneQueue = tracy::QueueType::ZoneBeginCallstack;
}
TracyQueuePrepareC( zoneQueue );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
TracyQueueCommitC( zoneBeginThread );
return ctx;
}
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int active )
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int32_t active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
@@ -4560,7 +4783,7 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int act
return ctx;
}
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int depth, int active )
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int32_t depth, int32_t active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
@@ -4583,13 +4806,17 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo
TracyQueueCommitC( zoneValidationThread );
}
#endif
tracy::GetProfiler().SendCallstack( depth );
auto zoneQueue = tracy::QueueType::ZoneBeginAllocSrcLoc;
if( depth > 0 && tracy::has_callstack() )
{
TracyQueuePrepareC( tracy::QueueType::ZoneBeginAllocSrcLocCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
TracyQueueCommitC( zoneBeginThread );
tracy::GetProfiler().SendCallstack( depth );
zoneQueue = tracy::QueueType::ZoneBeginAllocSrcLocCallstack;
}
TracyQueuePrepareC( zoneQueue );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
TracyQueueCommitC( zoneBeginThread );
return ctx;
}
@@ -4687,26 +4914,78 @@ TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value )
}
}
TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size, int secure ) { tracy::Profiler::MemAlloc( ptr, size, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth, int secure ) { tracy::Profiler::MemAllocCallstack( ptr, size, depth, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_free( const void* ptr, int secure ) { tracy::Profiler::MemFree( ptr, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int depth, int secure ) { tracy::Profiler::MemFreeCallstack( ptr, depth, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_alloc_named( const void* ptr, size_t size, int secure, const char* name ) { tracy::Profiler::MemAllocNamed( ptr, size, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack_named( const void* ptr, size_t size, int depth, int secure, const char* name ) { tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_free_named( const void* ptr, int secure, const char* name ) { tracy::Profiler::MemFreeNamed( ptr, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_free_callstack_named( const void* ptr, int depth, int secure, const char* name ) { tracy::Profiler::MemFreeCallstackNamed( ptr, depth, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size, int32_t secure ) { tracy::Profiler::MemAlloc( ptr, size, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int32_t depth, int32_t secure )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemAllocCallstack( ptr, size, depth, secure != 0 );
}
else
{
tracy::Profiler::MemAlloc( ptr, size, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_free( const void* ptr, int32_t secure ) { tracy::Profiler::MemFree( ptr, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int32_t depth, int32_t secure )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemFreeCallstack( ptr, depth, secure != 0 );
}
else
{
tracy::Profiler::MemFree( ptr, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_discard( const char* name, int32_t secure ) { tracy::Profiler::MemDiscard( name, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_discard_callstack( const char* name, int32_t secure, int32_t depth )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemDiscardCallstack( name, secure != 0, depth );
}
else
{
tracy::Profiler::MemDiscard( name, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_alloc_named( const void* ptr, size_t size, int32_t secure, const char* name ) { tracy::Profiler::MemAllocNamed( ptr, size, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack_named( const void* ptr, size_t size, int32_t depth, int32_t secure, const char* name )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, secure != 0, name );
}
else
{
tracy::Profiler::MemAllocNamed( ptr, size, secure != 0, name );
}
}
TRACY_API void ___tracy_emit_memory_free_named( const void* ptr, int32_t secure, const char* name ) { tracy::Profiler::MemFreeNamed( ptr, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_free_callstack_named( const void* ptr, int32_t depth, int32_t secure, const char* name )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemFreeCallstackNamed( ptr, depth, secure != 0, name );
}
else
{
tracy::Profiler::MemFreeNamed( ptr, secure != 0, name );
}
}
TRACY_API void ___tracy_emit_frame_mark( const char* name ) { tracy::Profiler::SendFrameMark( name ); }
TRACY_API void ___tracy_emit_frame_mark_start( const char* name ) { tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgStart ); }
TRACY_API void ___tracy_emit_frame_mark_end( const char* name ) { tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgEnd ); }
TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_t h, uint8_t offset, int flip ) { tracy::Profiler::SendFrameImage( image, w, h, offset, flip ); }
TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_t h, uint8_t offset, int32_t flip ) { tracy::Profiler::SendFrameImage( image, w, h, offset, flip != 0 ); }
TRACY_API void ___tracy_emit_plot( const char* name, double val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_float( const char* name, float val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_int( const char* name, int64_t val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_config( const char* name, int type, int step, int fill, uint32_t color ) { tracy::Profiler::ConfigurePlot( name, tracy::PlotFormatType(type), step, fill, color ); }
TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ) { tracy::Profiler::Message( txt, size, callstack ); }
TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ) { tracy::Profiler::Message( txt, callstack ); }
TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, size, color, callstack ); }
TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, color, callstack ); }
TRACY_API void ___tracy_emit_plot_config( const char* name, int32_t type, int32_t step, int32_t fill, uint32_t color ) { tracy::Profiler::ConfigurePlot( name, tracy::PlotFormatType(type), step != 0, fill != 0, color ); }
TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int32_t callstack_depth ) { tracy::Profiler::Message( txt, size, callstack_depth ); }
TRACY_API void ___tracy_emit_messageL( const char* txt, int32_t callstack_depth ) { tracy::Profiler::Message( txt, callstack_depth ); }
TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int32_t callstack_depth ) { tracy::Profiler::MessageColor( txt, size, color, callstack_depth ); }
TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int32_t callstack_depth ) { tracy::Profiler::MessageColor( txt, color, callstack_depth ); }
TRACY_API void ___tracy_emit_message_appinfo( const char* txt, size_t size ) { tracy::Profiler::MessageAppInfo( txt, size ); }
TRACY_API uint64_t ___tracy_alloc_srcloc( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, uint32_t color ) {
@@ -5004,7 +5283,7 @@ TRACY_API void ___tracy_terminate_lockable_ctx( struct __tracy_lockable_context_
tracy::tracy_free((void*)lockdata);
}
TRACY_API int ___tracy_before_lock_lockable_ctx( struct __tracy_lockable_context_data* lockdata )
TRACY_API int32_t ___tracy_before_lock_lockable_ctx( struct __tracy_lockable_context_data* lockdata )
{
#ifdef TRACY_ON_DEMAND
bool queue = false;
@@ -5016,7 +5295,7 @@ TRACY_API int ___tracy_before_lock_lockable_ctx( struct __tracy_lockable_context
if( active != connected ) lockdata->m_active.store( connected, std::memory_order_relaxed );
if( connected ) queue = true;
}
if( !queue ) return false;
if( !queue ) return static_cast<int32_t>(false);
#endif
auto item = tracy::Profiler::QueueSerial();
@@ -5025,7 +5304,7 @@ TRACY_API int ___tracy_before_lock_lockable_ctx( struct __tracy_lockable_context
tracy::MemWrite( &item->lockWait.id, lockdata->m_id );
tracy::MemWrite( &item->lockWait.time, tracy::Profiler::GetTime() );
tracy::Profiler::QueueSerialFinish();
return true;
return static_cast<int32_t>(true);
}
TRACY_API void ___tracy_after_lock_lockable_ctx( struct __tracy_lockable_context_data* lockdata )
@@ -5057,7 +5336,7 @@ TRACY_API void ___tracy_after_unlock_lockable_ctx( struct __tracy_lockable_conte
tracy::Profiler::QueueSerialFinish();
}
TRACY_API void ___tracy_after_try_lock_lockable_ctx( struct __tracy_lockable_context_data* lockdata, int acquired )
TRACY_API void ___tracy_after_try_lock_lockable_ctx( struct __tracy_lockable_context_data* lockdata, int32_t acquired )
{
#ifdef TRACY_ON_DEMAND
if( !acquired ) return;
@@ -5122,9 +5401,9 @@ TRACY_API void ___tracy_custom_name_lockable_ctx( struct __tracy_lockable_contex
tracy::Profiler::QueueSerialFinish();
}
TRACY_API int ___tracy_connected( void )
TRACY_API int32_t ___tracy_connected( void )
{
return tracy::GetProfiler().IsConnected();
return static_cast<int32_t>( tracy::GetProfiler().IsConnected() );
}
#ifdef TRACY_FIBERS
@@ -5132,7 +5411,7 @@ TRACY_API void ___tracy_fiber_enter( const char* fiber ){ tracy::Profiler::Enter
TRACY_API void ___tracy_fiber_leave( void ){ tracy::Profiler::LeaveFiber(); }
#endif
# ifdef TRACY_MANUAL_LIFETIME
# if defined TRACY_MANUAL_LIFETIME && defined TRACY_DELAYED_INIT
TRACY_API void ___tracy_startup_profiler( void )
{
tracy::StartupProfiler();
@@ -5143,9 +5422,9 @@ TRACY_API void ___tracy_shutdown_profiler( void )
tracy::ShutdownProfiler();
}
TRACY_API int ___tracy_profiler_started( void )
TRACY_API int32_t ___tracy_profiler_started( void )
{
return tracy::s_isProfilerStarted.load( std::memory_order_seq_cst );
return static_cast<int32_t>( tracy::s_isProfilerStarted.load( std::memory_order_seq_cst ) );
}
# endif