mirror of
https://github.com/wolfpld/tracy.git
synced 2026-06-08 08:33:48 +00:00
Add a way to override profiled program name and PID.
This commit is contained in:
@@ -425,8 +425,13 @@ static int64_t SetupHwTimer()
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t ___tracy_magic_pid_override = 0;
|
||||
char ___tracy_magic_process_name[64] = {};
|
||||
|
||||
static const char* GetProcessName()
|
||||
{
|
||||
if( *___tracy_magic_process_name != 0 ) return ___tracy_magic_process_name;
|
||||
|
||||
const char* processName = "unknown";
|
||||
#ifdef _WIN32
|
||||
static char buf[_MAX_PATH];
|
||||
@@ -750,6 +755,8 @@ static const char* GetHostInfo()
|
||||
|
||||
static uint64_t GetPid()
|
||||
{
|
||||
if( ___tracy_magic_pid_override != 0 ) return uint64_t( ___tracy_magic_pid_override );
|
||||
|
||||
#if defined _WIN32
|
||||
return uint64_t( GetCurrentProcessId() );
|
||||
#else
|
||||
@@ -4187,6 +4194,16 @@ void Profiler::HandleParameter( uint64_t payload )
|
||||
|
||||
void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
|
||||
{
|
||||
#ifdef __linux__
|
||||
// When profiling an external process, symbol addresses are ELF virtual
|
||||
// addresses, not pointers in the monitor's address space. We cannot
|
||||
// read code bytes directly.
|
||||
if( ___tracy_magic_pid_override != 0 )
|
||||
{
|
||||
AckSymbolCodeNotAvailable();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if( symbol >> 63 != 0 )
|
||||
{
|
||||
QueueKernelCode( symbol, size );
|
||||
|
||||
@@ -412,6 +412,8 @@ static int s_ctxBufferIdx = 0;
|
||||
|
||||
static RingBuffer* s_ring = nullptr;
|
||||
|
||||
extern uint32_t ___tracy_magic_pid_override;
|
||||
|
||||
static const int ThreadHashSize = 4 * 1024;
|
||||
static uint32_t s_threadHash[ThreadHashSize] = {};
|
||||
|
||||
@@ -423,7 +425,14 @@ static bool CurrentProcOwnsThread( uint32_t tid )
|
||||
if( hv == -tid ) return false;
|
||||
|
||||
char path[256];
|
||||
if( ___tracy_magic_pid_override != 0 )
|
||||
{
|
||||
sprintf( path, "/proc/%d/task/%d", (int)___tracy_magic_pid_override, tid );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( path, "/proc/self/task/%d", tid );
|
||||
}
|
||||
struct stat st;
|
||||
if( stat( path, &st ) == 0 )
|
||||
{
|
||||
@@ -648,7 +657,7 @@ bool SysTraceStart( int64_t& samplingPeriod )
|
||||
#endif
|
||||
|
||||
samplingPeriod = GetSamplingPeriod();
|
||||
uint32_t currentPid = (uint32_t)getpid();
|
||||
uint32_t currentPid = ___tracy_magic_pid_override != 0 ? ___tracy_magic_pid_override : (uint32_t)getpid();
|
||||
|
||||
s_numCpus = (int)std::thread::hardware_concurrency();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user