Fix bandwidth logging for mixed read/write workloads.
authorJosh Carter <public@joshcarter.com>
Mon, 20 Feb 2012 09:12:22 +0000 (10:12 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 20 Feb 2012 09:12:22 +0000 (10:12 +0100)
fio was maintaining separate read/write stats, but only one timer for
bw_avg_time. Whichever IO direction happened to cross the timer would
get its interval logged; the other data direction would not. Now both
ddir are logged each time we cross bw_avg_time.

Where intervals don't contain any activity in a given ddir, no log
entry is made.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
stat.c

diff --git a/stat.c b/stat.c
index 7e3b97966c0b7754cdb10333ffa341a0adf26a5e..68744281a92de519cbb1f350fb459dfcca517cfd 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1291,16 +1291,27 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
        spent = mtime_since(&td->bw_sample_time, t);
        if (spent < td->o.bw_avg_time)
                return;
        spent = mtime_since(&td->bw_sample_time, t);
        if (spent < td->o.bw_avg_time)
                return;
+       
+       /* 
+        * Compute both read and write rates for the interval.
+        */
+       for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) {
+               uint64_t delta;
+
+               delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
+               if (!delta)
+                       continue; /* No entries for interval */
 
 
-       rate = (td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]) *
-                       1000 / spent / 1024;
-       add_stat_sample(&ts->bw_stat[ddir], rate);
+               rate = delta * 1000 / spent / 1024;
+               add_stat_sample(&ts->bw_stat[ddir], rate);
 
 
-       if (td->bw_log)
-               add_log_sample(td, td->bw_log, rate, ddir, bs);
+               if (td->bw_log)
+                       add_log_sample(td, td->bw_log, rate, ddir, bs);
+
+               td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
+       }
 
        fio_gettime(&td->bw_sample_time, NULL);
 
        fio_gettime(&td->bw_sample_time, NULL);
-       td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
 }
 
 void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
 }
 
 void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,