summaryrefslogtreecommitdiffstats
path: root/python.d
diff options
context:
space:
mode:
authorSteven Noonan <steven@uplinklabs.net>2017-09-09 08:54:53 -0700
committerSteven Noonan <steven@uplinklabs.net>2017-09-09 08:54:53 -0700
commit865aedf6bfd26d96b887c92be68bcbadc2a0f7eb (patch)
tree90b0637a1c912f664d358722630a83b73cf941a2 /python.d
parent61dbe88ef1b1d8d927c6eb13bd00046113841cd2 (diff)
cpufreq.chart.py: use much more accurate accounting for average CPU frequency
The way I was tracking it before was bad because if we were too early or late reading the time_in_state file, we might get really bogus results. Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Diffstat (limited to 'python.d')
-rw-r--r--python.d/cpufreq.chart.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/python.d/cpufreq.chart.py b/python.d/cpufreq.chart.py
index 87f71f5748..01cc22b027 100644
--- a/python.d/cpufreq.chart.py
+++ b/python.d/cpufreq.chart.py
@@ -38,20 +38,31 @@ class Service(SimpleService):
data = {}
if self.accurate_exists:
- elapsed = time.time() - self.timetable['last']
-
accurate_ok = True
for name, paths in self.assignment.items():
last = self.accurate_last[name]
- current = 0
+
+ current = {}
+ deltas = {}
+ ticks_since_last = 0
+
for line in open(paths['accurate'], 'r'):
line = list(map(int, line.split()))
- current += (line[0] * line[1]) / 100
- delta = current - last
- data[name] = delta
+ current[line[0]] = line[1]
+ ticks = line[1] - last.get(line[0], 0)
+ ticks_since_last += ticks
+ deltas[line[0]] = line[1] - last.get(line[0], 0)
+
+ avg_freq = 0
+ if ticks_since_last != 0:
+ for frequency, ticks in deltas.items():
+ avg_freq += frequency * ticks
+ avg_freq /= ticks_since_last
+
+ data[name] = avg_freq
self.accurate_last[name] = current
- if delta == 0 or abs(delta) > 1e7:
+ if avg_freq == 0 or ticks_since_last == 0:
# Delta is either too large or nonexistent, fall back to
# less accurate reading. This can happen if we switch
# to/from the 'schedutil' governor, which doesn't report
@@ -81,7 +92,7 @@ class Service(SimpleService):
if cpu not in self.assignment:
self.assignment[cpu] = {}
self.assignment[cpu]['accurate'] = path
- self.accurate_last[cpu] = 0
+ self.accurate_last[cpu] = {}
if len(self.assignment) == 0:
self.accurate_exists = False