From: Chris Mason Date: Mon, 27 Aug 2012 22:27:59 +0000 (-0400) Subject: iowatcher: Fix divide by zero while calculating averages X-Git-Tag: blktrace-1.1.0~2^2~46 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=f5f8c9820df3e7714b46e3b8f1cc1aa5d6af12e3;p=blktrace.git iowatcher: Fix divide by zero while calculating averages Signed-off-by: Chris Mason --- 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;