From 0f53567f3172e5d0e96e14776fcc71e42097d9b5 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 20 Oct 2019 10:07:44 +0200 Subject: [PATCH] [modules/sensors(2)] Better (?) CPU reading Add support for ARM/PowerPC (BogoMIPS) and make sure that the module doesn't throw errors when problems reading the CPU frequency occurs. fixes #458 --- bumblebee/modules/sensors.py | 10 +++++++++- bumblebee/modules/sensors2.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/sensors.py b/bumblebee/modules/sensors.py index 92f3feb..567d9db 100644 --- a/bumblebee/modules/sensors.py +++ b/bumblebee/modules/sensors.py @@ -93,13 +93,21 @@ class Module(bumblebee.engine.Module): return temperature def get_mhz(self): + mhz = None try: output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() mhz = int(float(output)/1000.0) except: output = open("/proc/cpuinfo").read() m = re.search(r"cpu MHz\s+:\s+(\d+)", output) - mhz = int(m.group(1)) + if m: + mhz = int(m.group(1)) + else: + m = re.search(r"BogoMIPS\s+:\s+(\d+)", output) + if m: + return "{} BogoMIPS".format(int(m.group(1))) + if not mhz: + return "n/a" if mhz < 1000: return "{} MHz".format(mhz) diff --git a/bumblebee/modules/sensors2.py b/bumblebee/modules/sensors2.py index eee997f..3bd245a 100644 --- a/bumblebee/modules/sensors2.py +++ b/bumblebee/modules/sensors2.py @@ -132,18 +132,25 @@ class Module(bumblebee.engine.Module): return output def _cpu(self, _): + mhz = None try: output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() mhz = int(float(output)/1000.0) except: output = open("/proc/cpuinfo").read() m = re.search(r"cpu MHz\s+:\s+(\d+)", output) - mhz = int(m.group(1)) + if m: + mhz = int(m.group(1)) + else: + m = re.search(r"BogoMIPS\s+:\s+(\d+)", output) + if m: + return "{} BogoMIPS".format(int(m.group(1))) + if not mhz: + return "n/a" if mhz < 1000: return "{} MHz".format(mhz) else: return "{:0.01f} GHz".format(float(mhz)/1000.0) - # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4