From 9258e2ced04b646c2da47e9c31defa5953e1c407 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 13 Aug 2020 01:41:05 +0200 Subject: [PATCH] Restore TSC usage on Linux. --- client/TracyProfiler.hpp | 2 +- client/TracySysTrace.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index cf1a1c8c..bf925ae2 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -25,7 +25,7 @@ # include #endif -#if defined _WIN32 || defined __CYGWIN__ || ( ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) && !defined __linux__ ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) +#if defined _WIN32 || defined __CYGWIN__ || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) # define TRACY_HW_TIMER #endif diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 1aaceb18..a2c82295 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -627,6 +627,10 @@ static int perf_event_open( struct perf_event_attr* hw_event, pid_t pid, int cpu static void SetupSampling( int64_t& samplingPeriod ) { +#ifndef CLOCK_MONOTONIC_RAW + return; +#endif + samplingPeriod = 100*1000; s_numCpus = (int)std::thread::hardware_concurrency(); @@ -645,8 +649,8 @@ static void SetupSampling( int64_t& samplingPeriod ) pe.disabled = 1; pe.freq = 1; +#if !defined TRACY_HW_TIMER || !( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) pe.use_clockid = 1; -#ifdef CLOCK_MONOTONIC_RAW pe.clockid = CLOCK_MONOTONIC_RAW; #endif @@ -669,6 +673,19 @@ static void SetupSampling( int64_t& samplingPeriod ) sched_param sp = { 5 }; pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp ); uint32_t currentPid = (uint32_t)getpid(); +#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) + for( int i=0; icallstackSampleFat.time, t0 ); MemWrite( &item->callstackSampleFat.thread, (uint64_t)tid ); @@ -827,7 +848,11 @@ bool SysTraceStart( int64_t& samplingPeriod ) TraceWrite( TraceOptions, sizeof( TraceOptions ), "norecord-tgid", 14 ); TraceWrite( TraceOptions, sizeof( TraceOptions ), "noirq-info", 11 ); TraceWrite( TraceOptions, sizeof( TraceOptions ), "noannotate", 11 ); +#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) + if( !TraceWrite( TraceClock, sizeof( TraceClock ), "x86-tsc", 8 ) ) return false; +#else if( !TraceWrite( TraceClock, sizeof( TraceClock ), "mono_raw", 9 ) ) return false; +#endif if( !TraceWrite( SchedSwitch, sizeof( SchedSwitch ), "1", 2 ) ) return false; if( !TraceWrite( SchedWakeup, sizeof( SchedWakeup ), "1", 2 ) ) return false; if( !TraceWrite( BufferSizeKb, sizeof( BufferSizeKb ), "4096", 5 ) ) return false; @@ -971,10 +996,14 @@ static void HandleTraceLine( const char* line ) line++; // ']' while( *line == ' ' ) line++; +#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) + const auto time = ReadNumber( line ); +#else const auto ts = ReadNumber( line ); line++; // '.' const auto tus = ReadNumber( line ); const auto time = ts * 1000000000ll + tus * 1000ll; +#endif line += 2; // ': ' if( memcmp( line, "sched_switch", 12 ) == 0 )