From f5f8c9820df3e7714b46e3b8f1cc1aa5d6af12e3 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Mon, 27 Aug 2012 18:27:59 -0400 Subject: [PATCH] iowatcher: Fix divide by zero while calculating averages Signed-off-by: Chris Mason --- iowatcher/main.c | 9 ++++++--- 1 file 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; -- 2.25.1