Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:steveyen/moxi
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyen committed May 21, 2009
2 parents 6ef39fc + 70e6dba commit 0f49b41
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions agent_ping.c
Expand Up @@ -322,6 +322,9 @@ void ping_server(char *server_name,
"max", recipe_stats.max);
stat_report(val_name, vlen, recipes[j].name,
"stddev", recipe_stats.stddev);
stat_report(val_name, vlen, recipes[j].name,
"95th", recipe_stats.ninetyfifth);


snprintf(val_name, vlen, "%s_fail", recipes[j].name);
int_report(val_name, failures);
Expand Down
2 changes: 2 additions & 0 deletions check_util.c
Expand Up @@ -189,6 +189,8 @@ START_TEST (test_compute_stats)
fail_unless(almost_equal(stats.avg, 5.0), "Avg should be 5");
fail_unless(almost_equal(stats.stddev, 2.0),
"Standard devition should be 2.");
fail_unless(almost_equal(stats.ninetyfifth, 9.0),
"95th %%ile should be 9.");
}
END_TEST

Expand Down
13 changes: 12 additions & 1 deletion util.c
Expand Up @@ -119,7 +119,14 @@ double timeval_to_double(struct timeval tv)
return (double)tv.tv_sec + ((double)tv.tv_usec / 1000000);
}

void compute_stats(struct moxi_stats *out, const double *vals, int num_vals)
static int cmp_doubles(const void *pa, const void *pb)
{
double a = *(double*)pa;
double b = *(double*)pb;
return a == b ? 0 : (a < b ? -1 : 1);
}

void compute_stats(struct moxi_stats *out, double *vals, int num_vals)
{
assert(out);
assert(vals);
Expand Down Expand Up @@ -147,4 +154,8 @@ void compute_stats(struct moxi_stats *out, const double *vals, int num_vals)
}

out->stddev = sqrt(sum / num_vals);

// 95th %ile
qsort(vals, num_vals, sizeof(double), cmp_doubles);
out->ninetyfifth = vals[(int)((float)num_vals * 0.95)];
}
7 changes: 6 additions & 1 deletion util.h
Expand Up @@ -32,9 +32,14 @@ struct moxi_stats {
double max;
double avg;
double stddev;
double ninetyfifth;
};

/**
* Compute some statistics over a sequence.
*
* @param out accumulated stats for input values
* @param vals input values (note: these will be reordered)
* @param num_values the number of values to be processed
*/
void compute_stats(struct moxi_stats *out, const double *vals, int num_vals);
void compute_stats(struct moxi_stats *out, double *vals, int num_vals);

0 comments on commit 0f49b41

Please sign in to comment.