1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Merge pull request #325 from BrychDaneel/automatic_timer_fallback

Automatic timer fallback
This commit is contained in:
Bartosz Taudul
2022-02-21 13:47:50 +01:00
committed by GitHub
2 changed files with 94 additions and 38 deletions
+38 -11
View File
@@ -26,11 +26,11 @@
# include <mach/mach_time.h>
#endif
#if !defined TRACY_TIMER_FALLBACK && ( defined _WIN32 || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) )
#if ( defined _WIN32 || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) )
# define TRACY_HW_TIMER
#endif
#if !defined TRACY_HW_TIMER
#if defined TRACY_TIMER_FALLBACK || !defined TRACY_HW_TIMER
# include <chrono>
#endif
@@ -68,6 +68,23 @@ TRACY_API bool ProfilerAvailable();
TRACY_API bool ProfilerAllocatorAvailable();
TRACY_API int64_t GetFrequencyQpc();
#if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
TRACY_API bool HardwareSupportsInvariantTSC(); // check, if we need fallback scenario
#else
# if defined TRACY_HW_TIMER
tracy_force_inline bool HardwareSupportsInvariantTSC()
{
return true; // this is checked at startup
}
# else
tracy_force_inline bool HardwareSupportsInvariantTSC()
{
return false;
}
# endif
#endif
struct SourceLocationData
{
const char* name;
@@ -167,25 +184,33 @@ public:
{
#ifdef TRACY_HW_TIMER
# if defined TARGET_OS_IOS && TARGET_OS_IOS == 1
return mach_absolute_time();
if( HardwareSupportsInvariantTSC() ) return mach_absolute_time();
# elif defined _WIN32
# ifdef TRACY_TIMER_QPC
return GetTimeQpc();
# else
return int64_t( __rdtsc() );
if( HardwareSupportsInvariantTSC() ) return int64_t( __rdtsc() );
# endif
# elif defined __i386 || defined _M_IX86
uint32_t eax, edx;
asm volatile ( "rdtsc" : "=a" (eax), "=d" (edx) );
return ( uint64_t( edx ) << 32 ) + uint64_t( eax );
if( HardwareSupportsInvariantTSC() )
{
uint32_t eax, edx;
asm volatile ( "rdtsc" : "=a" (eax), "=d" (edx) );
return ( uint64_t( edx ) << 32 ) + uint64_t( eax );
}
# elif defined __x86_64__ || defined _M_X64
uint64_t rax, rdx;
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );
return (int64_t)(( rdx << 32 ) + rax);
if( HardwareSupportsInvariantTSC() )
{
uint64_t rax, rdx;
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );
return (int64_t)(( rdx << 32 ) + rax);
}
# else
# error "TRACY_HW_TIMER detection logic needs fixing"
# endif
#else
#endif
#if !defined TRACY_HW_TIMER || defined TRACY_TIMER_FALLBACK
# if defined __linux__ && defined CLOCK_MONOTONIC_RAW
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC_RAW, &ts );
@@ -194,6 +219,8 @@ public:
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
# endif
#endif
return 0; // unreacheble branch
}
tracy_force_inline uint32_t GetNextZoneId()