mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 12:23:53 +00:00
Restore TSC usage on Linux.
This commit is contained in:
parent
c0c9832713
commit
9258e2ced0
@ -25,7 +25,7 @@
|
|||||||
# include <mach/mach_time.h>
|
# include <mach/mach_time.h>
|
||||||
#endif
|
#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
|
# define TRACY_HW_TIMER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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 )
|
static void SetupSampling( int64_t& samplingPeriod )
|
||||||
{
|
{
|
||||||
|
#ifndef CLOCK_MONOTONIC_RAW
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
samplingPeriod = 100*1000;
|
samplingPeriod = 100*1000;
|
||||||
|
|
||||||
s_numCpus = (int)std::thread::hardware_concurrency();
|
s_numCpus = (int)std::thread::hardware_concurrency();
|
||||||
@ -645,8 +649,8 @@ static void SetupSampling( int64_t& samplingPeriod )
|
|||||||
|
|
||||||
pe.disabled = 1;
|
pe.disabled = 1;
|
||||||
pe.freq = 1;
|
pe.freq = 1;
|
||||||
|
#if !defined TRACY_HW_TIMER || !( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
|
||||||
pe.use_clockid = 1;
|
pe.use_clockid = 1;
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
|
||||||
pe.clockid = CLOCK_MONOTONIC_RAW;
|
pe.clockid = CLOCK_MONOTONIC_RAW;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -669,6 +673,19 @@ static void SetupSampling( int64_t& samplingPeriod )
|
|||||||
sched_param sp = { 5 };
|
sched_param sp = { 5 };
|
||||||
pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp );
|
pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp );
|
||||||
uint32_t currentPid = (uint32_t)getpid();
|
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; i<s_numCpus; i++ )
|
||||||
|
{
|
||||||
|
if( !s_ring[i].CheckTscCaps() )
|
||||||
|
{
|
||||||
|
for( int j=0; j<s_numCpus; j++ ) s_ring[j].~RingBuffer();
|
||||||
|
tracy_free( s_ring );
|
||||||
|
const char* err = "Tracy Profiler: sampling is disabled due to non-native scheduler clock. Are you running under a VM?";
|
||||||
|
Profiler::MessageAppInfo( err, strlen( err ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for( int i=0; i<s_numCpus; i++ ) s_ring[i].Enable();
|
for( int i=0; i<s_numCpus; i++ ) s_ring[i].Enable();
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -721,6 +738,10 @@ static void SetupSampling( int64_t& samplingPeriod )
|
|||||||
}
|
}
|
||||||
memcpy( trace, &cnt, sizeof( uint64_t ) );
|
memcpy( trace, &cnt, sizeof( uint64_t ) );
|
||||||
|
|
||||||
|
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
|
||||||
|
t0 = s_ring[i].ConvertTimeToTsc( t0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
TracyLfqPrepare( QueueType::CallstackSample );
|
TracyLfqPrepare( QueueType::CallstackSample );
|
||||||
MemWrite( &item->callstackSampleFat.time, t0 );
|
MemWrite( &item->callstackSampleFat.time, t0 );
|
||||||
MemWrite( &item->callstackSampleFat.thread, (uint64_t)tid );
|
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 ), "norecord-tgid", 14 );
|
||||||
TraceWrite( TraceOptions, sizeof( TraceOptions ), "noirq-info", 11 );
|
TraceWrite( TraceOptions, sizeof( TraceOptions ), "noirq-info", 11 );
|
||||||
TraceWrite( TraceOptions, sizeof( TraceOptions ), "noannotate", 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;
|
if( !TraceWrite( TraceClock, sizeof( TraceClock ), "mono_raw", 9 ) ) return false;
|
||||||
|
#endif
|
||||||
if( !TraceWrite( SchedSwitch, sizeof( SchedSwitch ), "1", 2 ) ) return false;
|
if( !TraceWrite( SchedSwitch, sizeof( SchedSwitch ), "1", 2 ) ) return false;
|
||||||
if( !TraceWrite( SchedWakeup, sizeof( SchedWakeup ), "1", 2 ) ) return false;
|
if( !TraceWrite( SchedWakeup, sizeof( SchedWakeup ), "1", 2 ) ) return false;
|
||||||
if( !TraceWrite( BufferSizeKb, sizeof( BufferSizeKb ), "4096", 5 ) ) return false;
|
if( !TraceWrite( BufferSizeKb, sizeof( BufferSizeKb ), "4096", 5 ) ) return false;
|
||||||
@ -971,10 +996,14 @@ static void HandleTraceLine( const char* line )
|
|||||||
line++; // ']'
|
line++; // ']'
|
||||||
while( *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 );
|
const auto ts = ReadNumber( line );
|
||||||
line++; // '.'
|
line++; // '.'
|
||||||
const auto tus = ReadNumber( line );
|
const auto tus = ReadNumber( line );
|
||||||
const auto time = ts * 1000000000ll + tus * 1000ll;
|
const auto time = ts * 1000000000ll + tus * 1000ll;
|
||||||
|
#endif
|
||||||
|
|
||||||
line += 2; // ': '
|
line += 2; // ': '
|
||||||
if( memcmp( line, "sched_switch", 12 ) == 0 )
|
if( memcmp( line, "sched_switch", 12 ) == 0 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user