27 #ifndef INCLUDED_TIMER 28 #define INCLUDED_TIMER 32 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC 109 #define TIMER(description) ScopeTimer UID__(description) 134 #define TIMER_BEGIN(description) { ScopeTimer UID__(description) 135 #define TIMER_END(description) } 162 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC 179 m_cycles += t1.m_cycles - t0.m_cycles;
184 const Cycles delta = t1.m_cycles - t0.m_cycles;
189 if(!
cpu_CAS64(&m_cycles, m_cycles, m_cycles+delta))
198 m_cycles -= t.m_cycles;
201 std::string ToString()
const 207 double ToSeconds()
const 239 i64 oldRepresentation;
240 memcpy(&oldRepresentation, &m_seconds,
sizeof(oldRepresentation));
243 i64 newRepresentation;
244 memcpy(&newRepresentation, &seconds,
sizeof(newRepresentation));
246 if(!
cpu_CAS64((
volatile i64*)&m_seconds, oldRepresentation, newRepresentation))
309 #define TIMER_ADD_CLIENT(id)\ 310 static TimerClient UID__;\ 311 static TimerClient* id = timer_AddClient(&UID__, WIDEN(#id)) 348 template<
class BillingPolicy = BillingPolicy_Default>
363 BillingPolicy()(m_tc,
m_t0, t1);
390 #define TIMER_ACCRUE(client) ScopeTimerAccrue<> UID__(client) 391 #define TIMER_ACCRUE_ATOMIC(client) ScopeTimerAccrue<BillingPolicy_Atomic> UID__(client) 393 #endif // #ifndef INCLUDED_TIMER TimerClient * m_tc
Definition: timer.h:368
int64_t i64
Definition: types.h:35
double os_cpu_ClockFrequency()
Definition: os_cpu.cpp:43
TimerUnit m_t0
Definition: timer.h:367
LIB_API TimerClient * timer_AddClient(TimerClient *tc, const wchar_t *description)
make the given TimerClient (usually instantiated as static data) ready for use.
Definition: timer.cpp:166
ScopeTimer(const wchar_t *description)
Definition: timer.h:78
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
Definition: utf8.cpp:208
void AddDifferenceAtomic(TimerUnit t0, TimerUnit t1)
Definition: timer.h:236
TimerClient * next
Definition: timer.h:282
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
Definition: timer.h:318
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...
Definition: aarch64.cpp:31
LIB_API std::string StringForCycles(Cycles cycles)
Definition: timer.cpp:220
bill the difference between t0 and t1 to the client's total.
Definition: timer.h:316
void AddDifference(TimerUnit t0, TimerUnit t1)
Definition: timer.h:231
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:287
thread-safe (not used by default due to its higher overhead) note: we can't just use thread-local var...
Definition: timer.h:331
LIB_API double timer_Resolution()
Definition: timer.cpp:145
double ToSeconds() const
Definition: timer.h:261
LIB_API std::string StringForSeconds(double seconds)
internal helper functions for returning an easily readable string (i.e.
Definition: timer.cpp:204
bool cpu_CAS64(volatile i64 *location, i64 expected, i64 newValue)
Definition: aarch64.cpp:41
TimerUnit sum
Definition: timer.h:277
void debug_printf(const char *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
Definition: debug.cpp:142
used by TIMER
Definition: timer.h:74
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
Definition: timer.h:333
void SetFromTimer()
Definition: timer.h:226
const wchar_t * m_description
Definition: timer.h:92
double m_t0
Definition: timer.h:91
i64 Cycles
Definition: timer.h:59
const wchar_t * description
Definition: timer.h:280
LIB_API void timer_LatchStartTime()
timer_Time will subsequently return values relative to the current time.
Definition: timer.cpp:74
LIB_API void timer_DisplayClientTotals()
display all clients' totals; does not reset them.
Definition: timer.cpp:181
void Subtract(TimerUnit t)
Definition: timer.h:250
used by TIMER_ACCRUE
Definition: timer.h:349
void SetToZero()
Definition: timer.h:221
std::string ToString() const
Definition: timer.h:255
double m_seconds
Definition: timer.h:267
~ScopeTimerAccrue()
Definition: timer.h:359
u64 rdtsc()
Definition: x86_x64.cpp:383
LIB_API double timer_Time()
Definition: timer.cpp:98
~ScopeTimer()
Definition: timer.h:83
intptr_t num_calls
Definition: timer.h:286
ScopeTimerAccrue(TimerClient *tc)
Definition: timer.h:353