From 06dcdd342fed710a72fe1866fb1b734ad5322a21 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 15 Jun 2021 01:26:50 +0200 Subject: [PATCH] Combine flags in welcome message. --- client/TracyProfiler.cpp | 26 +++++++++----------------- common/TracyProtocol.hpp | 16 ++++++++++++---- server/TracyWorker.cpp | 8 ++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index b440995c..e13ecce7 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1344,16 +1344,16 @@ void Profiler::Worker() const uint64_t pid = GetPid(); -#ifdef TRACY_ON_DEMAND - uint8_t onDemand = 1; -#else - uint8_t onDemand = 0; -#endif + uint8_t flags = 0; +#ifdef TRACY_ON_DEMAND + flags |= WelcomeFlag::OnDemand; +#endif #ifdef __APPLE__ - uint8_t isApple = 1; -#else - uint8_t isApple = 0; + flags |= WelcomeFlag::IsApple; +#endif +#ifndef TRACY_NO_CODE_TRANSFER + flags |= WelcomeFlag::CodeTransfer; #endif #if defined __i386 || defined _M_IX86 @@ -1368,12 +1368,6 @@ void Profiler::Worker() uint8_t cpuArch = CpuArchUnknown; #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 uint32_t regs[4]; char manufacturer[12]; @@ -1399,10 +1393,8 @@ void Profiler::Worker() MemWrite( &welcome.exectime, m_exectime ); MemWrite( &welcome.pid, pid ); MemWrite( &welcome.samplingPeriod, m_samplingPeriod ); - MemWrite( &welcome.onDemand, onDemand ); - MemWrite( &welcome.isApple, isApple ); + MemWrite( &welcome.flags, flags ); MemWrite( &welcome.cpuArch, cpuArch ); - MemWrite( &welcome.codeTransfer, codeTransfer ); memcpy( welcome.cpuManufacturer, manufacturer, 12 ); MemWrite( &welcome.cpuId, cpuId ); memcpy( welcome.programName, procname, pnsz ); diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 3cc90ccf..113ac2a5 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy 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 }; 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 { double timerMul; @@ -88,10 +98,8 @@ struct WelcomeMessage uint64_t exectime; uint64_t pid; int64_t samplingPeriod; - uint8_t onDemand; - uint8_t isApple; + uint8_t flags; uint8_t cpuArch; - uint8_t codeTransfer; char cpuManufacturer[12]; uint32_t cpuId; char programName[WelcomeMessageProgramNameSize]; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 52ba5926..4e010aec 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2836,13 +2836,13 @@ void Worker::Exec() m_resolution = TscTime( welcome.resolution ); m_pid = welcome.pid; m_samplingPeriod = welcome.samplingPeriod; - m_onDemand = welcome.onDemand; + m_onDemand = welcome.flags & WelcomeFlag::OnDemand; m_captureProgram = welcome.programName; m_captureTime = welcome.epoch; 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_codeTransfer = welcome.codeTransfer; + m_codeTransfer = welcome.flags & WelcomeFlag::CodeTransfer; m_data.cpuId = welcome.cpuId; memcpy( m_data.cpuManufacturer, welcome.cpuManufacturer, 12 ); m_data.cpuManufacturer[12] = '\0'; @@ -2857,7 +2857,7 @@ void Worker::Exec() m_hostInfo = welcome.hostInfo; - if( welcome.onDemand != 0 ) + if( m_onDemand ) { OnDemandPayloadMessage onDemand; if( !m_sock.Read( &onDemand, sizeof( onDemand ), 10, ShouldExit ) )