From 61c0dfaf60d78641fcce8c49e80bbed098f98559 Mon Sep 17 00:00:00 2001 From: bunder2015 Date: Fri, 19 Jan 2018 09:01:49 -0500 Subject: [PATCH] Fix issue #307 - High bars in cpugraph (#429) Authored-by: kira78 Signed-off-by: bunder2015 --- src/linux.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/linux.cc b/src/linux.cc index 664ddf5e..d710a824 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -847,6 +847,7 @@ int update_stat(void) static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER; static double last_stat_update = 0.0; + float cur_total = 0.0; /* since we use wrappers for this function, the update machinery * can't eliminate double invocations of this function. Check for @@ -920,9 +921,13 @@ int update_stat(void) break; } - cpu[idx].cpu_val[0] = (cpu[idx].cpu_active_total - - cpu[idx].cpu_last_active_total) / - (float) (cpu[idx].cpu_total - cpu[idx].cpu_last_total); + cur_total = (float) (cpu[idx].cpu_total - cpu[idx].cpu_last_total); + if (cur_total == 0.0) { + cpu[idx].cpu_val[0] = 1.0; + } else { + cpu[idx].cpu_val[0] = (cpu[idx].cpu_active_total - + cpu[idx].cpu_last_active_total) / cur_total; + } curtmp = 0; int samples = cpu_avg_samples.get(*state);