Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions libs/tracy/TracyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#include "client/TracyOverride.cpp"
#include "client/TracyKCore.cpp"

#ifdef TRACY_ROCPROF
# include "client/TracyRocprof.cpp"
#endif

#if defined(TRACY_HAS_CALLSTACK)
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
# include "libbacktrace/alloc.cpp"
Expand Down
4 changes: 2 additions & 2 deletions libs/tracy/client/TracyCallstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# endif

# if defined _WIN32
# include "../common/TracyWinFamily.hpp"
# if !defined TRACY_WIN32_NO_DESKTOP
# include "../common/TracyUwp.hpp"
# ifndef TRACY_UWP
# define TRACY_HAS_CALLSTACK 1
# endif
# elif defined __ANDROID__
Expand Down
6 changes: 2 additions & 4 deletions libs/tracy/client/TracyLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ class Lockable
m_ctx.CustomName( name, size );
}

T m_lockable;

private:
T m_lockable;
LockableCtx m_ctx;
};

Expand Down Expand Up @@ -536,9 +535,8 @@ class SharedLockable
m_ctx.CustomName( name, size );
}

T m_lockable;

private:
T m_lockable;
SharedLockableCtx m_ctx;
};

Expand Down
145 changes: 70 additions & 75 deletions libs/tracy/client/TracyProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# include <tlhelp32.h>
# include <inttypes.h>
# include <intrin.h>
# include "../common/TracyWinFamily.hpp"
# include "../common/TracyUwp.hpp"
# ifndef _MSC_VER
# include <excpt.h>
# endif
Expand Down Expand Up @@ -327,13 +327,7 @@ static inline void CpuId( uint32_t* regs, uint32_t leaf )

static void InitFailure( const char* msg )
{
#if defined TRACY_GDK
const char* format = "Tracy Profiler initialization failure: %s\n";
const int length = snprintf( nullptr, 0, format, msg );
char* buffer = (char*)alloca( length + 1 );
snprintf( buffer, length + 1, format, msg );
OutputDebugStringA( buffer );
#elif defined _WIN32
#if defined _WIN32
bool hasConsole = false;
bool reopen = false;
const auto attached = AttachConsole( ATTACH_PARENT_PROCESS );
Expand Down Expand Up @@ -516,7 +510,7 @@ static const char* GetHostInfo()
static char buf[1024];
auto ptr = buf;
#if defined _WIN32
# if defined TRACY_WIN32_NO_DESKTOP
# ifdef TRACY_UWP
auto GetVersion = &::GetVersionEx;
# else
auto GetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" );
Expand Down Expand Up @@ -599,7 +593,7 @@ static const char* GetHostInfo()
char hostname[512];
gethostname( hostname, 512 );

# if defined TRACY_WIN32_NO_DESKTOP
# ifdef TRACY_UWP
const char* user = "";
# else
DWORD userSz = UNLEN+1;
Expand Down Expand Up @@ -810,7 +804,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz,
return msg;
}

#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
static DWORD s_profilerThreadId = 0;
static DWORD s_symbolThreadId = 0;
static char s_crashText[1024];
Expand Down Expand Up @@ -1171,38 +1165,6 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
}
#endif

#ifdef TRACY_HAS_SYSTEM_TRACING
static void StartSystemTracing( int64_t& samplingPeriod )
{
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
const char* noSysTrace = GetEnvVar( "TRACY_NO_SYS_TRACE" );
const bool disableSystrace = (noSysTrace && noSysTrace[0] == '1');
if( disableSystrace )
{
TracyDebug("TRACY: Sys Trace was disabled by 'TRACY_NO_SYS_TRACE=1'\n");
}
else if( SysTraceStart( samplingPeriod ) )
{
s_sysTraceThread = (Thread*)tracy_malloc( sizeof( Thread ) );
new(s_sysTraceThread) Thread( SysTraceWorker, nullptr );
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
}
}

static void StopSystemTracing()
{
if( s_sysTraceThread )
{
SysTraceStop();
s_sysTraceThread->~Thread();
tracy_free( s_sysTraceThread );
s_sysTraceThread = nullptr;
}
}
#endif

enum { QueuePrealloc = 256 * 1024 };

Expand Down Expand Up @@ -1556,7 +1518,7 @@ void Profiler::InstallCrashHandler()
sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt );
#endif

#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
// We cannot use Vectored Exception handling because it catches application-wide frame-based SEH blocks. We only
// want to catch unhandled exceptions.
m_prevHandler = reinterpret_cast<void*>( SetUnhandledExceptionFilter( CrashFilter ) );
Expand All @@ -1570,7 +1532,7 @@ void Profiler::InstallCrashHandler()

void Profiler::RemoveCrashHandler()
{
#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
if( m_crashHandlerInstalled )
{
auto prev = SetUnhandledExceptionFilter( (LPTOP_LEVEL_EXCEPTION_FILTER)m_prevHandler );
Expand Down Expand Up @@ -1601,7 +1563,20 @@ void Profiler::RemoveCrashHandler()
void Profiler::SpawnWorkerThreads()
{
#ifdef TRACY_HAS_SYSTEM_TRACING
StartSystemTracing( m_samplingPeriod );
// 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
const char* noSysTrace = GetEnvVar( "TRACY_NO_SYS_TRACE" );
const bool disableSystrace = (noSysTrace && noSysTrace[0] == '1');
if( disableSystrace )
{
TracyDebug("TRACY: Sys Trace was disabled by 'TRACY_NO_SYS_TRACE=1'\n");
}
else if( SysTraceStart( m_samplingPeriod ) )
{
s_sysTraceThread = (Thread*)tracy_malloc( sizeof( Thread ) );
new(s_sysTraceThread) Thread( SysTraceWorker, nullptr );
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
}
#endif

s_thread = (Thread*)tracy_malloc( sizeof( Thread ) );
Expand All @@ -1617,7 +1592,7 @@ void Profiler::SpawnWorkerThreads()
new(s_symbolThread) Thread( LaunchSymbolWorker, this );
#endif

#if defined _WIN32 && !defined TRACY_WIN32_NO_DESKTOP && !defined TRACY_NO_CRASH_HANDLER
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
s_profilerThreadId = GetThreadId( s_thread->Handle() );
# ifdef TRACY_HAS_CALLSTACK
s_symbolThreadId = GetThreadId( s_symbolThread->Handle() );
Expand All @@ -1638,7 +1613,12 @@ Profiler::~Profiler()
RemoveCrashHandler();

#ifdef TRACY_HAS_SYSTEM_TRACING
StopSystemTracing();
if( s_sysTraceThread )
{
SysTraceStop();
s_sysTraceThread->~Thread();
tracy_free( s_sysTraceThread );
}
#endif

#ifdef TRACY_HAS_CALLSTACK
Expand Down Expand Up @@ -1791,6 +1771,7 @@ void Profiler::Worker()
MemWrite( &welcome.timerMul, m_timerMul );
MemWrite( &welcome.initBegin, GetInitTime() );
MemWrite( &welcome.initEnd, m_timeBegin.load( std::memory_order_relaxed ) );
MemWrite( &welcome.delay, m_delay );
MemWrite( &welcome.resolution, m_resolution );
MemWrite( &welcome.epoch, m_epoch );
MemWrite( &welcome.exectime, m_exectime );
Expand Down Expand Up @@ -2030,6 +2011,7 @@ void Profiler::Worker()
}
else if( status == DequeueStatus::QueueEmpty && serialStatus == DequeueStatus::QueueEmpty )
{
if( ShouldExit() ) break;
if( m_bufferOffset != m_bufferStart )
{
if( !CommitData() ) break;
Expand Down Expand Up @@ -2060,7 +2042,7 @@ void Profiler::Worker()
connActive = HandleServerQuery();
if( !connActive ) break;
}
if( !connActive || ShouldExit() ) break;
if( !connActive ) break;
}
if( ShouldExit() ) break;

Expand Down Expand Up @@ -2126,13 +2108,7 @@ void Profiler::Worker()
while( s_symbolThreadGone.load() == false ) { YieldThread(); }
#endif

// Client is exiting.
#ifdef TRACY_HAS_SYSTEM_TRACING
// Stop filling queues with new data.
StopSystemTracing();
#endif

// Send items remaining in queues.
// Client is exiting. Send items remaining in queues.
for(;;)
{
const auto status = Dequeue( token );
Expand Down Expand Up @@ -2383,10 +2359,6 @@ static void FreeAssociatedMemory( const QueueItem& item )
tracy_free( (void*)ptr );
break;
#endif
case QueueType::GpuAnnotationName:
ptr = MemRead<uint64_t>( &item.gpuAnnotationNameFat.ptr );
tracy_free( (void*)ptr );
break;
#ifdef TRACY_ON_DEMAND
case QueueType::MessageAppInfo:
case QueueType::GpuContextName:
Expand Down Expand Up @@ -2602,12 +2574,6 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
tracy_free_fast( (void*)ptr );
#endif
break;
case QueueType::GpuAnnotationName:
ptr = MemRead<uint64_t>( &item->gpuAnnotationNameFat.ptr );
size = MemRead<uint16_t>( &item->gpuAnnotationNameFat.size );
SendSingleString( (const char*)ptr, size );
tracy_free_fast( (void*)ptr );
break;
case QueueType::PlotDataInt:
case QueueType::PlotDataFloat:
case QueueType::PlotDataDouble:
Expand Down Expand Up @@ -2966,14 +2932,6 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
#endif
break;
}
case QueueType::GpuAnnotationName:
{
ptr = MemRead<uint64_t>( &item->gpuAnnotationNameFat.ptr );
uint16_t size = MemRead<uint16_t>( &item->gpuAnnotationNameFat.size );
SendSingleString( (const char*)ptr, size );
tracy_free_fast( (void*)ptr );
break;
}
#ifdef TRACY_FIBERS
case QueueType::ZoneBegin:
case QueueType::ZoneBeginCallstack:
Expand Down Expand Up @@ -3853,6 +3811,43 @@ void Profiler::CalibrateDelay()
if( dti > 0 && dti < mindiff ) mindiff = dti;
}
m_resolution = mindiff;

#ifdef TRACY_DELAYED_INIT
m_delay = m_resolution;
#else
constexpr int Events = Iterations * 2; // start + end
static_assert( Events < QueuePrealloc, "Delay calibration loop will allocate memory in queue" );

static const tracy::SourceLocationData __tracy_source_location { nullptr, TracyFunction, TracyFile, (uint32_t)TracyLine, 0 };
const auto t0 = GetTime();
for( int i=0; i<Iterations; i++ )
{
{
TracyLfqPrepare( QueueType::ZoneBegin );
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
MemWrite( &item->zoneBegin.srcloc, (uint64_t)&__tracy_source_location );
TracyLfqCommit;
}
{
TracyLfqPrepare( QueueType::ZoneEnd );
MemWrite( &item->zoneEnd.time, GetTime() );
TracyLfqCommit;
}
}
const auto t1 = GetTime();
const auto dt = t1 - t0;
m_delay = dt / Events;

moodycamel::ConsumerToken token( GetQueue() );
int left = Events;
while( left != 0 )
{
const auto sz = GetQueue().try_dequeue_bulk_single( token, [](const uint64_t&){}, [](QueueItem* item, size_t sz){} );
assert( sz > 0 );
left -= (int)sz;
}
assert( GetQueue().size_approx() == 0 );
#endif
}

void Profiler::ReportTopology()
Expand All @@ -3867,7 +3862,7 @@ void Profiler::ReportTopology()
};

#if defined _WIN32
# if defined TRACY_WIN32_NO_DESKTOP
# ifdef TRACY_UWP
t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = &::GetLogicalProcessorInformationEx;
# else
t_GetLogicalProcessorInformationEx _GetLogicalProcessorInformationEx = (t_GetLogicalProcessorInformationEx)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetLogicalProcessorInformationEx" );
Expand Down
1 change: 1 addition & 0 deletions libs/tracy/client/TracyProfiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ class Profiler

double m_timerMul;
uint64_t m_resolution;
uint64_t m_delay;
std::atomic<int64_t> m_timeBegin;
uint32_t m_mainThread;
uint64_t m_epoch, m_exectime;
Expand Down
Loading
Loading