Fixes for OS/X and whitespace cleanup.

This commit is contained in:
Gregory Burd 2013-06-06 15:16:50 -04:00
parent 0fef28de92
commit b2c0b65114
3 changed files with 36 additions and 16 deletions

View file

@ -13,6 +13,28 @@
#include <time.h> #include <time.h>
#include <sys/timeb.h> #include <sys/timeb.h>
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#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; typedef enum { ns = 0, mcs, ms, s } time_scale;
struct scale_time { struct scale_time {
const char *abbreviation; const char *abbreviation;
@ -28,7 +50,7 @@ static const struct scale_time scale[] = {
static uint64_t ts(time_scale unit) static uint64_t ts(time_scale unit)
{ {
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); current_utc_time(&ts);
return (((uint64_t)ts.tv_sec * scale[unit].mul) + 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));
} }
@ -45,11 +67,9 @@ static inline uint64_t cpu_clock_ticks()
{ {
uint32_t lo, hi; uint32_t lo, hi;
__asm__ __volatile__ ( __asm__ __volatile__ (
"; Flush the pipeline" "XORL %%eax, %%eax\n" /* Flush the pipeline */
"XORL %%eax, %%eax\n"
"CPUID\n" "CPUID\n"
"; Get RDTSC counter in edx:eax" "RDTSC\n" /* Get RDTSC counter in edx:eax */
"RDTSC\n"
: "=a" (lo), "=d" (hi) : "=a" (lo), "=d" (hi)
: :
: "%ebx", "%ecx" ); : "%ebx", "%ecx" );

View file

@ -152,7 +152,7 @@ static unsigned int __log2_64(uint64_t x) {
fprintf(stderr, " ns μs ms s ks\n"); \ fprintf(stderr, " ns μs ms s ks\n"); \
fprintf(stderr, "min: "); \ fprintf(stderr, "min: "); \
if (s->min < 1000) \ if (s->min < 1000) \
fprintf(stderr, "%lu (ns)", s->min); \ fprintf(stderr, "%llu (ns)", s->min); \
else if (s->min < 1000000) \ else if (s->min < 1000000) \
fprintf(stderr, "%.2f (μs)", s->min / 1000.0); \ fprintf(stderr, "%.2f (μs)", s->min / 1000.0); \
else if (s->min < 1000000000) \ 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, "%.2f (s)", s->min / 1000000000.0); \
fprintf(stderr, " max: "); \ fprintf(stderr, " max: "); \
if (s->max < 1000) \ if (s->max < 1000) \
fprintf(stderr, "%lu (ns)", s->max); \ fprintf(stderr, "%llu (ns)", s->max); \
else if (s->max < 1000000) \ else if (s->max < 1000000) \
fprintf(stderr, "%.2f (μs)", s->max / 1000.0); \ fprintf(stderr, "%.2f (μs)", s->max / 1000.0); \
else if (s->max < 1000000000) \ else if (s->max < 1000000000) \

View file

@ -613,9 +613,9 @@ __wterl_progress_handler(WT_EVENT_HANDLER *handler, const char *operation, uint6
enif_make_int64(msg_env, counter))); enif_make_int64(msg_env, counter)));
enif_clear_env(msg_env); enif_clear_env(msg_env);
if (!enif_send(NULL, to_pid, msg_env, msg)) if (!enif_send(NULL, to_pid, msg_env, msg))
fprintf(stderr, "[%ld] %s\n", counter, operation); fprintf(stderr, "[%llu] %s\n", counter, operation);
} else { } 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); enif_mutex_unlock(eh->progress_mutex);
return rc; return rc;