Use DDIR_WRITE symbolic value instead of a hard coded 2
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index e5e626ce862207de52731ddc6fe2d957dd9d2a83..7b4b9d576a595767e3260b87edf5116a7beab978 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -372,7 +372,7 @@ static void show_group_stats(struct group_run_stats *rs, int id)
                p3 = num2str(rs->min_bw[i], 6, 1);
                p4 = num2str(rs->max_bw[i], 6, 1);
 
-               fprintf(f_out, "%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s, mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, p3, p4, rs->min_run[0], rs->max_run[0]);
+               fprintf(f_out, "%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s, mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
 
                free(p1);
                free(p2);
@@ -590,7 +590,7 @@ static void show_thread_status_terse(struct thread_stat *ts,
        fprintf(f_out, "\n");
 }
 
-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, int nr)
 {
        double mean, S;
 
@@ -614,18 +614,12 @@ static void __sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
        dst->S = S;
 }
 
-static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
-{
-       __sum_stat(&dst[DDIR_READ], &src[DDIR_READ], nr);
-       __sum_stat(&dst[DDIR_WRITE], &src[DDIR_WRITE], nr);
-}
-
 void show_run_stats(void)
 {
        struct group_run_stats *runstats, *rs;
        struct thread_data *td;
        struct thread_stat *threadstats, *ts;
-       int i, j, k, nr_ts, last_ts, members;
+       int i, j, k, l, nr_ts, last_ts, idx;
 
        runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
 
@@ -661,21 +655,20 @@ void show_run_stats(void)
                ts = &threadstats[i];
 
                memset(ts, 0, sizeof(*ts));
-               ts->clat_stat[0].min_val = -1UL;
-               ts->clat_stat[1].min_val = -1UL;
-               ts->slat_stat[0].min_val = -1UL;
-               ts->slat_stat[1].min_val = -1UL;
-               ts->bw_stat[0].min_val = -1UL;
-               ts->bw_stat[1].min_val = -1UL;
+               for (j = 0; j <= DDIR_WRITE; j++) {
+                       ts->clat_stat[j].min_val = -1UL;
+                       ts->slat_stat[j].min_val = -1UL;
+                       ts->bw_stat[j].min_val = -1UL;
+               }
        }
 
        j = 0;
        last_ts = -1;
-       members = 0;
+       idx = 0;
        for_each_td(td, i) {
                ts = &threadstats[j];
 
-               members++;
+               idx++;
                ts->members++;
 
                if (!ts->groupid) {
@@ -697,12 +690,17 @@ void show_run_stats(void)
                        ts->verror = td->verror;
                }
 
-               sum_stat(ts->clat_stat, td->ts.clat_stat, members);
-               sum_stat(ts->slat_stat, td->ts.slat_stat, members);
-               sum_stat(ts->bw_stat, td->ts.bw_stat, members);
+               for (l = 0; l <= DDIR_WRITE; l++) {
+                       sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx);
+                       sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx);
+                       sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx);
+
+                       ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l];
+                       ts->io_bytes[l] += td->ts.io_bytes[l];
 
-               ts->stat_io_bytes[0] += td->ts.stat_io_bytes[0];
-               ts->stat_io_bytes[1] += td->ts.stat_io_bytes[1];
+                       if (ts->runtime[l] < td->ts.runtime[l])
+                               ts->runtime[l] = td->ts.runtime[l];
+               }
 
                ts->usr_time += td->ts.usr_time;
                ts->sys_time += td->ts.sys_time;
@@ -714,18 +712,11 @@ void show_run_stats(void)
                        ts->io_u_lat[k] += td->ts.io_u_lat[k];
 
                ts->total_io_u += td->ts.total_io_u;
-               ts->io_bytes[0] += td->ts.io_bytes[0];
-               ts->io_bytes[1] += td->ts.io_bytes[1];
-
-               if (ts->runtime[0] < td->ts.runtime[0])
-                       ts->runtime[0] = td->ts.runtime[0];
-               if (ts->runtime[1] < td->ts.runtime[1])
-                       ts->runtime[1] = td->ts.runtime[1];
 
                ts->total_run_time += td->ts.total_run_time;
 
                if (!td->group_reporting) {
-                       members = 0;
+                       idx = 0;
                        j++;
                        continue;
                }
@@ -733,7 +724,7 @@ void show_run_stats(void)
                        continue;
 
                if (last_ts != -1) {
-                       members = 0;
+                       idx = 0;
                        j++;
                }
 
@@ -741,37 +732,29 @@ void show_run_stats(void)
        }
 
        for (i = 0; i < nr_ts; i++) {
-               unsigned long long rbw, wbw;
+               unsigned long long bw;
 
                ts = &threadstats[i];
                rs = &runstats[ts->groupid];
 
-               if (ts->runtime[0] < rs->min_run[0] || !rs->min_run[0])
-                       rs->min_run[0] = ts->runtime[0];
-               if (ts->runtime[0] > rs->max_run[0])
-                       rs->max_run[0] = ts->runtime[0];
-               if (ts->runtime[1] < rs->min_run[1] || !rs->min_run[1])
-                       rs->min_run[1] = ts->runtime[1];
-               if (ts->runtime[1] > rs->max_run[1])
-                       rs->max_run[1] = ts->runtime[1];
-
-               rbw = wbw = 0;
-               if (ts->runtime[0])
-                       rbw = ts->io_bytes[0] / (unsigned long long) ts->runtime[0];
-               if (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;
-               if (wbw < rs->min_bw[1])
-                       rs->min_bw[1] = wbw;
-               if (rbw > rs->max_bw[0])
-                       rs->max_bw[0] = rbw;
-               if (wbw > rs->max_bw[1])
-                       rs->max_bw[1] = wbw;
-
-               rs->io_kb[0] += ts->io_bytes[0] >> 10;
-               rs->io_kb[1] += ts->io_bytes[1] >> 10;
+               for (j = 0; j <= DDIR_WRITE; j++) {
+                       if (!ts->runtime[j])
+                               continue;
+                       if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
+                               rs->min_run[j] = ts->runtime[j];
+                       if (ts->runtime[j] > rs->max_run[j])
+                               rs->max_run[j] = ts->runtime[j];
+
+                       bw = 0;
+                       if (ts->runtime[j])
+                               bw = ts->io_bytes[j] / (unsigned long long) ts->runtime[j];
+                       if (bw < rs->min_bw[j])
+                               rs->min_bw[j] = bw;
+                       if (bw > rs->max_bw[j])
+                               rs->max_bw[j] = bw;
+
+                       rs->io_kb[j] += ts->io_bytes[j] >> 10;
+               }
        }
 
        for (i = 0; i < groupid + 1; i++) {