diff options
author | Chris Mason <chris.mason@fusionio.com> | 2012-08-27 18:27:59 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2012-08-27 18:27:59 -0400 |
commit | f5f8c9820df3e7714b46e3b8f1cc1aa5d6af12e3 (patch) | |
tree | c673321bd7908604b7a79c4f763bfb99d7b97dfb | |
parent | 5122a20d002a5197b8e5789934620d7ad1ece27c (diff) | |
download | blktrace-f5f8c9820df3e7714b46e3b8f1cc1aa5d6af12e3.tar.gz |
iowatcher: Fix divide by zero while calculating averages
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r-- | iowatcher/main.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/iowatcher/main.c b/iowatcher/main.c index f2945fa..38f28bd 100644 --- a/iowatcher/main.c +++ b/iowatcher/main.c @@ -669,9 +669,12 @@ static int __plot_cpu(struct plot *plot, int seconds, char *label, struct graph_line_data *gld = tf->mpstat_gld[i * MPSTAT_GRAPHS + gld_index]; double this_avg = 0; - for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) - this_avg += gld->data[i].sum / - gld->data[i].count;; + for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) { + if (gld->data[i].count) { + this_avg += gld->data[i].sum / + gld->data[i].count; + } + } this_avg /= gld->stop_seconds; |