diff --git a/c_src/duration.h b/c_src/duration.h index 587a694..fbc97cb 100644 --- a/c_src/duration.h +++ b/c_src/duration.h @@ -13,6 +13,28 @@ #include #include +#ifdef __MACH__ +#include +#include +#endif + + +void current_utc_time(struct timespec *ts) +{ +#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; +#else + clock_gettime(CLOCK_REALTIME, ts); +#endif + +} + typedef enum { ns = 0, mcs, ms, s } time_scale; struct scale_time { const char *abbreviation; @@ -28,9 +50,9 @@ static const struct scale_time scale[] = { static uint64_t ts(time_scale unit) { struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); + current_utc_time(&ts); return (((uint64_t)ts.tv_sec * scale[unit].mul) + - ((uint64_t)ts.tv_nsec / scale[unit].div)); + ((uint64_t)ts.tv_nsec / scale[unit].div)); } #if defined(__i386__) || defined(__x86_64__) @@ -45,11 +67,9 @@ static inline uint64_t cpu_clock_ticks() { uint32_t lo, hi; __asm__ __volatile__ ( - "; Flush the pipeline" - "XORL %%eax, %%eax\n" + "XORL %%eax, %%eax\n" /* Flush the pipeline */ "CPUID\n" - "; Get RDTSC counter in edx:eax" - "RDTSC\n" + "RDTSC\n" /* Get RDTSC counter in edx:eax */ : "=a" (lo), "=d" (hi) : : "%ebx", "%ecx" ); @@ -90,14 +110,14 @@ static inline uint64_t elapsed(duration_t *d) #define ELAPSED_DURING(result, resolution, block) \ do { \ - DURATION(__x, resolution); \ - do block while(0); \ - *result = elapsed(&__x); \ + DURATION(__x, resolution); \ + do block while(0); \ + *result = elapsed(&__x); \ } while(0); #define CYCLES_DURING(result, block) \ do { \ - uint64_t __begin = cpu_clock_ticks(); \ - do block while(0); \ - *result = cpu_clock_ticks() - __begin; \ + uint64_t __begin = cpu_clock_ticks(); \ + do block while(0); \ + *result = cpu_clock_ticks() - __begin; \ } while(0); diff --git a/c_src/stats.h b/c_src/stats.h index 2f465be..f44319b 100644 --- a/c_src/stats.h +++ b/c_src/stats.h @@ -152,7 +152,7 @@ static unsigned int __log2_64(uint64_t x) { fprintf(stderr, " ns μs ms s ks\n"); \ fprintf(stderr, "min: "); \ if (s->min < 1000) \ - fprintf(stderr, "%lu (ns)", s->min); \ + fprintf(stderr, "%llu (ns)", s->min); \ else if (s->min < 1000000) \ fprintf(stderr, "%.2f (μs)", s->min / 1000.0); \ else if (s->min < 1000000000) \ @@ -161,7 +161,7 @@ static unsigned int __log2_64(uint64_t x) { fprintf(stderr, "%.2f (s)", s->min / 1000000000.0); \ fprintf(stderr, " max: "); \ if (s->max < 1000) \ - fprintf(stderr, "%lu (ns)", s->max); \ + fprintf(stderr, "%llu (ns)", s->max); \ else if (s->max < 1000000) \ fprintf(stderr, "%.2f (μs)", s->max / 1000.0); \ else if (s->max < 1000000000) \ diff --git a/c_src/wterl.c b/c_src/wterl.c index fd21196..8756879 100644 --- a/c_src/wterl.c +++ b/c_src/wterl.c @@ -613,9 +613,9 @@ __wterl_progress_handler(WT_EVENT_HANDLER *handler, const char *operation, uint6 enif_make_int64(msg_env, counter))); enif_clear_env(msg_env); if (!enif_send(NULL, to_pid, msg_env, msg)) - fprintf(stderr, "[%ld] %s\n", counter, operation); + fprintf(stderr, "[%llu] %s\n", counter, operation); } else { - rc = (printf("[%ld] %s\n", counter, operation) >= 0 ? 0 : EIO); + rc = (printf("[%llu] %s\n", counter, operation) >= 0 ? 0 : EIO); } enif_mutex_unlock(eh->progress_mutex); return rc;