diff options
author | Keith Bostic <keith@wiredtiger.com> | 2013-11-26 17:36:42 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2013-11-26 17:36:42 -0500 |
commit | 7bb57d89faab7fde7397e2add8493645298440a7 (patch) | |
tree | 48dac9feef75d6ff29dc268ae211c20373b1e64e /bench/wtperf/misc.c | |
parent | 8f10c6b0fd078f45a04984a51424b94550f80638 (diff) | |
download | mongo-7bb57d89faab7fde7397e2add8493645298440a7.tar.gz |
Break out the operation/latency tracking code into its own file.
Diffstat (limited to 'bench/wtperf/misc.c')
-rw-r--r-- | bench/wtperf/misc.c | 344 |
1 files changed, 0 insertions, 344 deletions
diff --git a/bench/wtperf/misc.c b/bench/wtperf/misc.c index fc06f3727cf..e5182cf4d3d 100644 --- a/bench/wtperf/misc.c +++ b/bench/wtperf/misc.c @@ -27,350 +27,6 @@ #include "wtperf.h" -/* - * Return total operations count for a group of threads. - */ -static uint64_t -sum_ops(CONFIG *cfg, size_t field_offset) -{ - CONFIG_THREAD *thread; - uint64_t total; - u_int i; - - total = 0; - - for (i = 0, thread = cfg->ckptthreads; - thread != NULL && i < cfg->checkpoint_threads; - ++i, ++thread) - total += ((TRACK *)((uint8_t *)thread + field_offset))->ops; - for (i = 0, thread = cfg->ithreads; - thread != NULL && i < cfg->insert_threads; - ++i, ++thread) - total += ((TRACK *)((uint8_t *)thread + field_offset))->ops; - for (i = 0, thread = cfg->rthreads; - thread != NULL && i < cfg->read_threads; - ++i, ++thread) - total += ((TRACK *)((uint8_t *)thread + field_offset))->ops; - for (i = 0, thread = cfg->uthreads; - thread != NULL && i < cfg->update_threads; - ++i, ++thread) - total += ((TRACK *)((uint8_t *)thread + field_offset))->ops; - - return (total); -} - -/* - * Return total insert operations for the populate phase. - */ -uint64_t -sum_pop_ops(CONFIG *cfg) -{ - CONFIG_THREAD *thread; - uint64_t total; - u_int i; - - total = 0; - - for (i = 0, thread = cfg->popthreads; - thread != NULL && i < cfg->populate_threads; ++i, ++thread) - total += thread->insert.ops; - return (total); -} - -uint64_t -sum_ckpt_ops(CONFIG *cfg) -{ - return (sum_ops(cfg, offsetof(CONFIG_THREAD, ckpt))); -} -uint64_t -sum_insert_ops(CONFIG *cfg) -{ - return (sum_ops(cfg, offsetof(CONFIG_THREAD, insert))); -} -uint64_t -sum_read_ops(CONFIG *cfg) -{ - return (sum_ops(cfg, offsetof(CONFIG_THREAD, read))); -} -uint64_t -sum_update_ops(CONFIG *cfg) -{ - return (sum_ops(cfg, offsetof(CONFIG_THREAD, update))); -} - -/* - * latency_op -- - * Get average, minimum and maximum latency for this period for a - * particular operation. - */ -static void -latency_op(CONFIG *cfg, - size_t field_offset, uint32_t *avgp, uint32_t *minp, uint32_t *maxp) -{ - CONFIG_THREAD *thread; - TRACK *track; - uint64_t ops, latency, tmp; - uint32_t max, min; - u_int i; - - ops = latency = 0; - max = 0; - min = UINT32_MAX; - for (i = 0, thread = cfg->ithreads; - thread != NULL && i < cfg->insert_threads; ++i, ++thread) { - track = (TRACK *)((uint8_t *)thread + field_offset); - tmp = track->ops; - ops += tmp - track->last_ops; - track->last_ops = tmp; - tmp = track->latency; - latency += tmp - track->last_latency; - track->last_latency = tmp; - - if (min > track->min_latency) - min = track->min_latency; - track->min_latency = UINT32_MAX; - if (max < track->max_latency) - max = track->max_latency; - track->max_latency = 0; - } - for (i = 0, thread = cfg->rthreads; - thread != NULL && i < cfg->read_threads; ++i, ++thread) { - track = (TRACK *)((uint8_t *)thread + field_offset); - tmp = track->ops; - ops += tmp - track->last_ops; - track->last_ops = tmp; - tmp = track->latency; - latency += tmp - track->last_latency; - track->last_latency = tmp; - - if (min > track->min_latency) - min = track->min_latency; - track->min_latency = UINT32_MAX; - if (max < track->max_latency) - max = track->max_latency; - track->max_latency = 0; - } - for (i = 0, thread = cfg->uthreads; - thread != NULL && i < cfg->update_threads; ++i, ++thread) { - track = (TRACK *)((uint8_t *)thread + field_offset); - tmp = track->ops; - ops += tmp - track->last_ops; - track->last_ops = tmp; - tmp = track->latency; - latency += tmp - track->last_latency; - track->last_latency = tmp; - - if (min > track->min_latency) - min = track->min_latency; - track->min_latency = UINT32_MAX; - if (max < track->max_latency) - max = track->max_latency; - track->max_latency = 0; - } - - if (ops == 0) - *avgp = *minp = *maxp = 0; - else { - *minp = min; - *maxp = max; - *avgp = (uint32_t)(latency / ops); - } -} - -void -latency_read(CONFIG *cfg, uint32_t *avgp, uint32_t *minp, uint32_t *maxp) -{ - static uint32_t last_avg = 0, last_max = 0, last_min = 0; - - latency_op(cfg, offsetof(CONFIG_THREAD, read), avgp, minp, maxp); - - /* - * If nothing happened, graph the average, minimum and maximum as they - * were the last time, it keeps the graphs from having discontinuities. - */ - if (*minp == 0) { - *avgp = last_avg; - *minp = last_min; - *maxp = last_max; - } else { - last_avg = *avgp; - last_min = *minp; - last_max = *maxp; - } -} - -void -latency_insert(CONFIG *cfg, uint32_t *avgp, uint32_t *minp, uint32_t *maxp) -{ - static uint32_t last_avg = 0, last_max = 0, last_min = 0; - - latency_op(cfg, offsetof(CONFIG_THREAD, insert), avgp, minp, maxp); - - /* - * If nothing happened, graph the average, minimum and maximum as they - * were the last time, it keeps the graphs from having discontinuities. - */ - if (*minp == 0) { - *avgp = last_avg; - *minp = last_min; - *maxp = last_max; - } else { - last_avg = *avgp; - last_min = *minp; - last_max = *maxp; - } -} - -void -latency_update(CONFIG *cfg, uint32_t *avgp, uint32_t *minp, uint32_t *maxp) -{ - static uint32_t last_avg = 0, last_max = 0, last_min = 0; - - latency_op(cfg, offsetof(CONFIG_THREAD, update), avgp, minp, maxp); - - /* - * If nothing happened, graph the average, minimum and maximum as they - * were the last time, it keeps the graphs from having discontinuities. - */ - if (*minp == 0) { - *avgp = last_avg; - *minp = last_min; - *maxp = last_max; - } else { - last_avg = *avgp; - last_min = *minp; - last_max = *maxp; - } -} - -/* - * sum_latency_thread -- - * Sum latency for a single thread. - */ -static void -sum_latency_thread(CONFIG_THREAD *thread, size_t field_offset, TRACK *total) -{ - TRACK *trk; - u_int i; - - trk = (TRACK *)((uint8_t *)thread + field_offset); - - for (i = 0; i < ELEMENTS(trk->us); ++i) { - total->ops += trk->us[i]; - total->us[i] += trk->us[i]; - } - for (i = 0; i < ELEMENTS(trk->ms); ++i) { - total->ops += trk->ms[i]; - total->ms[i] += trk->ms[i]; - } - for (i = 0; i < ELEMENTS(trk->sec); ++i) { - total->ops += trk->sec[i]; - total->sec[i] += trk->sec[i]; - } -} - -/* - * sum_latency -- - * Sum latency for a set of threads. - */ -static void -sum_latency(CONFIG *cfg, size_t field_offset, TRACK *total) -{ - CONFIG_THREAD *thread; - u_int i; - - memset(total, 0, sizeof(*total)); - - for (i = 0, thread = cfg->ithreads; - thread != NULL && i < cfg->insert_threads; ++i, ++thread) - sum_latency_thread(thread, field_offset, total); - for (i = 0, thread = cfg->rthreads; - thread != NULL && i < cfg->read_threads; ++i, ++thread) - sum_latency_thread(thread, field_offset, total); - for (i = 0, thread = cfg->uthreads; - thread != NULL && i < cfg->update_threads; ++i, ++thread) - sum_latency_thread(thread, field_offset, total); -} - -static void -sum_insert_latency(CONFIG *cfg, TRACK *total) -{ - sum_latency(cfg, offsetof(CONFIG_THREAD, insert), total); -} - -static void -sum_read_latency(CONFIG *cfg, TRACK *total) -{ - sum_latency(cfg, offsetof(CONFIG_THREAD, read), total); -} - -static void -sum_update_latency(CONFIG *cfg, TRACK *total) -{ - sum_latency(cfg, offsetof(CONFIG_THREAD, update), total); -} - -static void -latency_print_single(CONFIG *cfg, TRACK *total, const char *name) -{ - FILE *fp; - u_int i; - uint64_t cumops; - char path[1024]; - - snprintf(path, sizeof(path), "%s/latency.%s", cfg->home, name); - if ((fp = fopen(path, "w")) == NULL) { - lprintf(cfg, errno, 0, "%s", path); - return; - } - -#ifdef __WRITE_A_HEADER - fprintf(fp, - "usecs,operations,cumulative-operations,total-operations\n"); -#endif - - cumops = 0; - for (i = 0; i < ELEMENTS(total->us); ++i) { - if (total->us[i] == 0) - continue; - cumops += total->us[i]; - fprintf(fp, - "%u,%" PRIu32 ",%" PRIu64 ",%" PRIu64 "\n", - (i + 1), total->us[i], cumops, total->ops); - } - for (i = 1; i < ELEMENTS(total->ms); ++i) { - if (total->ms[i] == 0) - continue; - cumops += total->ms[i]; - fprintf(fp, - "%llu,%" PRIu32 ",%" PRIu64 ",%" PRIu64 "\n", - ms_to_us(i + 1), total->ms[i], cumops, total->ops); - } - for (i = 1; i < ELEMENTS(total->sec); ++i) { - if (total->sec[i] == 0) - continue; - cumops += total->sec[i]; - fprintf(fp, - "%llu,%" PRIu32 ",%" PRIu64 ",%" PRIu64 "\n", - sec_to_us(i + 1), total->sec[i], cumops, total->ops); - } - - (void)fclose(fp); -} - -void -latency_print(CONFIG *cfg) -{ - TRACK total; - - sum_insert_latency(cfg, &total); - latency_print_single(cfg, &total, "insert"); - sum_read_latency(cfg, &total); - latency_print_single(cfg, &total, "read"); - sum_update_latency(cfg, &total); - latency_print_single(cfg, &total, "update"); -} - int enomem(const CONFIG *cfg) { |