Default to using gettimeofday()
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index ccab0c70ca855f0ce94a6ad80767b31d4a44b129..9df6c1c803b0a074f557e670455a8af39092e89e 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -6,7 +6,6 @@
 #include <dirent.h>
 #include <libgen.h>
 #include <math.h>
-#include <assert.h>
 
 #include "fio.h"
 
@@ -580,8 +579,8 @@ static void __sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
                mean = src->mean;
                S = src->S;
        } else {
-               mean = ((src->mean * (double) nr) + dst->mean) / ((double) nr + 1.0);
-               S = ((src->S * (double) nr) + dst->S) / ((double) nr + 1.0);
+               mean = ((src->mean * (double) (nr - 1)) + dst->mean) / ((double) nr);
+               S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr);
        }
 
        dst->mean = mean;
@@ -652,11 +651,21 @@ void show_run_stats(void)
                members++;
 
                if (!ts->groupid) {
+                       /*
+                        * These are per-group shared already
+                        */
                        ts->name = td->name;
                        ts->description = td->description;
-                       ts->error = td->error;
                        ts->groupid = td->groupid;
+
+                       /*
+                        * first pid in group, not very useful...
+                        */
                        ts->pid = td->pid;
+               }
+
+               if (td->error && !ts->error) {
+                       ts->error = td->error;
                        ts->verror = td->verror;
                }
 
@@ -720,9 +729,9 @@ void show_run_stats(void)
 
                rbw = wbw = 0;
                if (ts->runtime[0])
-                       rbw = td->io_bytes[0] / (unsigned long long) ts->runtime[0];
+                       rbw = ts->io_bytes[0] / (unsigned long long) ts->runtime[0];
                if (ts->runtime[1])
-                       wbw = td->io_bytes[1] / (unsigned long long) ts->runtime[1];
+                       wbw = ts->io_bytes[1] / (unsigned long long) ts->runtime[1];
 
                if (rbw < rs->min_bw[0])
                        rs->min_bw[0] = rbw;
@@ -776,7 +785,7 @@ void show_run_stats(void)
 static inline void add_stat_sample(struct io_stat *is, unsigned long data)
 {
        double val = data;
-       double delta, n;
+       double delta;
 
        if (data > is->max_val)
                is->max_val = data;
@@ -784,8 +793,7 @@ static inline void add_stat_sample(struct io_stat *is, unsigned long data)
                is->min_val = data;
 
        delta = val - is->mean;
-       n = is->samples + 1.0;
-       is->mean += delta / n;
+       is->mean += delta / (is->samples + 1.0);
        is->S += delta * (val - is->mean);
 
        is->samples++;