48 # define HAVE_GETTIMEOFDAY 1
50 # define HAVE_GETTIMEOFDAY 0
53 #if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) || OS_WIN
54 # define HAVE_CLOCK_GETTIME 1
56 # define HAVE_CLOCK_GETTIME 0
64 #if HAVE_CLOCK_GETTIME
66 #elif HAVE_GETTIMEOFDAY
67 static struct timeval start;
78 #elif HAVE_CLOCK_GETTIME
80 #elif HAVE_GETTIMEOFDAY
81 gettimeofday(&start, 0);
91 static double maxTime;
92 maxTime = std::max(maxTime, newTime);
104 #elif HAVE_CLOCK_GETTIME
105 ENSURE(start.tv_sec || start.tv_nsec);
108 t = (cur.
tv_sec - start.tv_sec) + (cur.
tv_nsec - start.tv_nsec)*1e-9;
109 #elif HAVE_GETTIMEOFDAY
110 ENSURE(start.tv_sec || start.tv_usec);
112 gettimeofday(&cur, 0);
113 t = (cur.tv_sec - start.tv_sec) + (cur.tv_usec - start.tv_usec)*1e-6;
115 # error "timer_Time: add timer implementation for this platform!"
130 #elif HAVE_CLOCK_GETTIME
184 debug_printf(L
"-----------------------------------------------------\n");
198 debug_printf(L
"-----------------------------------------------------\n");
207 const wchar_t* unit = L
" us";
209 scale = 1, unit = L
" s";
210 else if(seconds > 1e-3)
211 scale = 1e3, unit = L
" ms";
213 std::wstringstream ss;
223 const wchar_t* unit = L
" c";
224 if(cycles > 10000000000LL)
225 scale = 1e-9, unit = L
" Gc";
226 else if(cycles > 10000000)
227 scale = 1e-6, unit = L
" Mc";
228 else if(cycles > 10000)
229 scale = 1e-3, unit = L
" kc";
231 std::wstringstream ss;
static pthread_mutex_t ensure_monotonic_mutex
static TimerClient * clients
int clock_gettime(clockid_t clock, struct timespec *ts)
TimerClient * timer_AddClient(TimerClient *tc, const wchar_t *description)
make the given TimerClient (usually instantiated as static data) ready for use.
static ModuleInitState initState
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
intptr_t ModuleInitState
initialization state of a module (class, source file, etc.) must be initialized to zero (e...
static Status InitResolution()
void timer_LatchStartTime()
timer_Time will subsequently return values relative to the current time.
int pthread_mutex_lock(pthread_mutex_t *m)
i64 Status
Error handling system.
double timer_Resolution()
const wchar_t * description
int pthread_mutex_unlock(pthread_mutex_t *m)
int clock_getres(clockid_t clock, struct timespec *ts)
#define PTHREAD_MUTEX_INITIALIZER
std::wstring ToString() const
Status ModuleInit(volatile ModuleInitState *initState, Status(*init)())
calls a user-defined init function if initState is zero.
std::wstring StringForSeconds(double seconds)
internal helper functions for returning an easily readable string (i.e.
std::wstring StringForCycles(Cycles cycles)
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
static void EnsureMonotonic(double &newTime)
void timer_DisplayClientTotals()
display all clients' totals; does not reset them.