From 5daa4ebed724cb0223dac4a1386e068f59722dab Mon Sep 17 00:00:00 2001 From: Josh Carter Date: Mon, 20 Feb 2012 10:12:22 +0100 Subject: [PATCH 1/1] Fix bandwidth logging for mixed read/write workloads. 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 --- stat.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/stat.c b/stat.c index 7e3b9796..68744281 100644 --- 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; + + /* + * 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); - td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; } void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, -- 2.25.1