From 5f3d1c0fafae45b25ee8fe75c5d92f695414846f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 20 May 2021 02:15:06 +0200 Subject: [PATCH] Sample cache and branch stats. --- client/TracySysTrace.cpp | 96 ++++++++++++++++++++++++++++++++++++++-- common/TracyQueue.hpp | 8 ++++ 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 40035bae..687843aa 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -681,7 +681,11 @@ enum TraceEventId { EventCallstack, EventCpuCycles, - EventInstructionsRetired + EventInstructionsRetired, + EventCacheReference, + EventCacheMiss, + EventBranchRetired, + EventBranchMiss }; static void SetupSampling( int64_t& samplingPeriod ) @@ -697,10 +701,24 @@ static void SetupSampling( int64_t& samplingPeriod ) const bool noRetirement = noRetirementEnv && noRetirementEnv[0] == '1'; #endif +#ifdef TRACY_NO_SAMPLE_CACHE + const bool noCache = true; +#else + const char* noCacheEnv = GetEnvVar( "TRACY_NO_SAMPLE_CACHE" ); + const bool noCache = noCacheEnv && noCacheEnv[0] == '1'; +#endif + +#ifdef TRACY_NO_SAMPLE_BRANCH + const bool noBranch = true; +#else + const char* noBranchEnv = GetEnvVar( "TRACY_NO_SAMPLE_BRANCH" ); + const bool noBranch = noBranchEnv && noBranchEnv[0] == '1'; +#endif + samplingPeriod = GetSamplingPeriod(); s_numCpus = (int)std::thread::hardware_concurrency(); - s_ring = (RingBuffer*)tracy_malloc( sizeof( RingBuffer ) * s_numCpus * 3 ); + s_ring = (RingBuffer*)tracy_malloc( sizeof( RingBuffer ) * s_numCpus * 7 ); s_numBuffers = 0; // Stack traces @@ -745,7 +763,6 @@ static void SetupSampling( int64_t& samplingPeriod ) pe.exclude_kernel = 1; pe.exclude_idle = 1; pe.precise_ip = 2; - if( !noRetirement ) { for( int i=0; i( fd, EventCacheReference ); + s_numBuffers++; + } + } + } + + // cache miss + pe.config = PERF_COUNT_HW_CACHE_MISSES; + if( !noCache ) + { + for( int i=0; i( fd, EventCacheMiss ); + s_numBuffers++; + } + } + } + + // branch retired + pe.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS; + if( !noBranch ) + { + for( int i=0; i( fd, EventBranchRetired ); + s_numBuffers++; + } + } + } + + // branch miss + pe.config = PERF_COUNT_HW_BRANCH_MISSES; + if( !noBranch ) + { + for( int i=0; i( fd, EventBranchMiss ); + s_numBuffers++; + } + } + } + s_threadSampling = (Thread*)tracy_malloc( sizeof( Thread ) ); new(s_threadSampling) Thread( [] (void*) { @@ -916,6 +992,18 @@ static void SetupSampling( int64_t& samplingPeriod ) case EventInstructionsRetired: type = QueueType::HwSampleInstructionRetired; break; + case EventCacheReference: + type = QueueType::HwSampleCpuCycle; + break; + case EventCacheMiss: + type = QueueType::HwSampleInstructionRetired; + break; + case EventBranchRetired: + type = QueueType::HwSampleCpuCycle; + break; + case EventBranchMiss: + type = QueueType::HwSampleInstructionRetired; + break; default: assert( false ); break; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index c385e876..051d9ab0 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -84,6 +84,10 @@ enum class QueueType : uint8_t TidToPid, HwSampleCpuCycle, HwSampleInstructionRetired, + HwSampleCacheReference, + HwSampleCacheMiss, + HwSampleBranchRetired, + HwSampleBranchMiss, PlotConfig, ParamSetup, AckServerQueryNoop, @@ -663,6 +667,10 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueTidToPid ), sizeof( QueueHeader ) + sizeof( QueueHwSample ), // cpu cycle sizeof( QueueHeader ) + sizeof( QueueHwSample ), // instruction retired + sizeof( QueueHeader ) + sizeof( QueueHwSample ), // cache reference + sizeof( QueueHeader ) + sizeof( QueueHwSample ), // cache miss + sizeof( QueueHeader ) + sizeof( QueueHwSample ), // branch retired + sizeof( QueueHeader ) + sizeof( QueueHwSample ), // branch miss sizeof( QueueHeader ) + sizeof( QueuePlotConfig ), sizeof( QueueHeader ) + sizeof( QueueParamSetup ), sizeof( QueueHeader ), // server query acknowledgement