27 #ifndef INCLUDED_TIMER 28 #define INCLUDED_TIMER 32 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC 111 #define TIMER(description) ScopeTimer UID__(description) 136 #define TIMER_BEGIN(description) { ScopeTimer UID__(description) 137 #define TIMER_END(description) } 164 #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC 181 m_cycles += t1.m_cycles - t0.m_cycles;
186 const Cycles delta = t1.m_cycles - t0.m_cycles;
191 if(!
cpu_CAS64(&m_cycles, m_cycles, m_cycles+delta))
200 m_cycles -= t.m_cycles;
209 double ToSeconds()
const 241 i64 oldRepresentation;
242 memcpy(&oldRepresentation, &m_seconds,
sizeof(oldRepresentation));
245 i64 newRepresentation;
246 memcpy(&newRepresentation, &seconds,
sizeof(newRepresentation));
248 if(!
cpu_CAS64((
volatile i64*)&m_seconds, oldRepresentation, newRepresentation))
311 #define TIMER_ADD_CLIENT(id)\ 312 static TimerClient UID__;\ 313 static TimerClient* id = timer_AddClient(&UID__, WIDEN(#id)) 350 template<
class BillingPolicy = BillingPolicy_Default>
365 BillingPolicy()(m_tc,
m_t0, t1);
392 #define TIMER_ACCRUE(client) ScopeTimerAccrue<> UID__(client) 393 #define TIMER_ACCRUE_ATOMIC(client) ScopeTimerAccrue<BillingPolicy_Atomic> UID__(client) 395 #endif // #ifndef INCLUDED_TIMER TimerClient * m_tc
Definition: timer.h:370
int64_t i64
Definition: types.h:35
void timer_DisplayClientTotals()
display all clients' totals; does not reset them.
Definition: timer.cpp:192
double os_cpu_ClockFrequency()
Definition: os_cpu.cpp:43
TimerUnit m_t0
Definition: timer.h:369
TimerClient * timer_AddClient(TimerClient *tc, const wchar_t *description)
make the given TimerClient (usually instantiated as static data) ready for use.
Definition: timer.cpp:177
ScopeTimer(const wchar_t *description)
Definition: timer.h:80
std::string ToString(const ScriptRequest &rq, JS::MutableHandleValue obj, bool pretty=false)
Convert an object to a UTF-8 encoded string, either with JSON (if pretty == true and there is no JSON...
Definition: JSON.cpp:117
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
Definition: utf8.cpp:212
void timer_Init()
timer_Time will subsequently return values relative to the current time.
Definition: timer.cpp:104
void AddDifferenceAtomic(TimerUnit t0, TimerUnit t1)
Definition: timer.h:238
TimerClient * next
Definition: timer.h:284
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
std::string StringForCycles(Cycles cycles)
Definition: timer.cpp:225
bill the difference between t0 and t1 to the client's total.
Definition: timer.h:318
void AddDifference(TimerUnit t0, TimerUnit t1)
Definition: timer.h:233
double timer_Time()
Definition: timer.cpp:130
double timer_Resolution()
Definition: timer.cpp:158
std::string ToString() const
Definition: timer.h:257
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:290
thread-safe (not used by default due to its higher overhead) note: we can't just use thread-local var...
Definition: timer.h:333
u64 rdtsc()
Definition: x86_x64.cpp:373
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
Definition: timer.h:320
bool cpu_CAS64(volatile i64 *location, i64 expected, i64 newValue)
Definition: aarch64.cpp:41
TimerUnit sum
Definition: timer.h:279
void debug_printf(const char *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
Definition: debug.cpp:148
used by TIMER
Definition: timer.h:76
void SetFromTimer()
Definition: timer.h:228
const wchar_t * m_description
Definition: timer.h:94
double m_t0
Definition: timer.h:93
i64 Cycles
Definition: timer.h:61
const wchar_t * description
Definition: timer.h:282
void Subtract(TimerUnit t)
Definition: timer.h:252
used by TIMER_ACCRUE
Definition: timer.h:351
std::string StringForSeconds(double seconds)
internal helper functions for returning an easily readable string (i.e.
Definition: timer.cpp:209
void SetToZero()
Definition: timer.h:223
double m_seconds
Definition: timer.h:269
~ScopeTimerAccrue()
Definition: timer.h:361
double ToSeconds() const
Definition: timer.h:263
~ScopeTimer()
Definition: timer.h:85
void operator()(TimerClient *tc, TimerUnit t0, TimerUnit t1) const
Definition: timer.h:335
intptr_t num_calls
Definition: timer.h:288
ScopeTimerAccrue(TimerClient *tc)
Definition: timer.h:355