Changeset View
Changeset View
Standalone View
Standalone View
source/lib/timer.h
Show All 24 Lines | |||||
*/ | */ | ||||
#ifndef INCLUDED_TIMER | #ifndef INCLUDED_TIMER | ||||
#define INCLUDED_TIMER | #define INCLUDED_TIMER | ||||
#include "lib/config2.h" // CONFIG2_TIMER_ALLOW_RDTSC | #include "lib/config2.h" // CONFIG2_TIMER_ALLOW_RDTSC | ||||
#include "lib/sysdep/cpu.h" // cpu_AtomicAdd | #include "lib/sysdep/cpu.h" // cpu_AtomicAdd | ||||
#if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC | #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC | ||||
# include "lib/sysdep/os_cpu.h" // os_cpu_ClockFrequency | |||||
# include "lib/sysdep/arch/x86_x64/x86_x64.h" // x86_x64::rdtsc | # include "lib/sysdep/arch/x86_x64/x86_x64.h" // x86_x64::rdtsc | ||||
#endif | #endif | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
/** | /** | ||||
* timer_Time will subsequently return values relative to the current time. | * timer_Time will subsequently return values relative to the current time. | ||||
**/ | **/ | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
std::string ToString() const | std::string ToString() const | ||||
{ | { | ||||
ENSURE(m_cycles >= 0); | ENSURE(m_cycles >= 0); | ||||
return StringForCycles(m_cycles); | return StringForCycles(m_cycles); | ||||
} | } | ||||
double ToSeconds() const | |||||
{ | |||||
return (double)m_cycles / os_cpu_ClockFrequency(); | |||||
} | |||||
private: | private: | ||||
Cycles m_cycles; | Cycles m_cycles; | ||||
}; | }; | ||||
#else | #else | ||||
class TimerUnit | class TimerUnit | ||||
{ | { | ||||
Show All 33 Lines | retry: | ||||
} | } | ||||
std::string ToString() const | std::string ToString() const | ||||
{ | { | ||||
ENSURE(m_seconds >= 0.0); | ENSURE(m_seconds >= 0.0); | ||||
return StringForSeconds(m_seconds); | return StringForSeconds(m_seconds); | ||||
} | } | ||||
double ToSeconds() const | |||||
{ | |||||
return m_seconds; | |||||
} | |||||
private: | private: | ||||
double m_seconds; | double m_seconds; | ||||
}; | }; | ||||
#endif | #endif | ||||
// opaque - do not access its fields! | // opaque - do not access its fields! | ||||
// note: must be defined here because clients instantiate them; | // note: must be defined here because clients instantiate them; | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator