X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=stat.c;h=8be4be5761cbfda454da47f541965a67115c6b26;hp=9f22c6e159c3c1a4c0a6a411d2d7da4a78b63aad;hb=cdcac5cf0e9262105e676874d11c4639a80574eb;hpb=31d23f47d5ee53f74fbf20e17e83c7cb42e39878 diff --git a/stat.c b/stat.c index 9f22c6e1..8be4be57 100644 --- a/stat.c +++ b/stat.c @@ -474,21 +474,28 @@ static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) dst->min_val = min(dst->min_val, src->min_val); dst->max_val = max(dst->max_val, src->max_val); - dst->samples += src->samples; /* - * Needs a new method for calculating stddev, we cannot just - * average them we do below for nr > 1 + * Compute new mean and S after the merge + * */ if (nr == 1) { mean = src->mean; S = src->S; } else { - mean = ((src->mean * (double) (nr - 1)) - + dst->mean) / ((double) nr); - S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr); + double delta = src->mean - dst->mean; + + mean = ((src->mean * src->samples) + + (dst->mean * dst->samples)) / + (dst->samples + src->samples); + + S = src->S + dst->S + pow(delta, 2.0) * + (dst->samples * src->samples) / + (dst->samples + src->samples); } + dst->samples += src->samples; dst->mean = mean; dst->S = S; }