From 0595788f54ade32e58b897d4292d865fd805b972 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Feb 2024 12:10:25 +0100 Subject: [PATCH] Fix showing partial cpu stats Signed-off-by: falkTX --- html/js/host.js | 4 ++++ mod/host.py | 13 ++++++++----- mod/webserver.py | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/html/js/host.js b/html/js/host.js index 66ebd76b..c377e435 100644 --- a/html/js/host.js +++ b/html/js/host.js @@ -119,6 +119,10 @@ $('document').ready(function() { $("#mod-cpu-stats").html(sprintf("%.1f GHz / %d °C", parseInt(cpufreq)/1000000, parseInt(cputemp)/1000)) + } else if (cpufreq !== "0") { + $("#mod-cpu-stats").html(sprintf("%.1f GHz", parseInt(cpufreq)/1000000)) + } else if (cputemp !== "0") { + $("#mod-cpu-stats").html(sprintf("%d °C", parseInt(cputemp)/1000)) } return } diff --git a/mod/host.py b/mod/host.py index ed70a140..f252d293 100644 --- a/mod/host.py +++ b/mod/host.py @@ -4774,11 +4774,14 @@ def get_free_memory_value(self): def get_system_stats_message(self): memload = self.get_free_memory_value() cpufreq = read_file_contents(self.cpufreqfile, "0") - try: - cputemp = read_file_contents(self.thermalfile, "0") - except OSError: - cputemp = "0" - self.thermalfile = None + cputemp = "0" + + if self.thermalfile is not None: + try: + cputemp = read_file_contents(self.thermalfile, "0") + except OSError: + self.thermalfile = None + return "sys_stats %s %s %s" % (memload, cpufreq, cputemp) def memtimer_callback(self): diff --git a/mod/webserver.py b/mod/webserver.py index 27cc4928..f61be889 100644 --- a/mod/webserver.py +++ b/mod/webserver.py @@ -1977,11 +1977,14 @@ def post(self): index = freqs.index(cur_freq) + 1 if index >= len(freqs): index = 0 + next_freq = freqs[index] + if cur_freq == next_freq: + return self.write(True) with open("/sys/devices/system/cpu/online", 'r') as fh: num_start, num_end = tuple(int(i) for i in fh.read().strip().split("-")) for num in range(num_start, num_end+1): with open("/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed" % num, 'w') as fh: - fh.write(freqs[index]) + fh.write(next_freq) self.write(True) class SaveSingleConfigValue(JsonRequestHandler):