summaryrefslogtreecommitdiff
path: root/bench/wtperf/misc.c
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2013-11-23 15:06:39 -0500
committerKeith Bostic <keith@wiredtiger.com>2013-11-23 15:06:39 -0500
commit2e4f631227cd37daeb7edcc178d67e01b7f18690 (patch)
treedd12203319431b87ce0023338b0dac15dedb4ae4 /bench/wtperf/misc.c
parent40ac21f4f14f4ead913338a8bce6be008f7e0598 (diff)
downloadmongo-2e4f631227cd37daeb7edcc178d67e01b7f18690.tar.gz
Add support for tracking operation latency in wtperf.
Diffstat (limited to 'bench/wtperf/misc.c')
-rw-r--r--bench/wtperf/misc.c194
1 files changed, 194 insertions, 0 deletions
diff --git a/bench/wtperf/misc.c b/bench/wtperf/misc.c
index e5182cf4d3d..44d882cea7a 100644
--- a/bench/wtperf/misc.c
+++ b/bench/wtperf/misc.c
@@ -27,6 +27,200 @@
#include "wtperf.h"
+/*
+ * Return total operations count for a group of threads.
+ */
+static uint64_t
+sum_ops(CONFIG *cfg, size_t off)
+{
+ 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 + off))->ops;
+ for (i = 0, thread = cfg->ithreads;
+ thread != NULL && i < cfg->insert_threads;
+ ++i, ++thread)
+ total += ((TRACK *)((uint8_t *)thread + off))->ops;
+ for (i = 0, thread = cfg->rthreads;
+ thread != NULL && i < cfg->read_threads;
+ ++i, ++thread)
+ total += ((TRACK *)((uint8_t *)thread + off))->ops;
+ for (i = 0, thread = cfg->uthreads;
+ thread != NULL && i < cfg->update_threads;
+ ++i, ++thread)
+ total += ((TRACK *)((uint8_t *)thread + off))->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)));
+}
+
+/*
+ * sum_latency_thread --
+ * Sum latency for a single thread.
+ */
+static void
+sum_latency_thread(CONFIG_THREAD *thread, size_t off, TRACK *total)
+{
+ TRACK *trk;
+ u_int i;
+
+ trk = (TRACK *)((uint8_t *)thread + off);
+
+ 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 off, 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, off, total);
+ for (i = 0, thread = cfg->rthreads;
+ thread != NULL && i < cfg->read_threads; ++i, ++thread)
+ sum_latency_thread(thread, off, total);
+ for (i = 0, thread = cfg->uthreads;
+ thread != NULL && i < cfg->update_threads; ++i, ++thread)
+ sum_latency_thread(thread, off, 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
+dump_latency_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;
+ }
+
+ cumops = 0;
+ for (i = 0; i < ELEMENTS(total->us); ++i) {
+ if (total->us[i] == 0)
+ continue;
+ cumops += total->us[i];
+ fprintf(fp,
+ "%u,%" PRIu64 ",%" 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,%" PRIu64 ",%" 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,%" PRIu64 ",%" PRIu64 ",%" PRIu64 "\n",
+ sec_to_us(i + 1), total->sec[i], cumops, total->ops);
+ }
+
+ (void)fclose(fp);
+}
+
+void
+dump_latency(CONFIG *cfg)
+{
+ TRACK total;
+
+ sum_insert_latency(cfg, &total);
+ dump_latency_single(cfg, &total, "insert");
+ sum_read_latency(cfg, &total);
+ dump_latency_single(cfg, &total, "read");
+ sum_update_latency(cfg, &total);
+ dump_latency_single(cfg, &total, "update");
+}
+
int
enomem(const CONFIG *cfg)
{