27 #ifndef INCLUDED_TIMER
28 #define INCLUDED_TIMER
32 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC
108 #define TIMER(description) ScopeTimer UID__(description)
133 #define TIMER_BEGIN(description) { ScopeTimer UID__(description)
134 #define TIMER_END(description) }
161 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC
178 m_cycles += t1.m_cycles - t0.m_cycles;
183 const Cycles delta = t1.m_cycles - t0.m_cycles;
188 if(!
cpu_CAS64(&m_cycles, m_cycles, m_cycles+delta))
197 m_cycles -= t.m_cycles;
238 i64 oldRepresentation;
239 memcpy(&oldRepresentation, &
m_seconds,
sizeof(oldRepresentation));
242 i64 newRepresentation;
243 memcpy(&newRepresentation, &seconds,
sizeof(newRepresentation));
308 #define TIMER_ADD_CLIENT(id)\
309 static TimerClient UID__;\
310 static TimerClient* id = timer_AddClient(&UID__, WIDEN(#id))
347 template<
class BillingPolicy = BillingPolicy_Default>
389 #define TIMER_ACCRUE(client) ScopeTimerAccrue<> UID__(client)
390 #define TIMER_ACCRUE_ATOMIC(client) ScopeTimerAccrue<BillingPolicy_Atomic> UID__(client)
392 #endif // #ifndef INCLUDED_TIMER
NONCOPYABLE(ScopeTimerAccrue)
double os_cpu_ClockFrequency()
ScopeTimer(const wchar_t *description)
void AddDifferenceAtomic(TimerUnit t0, TimerUnit t1)
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
TimerClient * timer_AddClient(TimerClient *tc, const wchar_t *description)
make the given TimerClient (usually instantiated as static data) ready for use.
intptr_t cpu_AtomicAdd(volatile intptr_t *location, intptr_t increment)
add a signed value to a variable without the possibility of interference from other threads/CPUs...
bill the difference between t0 and t1 to the client's total.
void AddDifference(TimerUnit t0, TimerUnit t1)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
thread-safe (not used by default due to its higher overhead) note: we can't just use thread-local var...
void timer_LatchStartTime()
timer_Time will subsequently return values relative to the current time.
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
const wchar_t * m_description
bool cpu_CAS64(volatile i64 *location, i64 expected, i64 newValue)
double timer_Resolution()
const wchar_t * description
void Subtract(TimerUnit t)
std::wstring ToString() const
std::wstring StringForSeconds(double seconds)
internal helper functions for returning an easily readable string (i.e.
std::wstring StringForCycles(Cycles cycles)
ScopeTimerAccrue(TimerClient *tc)
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
void timer_DisplayClientTotals()
display all clients' totals; does not reset them.