1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 12:23:53 +00:00

Transfer PID of profiled program.

This commit is contained in:
Bartosz Taudul 2019-08-17 22:19:04 +02:00
parent 1024992493
commit 678e942e9f
5 changed files with 28 additions and 2 deletions

View File

@ -495,6 +495,15 @@ static const char* GetHostInfo()
return buf;
}
static uint64_t GetPid()
{
#if defined _WIN32 || defined __CYGWIN__
return uint64_t( GetCurrentProcessId() );
#else
return uint64_t( getpid() );
#endif
}
static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, int& len )
{
static BroadcastMessage msg;
@ -1157,6 +1166,8 @@ void Profiler::Worker()
const auto hostinfo = GetHostInfo();
const auto hisz = std::min<size_t>( strlen( hostinfo ), WelcomeMessageHostInfoSize - 1 );
const uint64_t pid = GetPid();
#ifdef TRACY_ON_DEMAND
uint8_t onDemand = 1;
#else
@ -1176,6 +1187,7 @@ void Profiler::Worker()
MemWrite( &welcome.delay, m_delay );
MemWrite( &welcome.resolution, m_resolution );
MemWrite( &welcome.epoch, m_epoch );
MemWrite( &welcome.pid, pid );
MemWrite( &welcome.onDemand, onDemand );
MemWrite( &welcome.isApple, isApple );
memcpy( welcome.programName, procname, pnsz );

View File

@ -9,7 +9,7 @@
namespace tracy
{
enum : uint32_t { ProtocolVersion = 16 };
enum : uint32_t { ProtocolVersion = 17 };
enum : uint32_t { BroadcastVersion = 0 };
using lz4sz_t = uint32_t;
@ -66,6 +66,7 @@ struct WelcomeMessage
uint64_t delay;
uint64_t resolution;
uint64_t epoch;
uint64_t pid;
uint8_t onDemand;
uint8_t isApple;
char programName[WelcomeMessageProgramNameSize];

View File

@ -7,7 +7,7 @@ namespace Version
{
enum { Major = 0 };
enum { Minor = 5 };
enum { Patch = 4 };
enum { Patch = 5 };
}
}

View File

@ -324,6 +324,15 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Read( m_data.lastTime );
f.Read( m_data.frameOffset );
if( fileVer >= FileVersion( 0, 5, 5 ) )
{
f.Read( m_pid );
}
else
{
m_pid = 0;
}
uint64_t sz;
{
f.Read( sz );
@ -2099,6 +2108,7 @@ void Worker::Exec()
m_data.lastTime = initEnd;
m_delay = TscTime( welcome.delay );
m_resolution = TscTime( welcome.resolution );
m_pid = welcome.pid;
m_onDemand = welcome.onDemand;
m_captureProgram = welcome.programName;
m_captureTime = welcome.epoch;
@ -4676,6 +4686,7 @@ void Worker::Write( FileWrite& f )
f.Write( &m_timerMul, sizeof( m_timerMul ) );
f.Write( &m_data.lastTime, sizeof( m_data.lastTime ) );
f.Write( &m_data.frameOffset, sizeof( m_data.frameOffset ) );
f.Write( &m_pid, sizeof( m_pid ) );
uint64_t sz = m_captureName.size();
f.Write( &sz, sizeof( sz ) );

View File

@ -274,6 +274,7 @@ public:
const std::string& GetHostInfo() const { return m_hostInfo; }
int64_t GetDelay() const { return m_delay; }
int64_t GetResolution() const { return m_resolution; }
uint64_t GetPid() const { return m_pid; };
std::shared_mutex& GetDataLock() { return m_data.lock; }
size_t GetFrameCount( const FrameData& fd ) const { return fd.frames.size(); }
@ -544,6 +545,7 @@ private:
std::string m_captureProgram;
uint64_t m_captureTime;
std::string m_hostInfo;
uint64_t m_pid;
bool m_terminate = false;
bool m_crashed = false;
bool m_disconnect = false;