diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 95f4b057..730ed698 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -8,6 +8,7 @@ # include # include # include +# include #else # include #endif @@ -233,6 +234,36 @@ static int64_t SetupHwTimer() return Profiler::GetTime(); } +#elif defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) +static inline void CpuId( uint32_t* regs, uint32_t leaf ) +{ +#if defined _MSC_VER || defined __CYGWIN__ + __cpuidex( (int*)regs, leaf, 0 ); +#else + __get_cpuid( leaf, regs, regs+1, regs+2, regs+3 ); +#endif +} + +static void InitFailure( const char* msg ) +{ +#if defined _WIN32 || defined __CYGWIN__ + MessageBoxA( nullptr, msg, "Tracy Profiler initialization failure", MB_ICONSTOP ); +#else + fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg ); +#endif + exit( 0 ); +} + +static int64_t SetupHwTimer() +{ + uint32_t regs[4]; + CpuId( regs, 0x80000001 ); + if( !( regs[3] & ( 1 << 27 ) ) ) InitFailure( "CPU doesn't support RDTSCP instruction." ); + CpuId( regs, 0x80000007 ); + if( !( regs[3] & ( 1 << 8 ) ) ) InitFailure( "CPU doesn't support invariant TSC." ); + + return Profiler::GetTime(); +} #else static int64_t SetupHwTimer() {