stat: fix potential divide-by-zero
authorJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 15:49:38 +0000 (09:49 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 14 Apr 2014 15:49:38 +0000 (09:49 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
stat.c

diff --git a/stat.c b/stat.c
index ca733108a879b772d45186a0600e8439f9f50433..1ef88ddf69884b083c229032c08fb9df8b6f63cb 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1803,7 +1803,11 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
                if (!delta)
                        continue; /* No entries for interval */
 
-               rate = delta * 1000 / spent / 1024;
+               if (spent)
+                       rate = delta * 1000 / spent / 1024;
+               else
+                       rate = 0;
+
                add_stat_sample(&ts->bw_stat[ddir], rate);
 
                if (td->bw_log)
@@ -1838,7 +1842,11 @@ void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs
                if (!delta)
                        continue; /* No entries for interval */
 
-               iops = (delta * 1000) / spent;
+               if (spent)
+                       iops = (delta * 1000) / spent;
+               else
+                       iops = 0;
+
                add_stat_sample(&ts->iops_stat[ddir], iops);
 
                if (td->iops_log)