Fix stat summing for unified_rw_reporting
authorJens Axboe <axboe@fb.com>
Mon, 7 Dec 2015 21:30:34 +0000 (14:30 -0700)
committerJens Axboe <axboe@fb.com>
Mon, 7 Dec 2015 21:30:34 +0000 (14:30 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
client.c
gclient.c
stat.c
stat.h
workqueue.c

index db472c4cb0b4cb1d87368358b8bb34d65f78d94c..2cba8a034993a6aa55d351c5c3f8dfa7b5a8ef02 100644 (file)
--- a/client.c
+++ b/client.c
@@ -946,7 +946,7 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
        if (sum_stat_clients <= 1)
                return;
 
-       sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
+       sum_thread_stats(&client_ts, &p->ts, sum_stat_nr == 1);
        sum_group_stats(&client_gs, &p->rs);
 
        client_ts.members++;
index d7d9616e4ef00d297055032fa6e600c3f28247d2..17af38ab381499b74193d018fa0921f83d0cd631 100644 (file)
--- a/gclient.c
+++ b/gclient.c
@@ -296,7 +296,7 @@ static void gfio_thread_status_op(struct fio_client *client,
        if (sum_stat_clients == 1)
                return;
 
-       sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
+       sum_thread_stats(&client_ts, &p->ts, sum_stat_nr == 1);
        sum_group_stats(&client_gs, &p->rs);
 
        client_ts.members++;
diff --git a/stat.c b/stat.c
index e5ec22374b8c2d410fdfa1e841ba93c0ad8ecd08..818756dd8537d3385995ae817a7815f57c0c3008 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1253,7 +1253,7 @@ struct json_object *show_thread_status(struct thread_stat *ts,
        return ret;
 }
 
-static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
+static void sum_stat(struct io_stat *dst, struct io_stat *src, bool first)
 {
        double mean, S;
 
@@ -1268,7 +1268,7 @@ static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
         * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
         *  #Parallel_algorithm>
         */
-       if (nr == 1) {
+       if (first) {
                mean = src->mean.u.f;
                S = src->S.u.f;
        } else {
@@ -1312,31 +1312,38 @@ void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
                dst->unit_base = src->unit_base;
 }
 
-void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
+void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src,
+                     bool first)
 {
        int l, k;
 
        for (l = 0; l < DDIR_RWDIR_CNT; l++) {
                if (!dst->unified_rw_rep) {
-                       sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
-                       sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
-                       sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
-                       sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
+                       sum_stat(&dst->clat_stat[l], &src->clat_stat[l], first);
+                       sum_stat(&dst->slat_stat[l], &src->slat_stat[l], first);
+                       sum_stat(&dst->lat_stat[l], &src->lat_stat[l], first);
+                       sum_stat(&dst->bw_stat[l], &src->bw_stat[l], first);
 
                        dst->io_bytes[l] += src->io_bytes[l];
 
                        if (dst->runtime[l] < src->runtime[l])
                                dst->runtime[l] = src->runtime[l];
                } else {
-                       sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr);
-                       sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr);
-                       sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr);
-                       sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr);
+                       sum_stat(&dst->clat_stat[0], &src->clat_stat[l], first);
+                       sum_stat(&dst->slat_stat[0], &src->slat_stat[l], first);
+                       sum_stat(&dst->lat_stat[0], &src->lat_stat[l], first);
+                       sum_stat(&dst->bw_stat[0], &src->bw_stat[l], first);
 
                        dst->io_bytes[0] += src->io_bytes[l];
 
                        if (dst->runtime[0] < src->runtime[l])
                                dst->runtime[0] = src->runtime[l];
+
+                       /*
+                        * We're summing to the same destination, so override
+                        * 'first' after the first iteration of the loop
+                        */
+                       first = false;
                }
        }
 
@@ -1531,7 +1538,7 @@ void __show_run_stats(void)
                for (k = 0; k < ts->nr_block_infos; k++)
                        ts->block_infos[k] = td->ts.block_infos[k];
 
-               sum_thread_stats(ts, &td->ts, idx);
+               sum_thread_stats(ts, &td->ts, idx == 1);
        }
 
        for (i = 0; i < nr_ts; i++) {
diff --git a/stat.h b/stat.h
index 0fc5533fd20529efbd65b3cc47e1bf5b8e84c094..33afd9b845b95a2283622f3a8661ff20eaef303f 100644 (file)
--- a/stat.h
+++ b/stat.h
@@ -256,7 +256,7 @@ extern void __show_run_stats(void);
 extern void __show_running_run_stats(void);
 extern void show_running_run_stats(void);
 extern void check_for_running_stats(void);
-extern void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr);
+extern void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, bool first);
 extern void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src);
 extern void init_thread_stat(struct thread_stat *ts);
 extern void init_group_run_stat(struct group_run_stats *gs);
index 27570b2a0b20e5e7cd4ad0a9ccaacf697f6962c7..8d43b090229c1eabda627bdc2b87f91beb3b2873 100644 (file)
@@ -363,7 +363,7 @@ static void shutdown_worker(struct submit_worker *sw, unsigned int *sum_cnt)
 
        pthread_join(sw->thread, NULL);
        (*sum_cnt)++;
-       sum_thread_stats(&parent->ts, &sw->td.ts, *sum_cnt);
+       sum_thread_stats(&parent->ts, &sw->td.ts, *sum_cnt == 1);
        free_worker(sw);
 }