Combine flags in welcome message.

This commit is contained in:
Bartosz Taudul 2021-06-15 01:26:50 +02:00
parent 004681b02b
commit 06dcdd342f
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 25 additions and 25 deletions

View File

@ -1344,16 +1344,16 @@ void Profiler::Worker()
const uint64_t pid = GetPid(); const uint64_t pid = GetPid();
#ifdef TRACY_ON_DEMAND uint8_t flags = 0;
uint8_t onDemand = 1;
#else
uint8_t onDemand = 0;
#endif
#ifdef TRACY_ON_DEMAND
flags |= WelcomeFlag::OnDemand;
#endif
#ifdef __APPLE__ #ifdef __APPLE__
uint8_t isApple = 1; flags |= WelcomeFlag::IsApple;
#else #endif
uint8_t isApple = 0; #ifndef TRACY_NO_CODE_TRANSFER
flags |= WelcomeFlag::CodeTransfer;
#endif #endif
#if defined __i386 || defined _M_IX86 #if defined __i386 || defined _M_IX86
@ -1368,12 +1368,6 @@ void Profiler::Worker()
uint8_t cpuArch = CpuArchUnknown; uint8_t cpuArch = CpuArchUnknown;
#endif #endif
#ifdef TRACY_NO_CODE_TRANSFER
uint8_t codeTransfer = 0;
#else
uint8_t codeTransfer = 1;
#endif
#if defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 #if defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64
uint32_t regs[4]; uint32_t regs[4];
char manufacturer[12]; char manufacturer[12];
@ -1399,10 +1393,8 @@ void Profiler::Worker()
MemWrite( &welcome.exectime, m_exectime ); MemWrite( &welcome.exectime, m_exectime );
MemWrite( &welcome.pid, pid ); MemWrite( &welcome.pid, pid );
MemWrite( &welcome.samplingPeriod, m_samplingPeriod ); MemWrite( &welcome.samplingPeriod, m_samplingPeriod );
MemWrite( &welcome.onDemand, onDemand ); MemWrite( &welcome.flags, flags );
MemWrite( &welcome.isApple, isApple );
MemWrite( &welcome.cpuArch, cpuArch ); MemWrite( &welcome.cpuArch, cpuArch );
MemWrite( &welcome.codeTransfer, codeTransfer );
memcpy( welcome.cpuManufacturer, manufacturer, 12 ); memcpy( welcome.cpuManufacturer, manufacturer, 12 );
MemWrite( &welcome.cpuId, cpuId ); MemWrite( &welcome.cpuId, cpuId );
memcpy( welcome.programName, procname, pnsz ); memcpy( welcome.programName, procname, pnsz );

View File

@ -9,7 +9,7 @@ namespace tracy
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
enum : uint32_t { ProtocolVersion = 47 }; enum : uint32_t { ProtocolVersion = 48 };
enum : uint16_t { BroadcastVersion = 2 }; enum : uint16_t { BroadcastVersion = 2 };
using lz4sz_t = uint32_t; using lz4sz_t = uint32_t;
@ -77,6 +77,16 @@ enum CpuArchitecture : uint8_t
}; };
struct WelcomeFlag
{
enum _t : uint8_t
{
OnDemand = 1 << 0,
IsApple = 1 << 1,
CodeTransfer = 1 << 2,
};
};
struct WelcomeMessage struct WelcomeMessage
{ {
double timerMul; double timerMul;
@ -88,10 +98,8 @@ struct WelcomeMessage
uint64_t exectime; uint64_t exectime;
uint64_t pid; uint64_t pid;
int64_t samplingPeriod; int64_t samplingPeriod;
uint8_t onDemand; uint8_t flags;
uint8_t isApple;
uint8_t cpuArch; uint8_t cpuArch;
uint8_t codeTransfer;
char cpuManufacturer[12]; char cpuManufacturer[12];
uint32_t cpuId; uint32_t cpuId;
char programName[WelcomeMessageProgramNameSize]; char programName[WelcomeMessageProgramNameSize];

View File

@ -2836,13 +2836,13 @@ void Worker::Exec()
m_resolution = TscTime( welcome.resolution ); m_resolution = TscTime( welcome.resolution );
m_pid = welcome.pid; m_pid = welcome.pid;
m_samplingPeriod = welcome.samplingPeriod; m_samplingPeriod = welcome.samplingPeriod;
m_onDemand = welcome.onDemand; m_onDemand = welcome.flags & WelcomeFlag::OnDemand;
m_captureProgram = welcome.programName; m_captureProgram = welcome.programName;
m_captureTime = welcome.epoch; m_captureTime = welcome.epoch;
m_executableTime = welcome.exectime; m_executableTime = welcome.exectime;
m_ignoreMemFreeFaults = welcome.onDemand || welcome.isApple; m_ignoreMemFreeFaults = ( welcome.flags & WelcomeFlag::OnDemand ) || ( welcome.flags & WelcomeFlag::IsApple );
m_data.cpuArch = (CpuArchitecture)welcome.cpuArch; m_data.cpuArch = (CpuArchitecture)welcome.cpuArch;
m_codeTransfer = welcome.codeTransfer; m_codeTransfer = welcome.flags & WelcomeFlag::CodeTransfer;
m_data.cpuId = welcome.cpuId; m_data.cpuId = welcome.cpuId;
memcpy( m_data.cpuManufacturer, welcome.cpuManufacturer, 12 ); memcpy( m_data.cpuManufacturer, welcome.cpuManufacturer, 12 );
m_data.cpuManufacturer[12] = '\0'; m_data.cpuManufacturer[12] = '\0';
@ -2857,7 +2857,7 @@ void Worker::Exec()
m_hostInfo = welcome.hostInfo; m_hostInfo = welcome.hostInfo;
if( welcome.onDemand != 0 ) if( m_onDemand )
{ {
OnDemandPayloadMessage onDemand; OnDemandPayloadMessage onDemand;
if( !m_sock.Read( &onDemand, sizeof( onDemand ), 10, ShouldExit ) ) if( !m_sock.Read( &onDemand, sizeof( onDemand ), 10, ShouldExit ) )