17 #ifndef AGX_HIGHACCURACYTIMER_H 18 #define AGX_HIGHACCURACYTIMER_H 20 #include <agx/config/AGX_USE_CPP11_TIMERS.h> 27 #include <sys/types.h> 28 #include <sys/sysctl.h> 32 #if AGX_USE_CPP11_TIMERS() 37 #include <mach/mach_time.h> 89 void reset(
bool startAfterReset =
false);
98 UInt64 getNumTicks()
const;
104 bool isRunning()
const;
107 static UInt64 getCurrentTick();
113 static void initClockSpeed();
119 static UInt64 getCurrentTickWindows();
124 #if AGX_USE_CPP11_TIMERS() 125 std::high_resolution_clock::time_point m_start;
126 std::duration<agx::Real64> m_total;
134 static agx::Real s_highAccuracyClockSpeed;
142 if (startImmediately)
154 #if AGX_USE_CPP11_TIMERS() 155 m_start = std::high_resolution_clock::now();
157 m_start = getCurrentTick();
167 #if AGX_USE_CPP11_TIMERS() 168 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
169 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
172 UInt64 now = getCurrentTick();
173 m_total += (now - m_start);
210 #if AGX_USE_CPP11_TIMERS() 213 std::high_resolution_clock::time_point now = std::high_resolution_clock::now();
214 std::duration<Real64> duration = duration_cast<std::duration<Real64>>(now - m_start);
215 std::duration<Real64> total = m_total + duration;
216 return total.count() *
Real64(1000);
220 return m_total.count() *
Real64(1000);;
224 return m_running ? (clockSpeed() * (
Real64)(getCurrentTick() - m_start + m_total)) : clockSpeed() * (
Real64)m_total;
232 agxAssert1(s_highAccuracyClockSpeed >= 0,
"HighAccuracyTimer class not properly initialized, forgot to call agx::init() ?");
235 return s_highAccuracyClockSpeed;
241 #if defined(_MSC_VER) 242 const UInt64 retVal = getCurrentTickWindows();
244 #elif defined(AGX_APPLE_IOS) 245 return mach_absolute_time();
246 #elif defined (__GNUC__) && ! defined(__INTEL_COMPILER) && defined(__ia64__) 247 unsigned long long int val;
248 __asm__ __volatile__(
"mov %0=ar.itc" :
"=r"(val) ::
"memory");
250 #elif defined(__INTEL_COMPILER) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER) 251 return __getReg(_IA64_REG_AR_ITC);
252 #elif defined(__ECC) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER) 253 return __getReg(_IA64_REG_AR_ITC);
254 #elif (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__)) && !defined(HAVE_TICK_COUNTER) 269 unsigned long long int lowbits, highbits;
270 __asm__ __volatile__(
"rdtsc":
"=a" (lowbits),
"=d"(highbits) : :
"ebx",
"ecx");
272 unsigned long int lowbits, highbits;
273 __asm__ __volatile__(
"pushal\n\t" "cpuid\n\t" "popal\n\t" "rdtsc":
"=a" (lowbits),
"=d"(highbits));
277 return (((
unsigned long long int)highbits << 32) | (
unsigned long long int)lowbits);
280 agxAbort1(
"Timer::getCurrentTick failed!");
289 return clockSpeed() * (
Real64)ticks;
static Real64 convertToMs(UInt64 ticks)
Return the given number of ticks in ms.
static UInt64 getCurrentTick()
Return raw value of the TSC register (in Windows: QueryPerformanceTimer).
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
UInt64 AGXCORE_EXPORT getStartTick()
UInt64 getStartTick() const
Return the start tick.
Real64 getTime() const
Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspend...
HighAccuracyTimer(bool startImmediately=false)
Creates a HighAccuracyTimer.
bool isRunning() const
Return true if running.
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
void start()
Starts the HighAccuracyTimer.
#define agxAssert1(expr, msg)
void stop()
Stops the HighAccuracyTimer.
UInt64 getNumTicks() const
Report execution time in CPU cycles.
void reset(bool startAfterReset=false)
Clear all data.