From 92c3b2ed5f8e49737e29b11244585960a3478494 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Sun, 28 Oct 2018 00:02:22 +0700 Subject: [PATCH] cpufreq plugin: Limit reported value of percent to 100.1 cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state \ ; sleep 10 ; cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state 2664000 463368 1998000 59724070 2664000 463385 1998000 59725054 The sum of counters change is 1001, which produces reported value near to 100.1%. I got calculated ds[0] = 100.100053 and such value produces gap on charts. Added limit to avoid such. --- src/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cpufreq.c b/src/cpufreq.c index 3e3244cc..a81cf462 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -172,6 +172,12 @@ static void cpufreq_read_stats(int cpu) { gauge_t g; if (value_to_rate(&g, (value_t){.derive = time}, DS_TYPE_DERIVE, now, &(cpu_data[cpu].time_state[state_index])) == 0) { + /* + * Due to some inaccuracy reported value can be a bit greatrer than 100.1. + * That produces gaps on charts. + */ + if (g > 100.1) + g = 100.1; cpufreq_submit(cpu, "percent", state, &(value_t){.gauge = g}); } state_index++; -- 2.11.0