Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement throughput calculation #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -197,5 +203,5 @@ void print_aggregated_metrics(struct thread_context *ctx, int num)
}
}

print_metrics(&context);
print_metrics(&context, timediff);
}
6 changes: 3 additions & 3 deletions metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,7 +53,7 @@ struct ResultMetrics {
long error_count;
};

#ifdef __cplusplus
#ifdef __cplusplus
}
#endif

Expand Down