diff --git a/main.c b/main.c index 910f456..1db0b5f 100644 --- a/main.c +++ b/main.c @@ -623,7 +623,7 @@ static int populate_dataset(struct thread_context *ctx) { int sres = -1; if (end > ctx->offset) - ctx->offset = 0; + ctx->offset = 0; if (verbose) { fprintf(stderr, "Populating from %d to %d\n", ctx->offset, end); @@ -958,7 +958,7 @@ int main(int argc, char **argv) { case 'h': add_host(optarg); break; case 'T': runtime_limit = atol(optarg); - break; + break; case 'i': no_items = atoi(optarg); break; case 's': srand(atoi(optarg)); @@ -1085,7 +1085,7 @@ int main(int argc, char **argv) { start_time = (int) time (NULL); if (runtime_limit > 0) { - alarm(runtime_limit); + alarm(runtime_limit); } } size_t nget = 0; @@ -1094,7 +1094,9 @@ int main(int argc, char **argv) { pthread_t *threads = calloc(sizeof(pthread_t), no_threads); struct thread_context *ctx = calloc(sizeof(struct thread_context), no_threads); int ii; + struct timespec local_start, local_end; + if (clock_gettime(CLOCK_MONOTONIC, &local_start)) abort(); if (no_iterations > 0) { int perThread = no_iterations / no_threads; int rest = no_iterations % no_threads; @@ -1118,13 +1120,16 @@ int main(int argc, char **argv) { assert(ret == (void*)&ctx[ii]); if (verbose) { fprintf(stdout, "Details from thread %d\n", ii); - print_metrics(&ctx[ii]); + print_metrics(&ctx[ii], 0); } } } + if (clock_gettime(CLOCK_MONOTONIC, &local_end)) abort(); + double time_diff = 1e-9*(local_end.tv_nsec - local_start.tv_nsec) + local_end.tv_sec - local_start.tv_sec; fprintf(stdout, "Average with %d threads\n", no_threads); - print_aggregated_metrics(ctx, no_threads); + print_aggregated_metrics(ctx, no_threads, time_diff); + free(threads); free(ctx); } while (loop); diff --git a/metrics.c b/metrics.c index 119b707..6cca82c 100644 --- a/metrics.c +++ b/metrics.c @@ -166,19 +166,25 @@ static void print_details(enum TxnType tx_type, struct ResultMetrics *r) { hrtime2text(r->max99th_result, tmax99, sizeof(tmax99))); } -void print_metrics(struct thread_context *ctx) { +void print_metrics(struct thread_context *ctx, double timediff) { + long total_count = 0; for (int ii = 0; ii < TX_CAS - TX_GET; ++ii) { if (ctx->tx[ii].current > 0) { struct ResultMetrics *r = calc_metrics(ii, ctx); if (r) { print_details(ii, r); + total_count += r->success_count; free(r); } } } + if (timediff) { + double throughput = total_count/timediff; + fprintf(stdout, "Throughput: %g s^-1\n", throughput); + } } -void print_aggregated_metrics(struct thread_context *ctx, int num) +void print_aggregated_metrics(struct thread_context *ctx, int num, double timediff) { int total = 0; for (int ii = 0; ii < num; ++ii) { @@ -197,5 +203,5 @@ void print_aggregated_metrics(struct thread_context *ctx, int num) } } - print_metrics(&context); + print_metrics(&context, timediff); } diff --git a/metrics.h b/metrics.h index e1566fb..689b3b4 100644 --- a/metrics.h +++ b/metrics.h @@ -39,8 +39,8 @@ struct thread_context; void record_tx(enum TxnType, hrtime_t, struct thread_context *); struct ResultMetrics *calc_metrics(enum TxnType tx_type, struct thread_context *); -void print_metrics(struct thread_context *); -void print_aggregated_metrics(struct thread_context *, int); +void print_metrics(struct thread_context *, double); +void print_aggregated_metrics(struct thread_context *, int, double); struct ResultMetrics { hrtime_t max_result; @@ -53,7 +53,7 @@ struct ResultMetrics { long error_count; }; -#ifdef __cplusplus +#ifdef __cplusplus } #endif