Cache session/[{cursor, config}] for reuse and spawn threads when needed. #9

Merged
gburd merged 30 commits from gsb-ctx-cache into master 2013-07-03 12:31:15 +00:00
3 changed files with 36 additions and 16 deletions
Showing only changes of commit b2c0b65114 - Show all commits

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,9 +50,9 @@ 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));
} }
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
@ -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" );
@ -90,14 +110,14 @@ static inline uint64_t elapsed(duration_t *d)
#define ELAPSED_DURING(result, resolution, block) \ #define ELAPSED_DURING(result, resolution, block) \
do { \ do { \
DURATION(__x, resolution); \ DURATION(__x, resolution); \
do block while(0); \ do block while(0); \
*result = elapsed(&__x); \ *result = elapsed(&__x); \
} while(0); } while(0);
#define CYCLES_DURING(result, block) \ #define CYCLES_DURING(result, block) \
do { \ do { \
uint64_t __begin = cpu_clock_ticks(); \ uint64_t __begin = cpu_clock_ticks(); \
do block while(0); \ do block while(0); \
*result = cpu_clock_ticks() - __begin; \ *result = cpu_clock_ticks() - __begin; \
} while(0); } while(0);

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;