mirror of https://github.com/aristocratos/bpytop
Improvement on osx cpu temperature collection with coretemp
parent
80bbf2716d
commit
1df9ed9f55
53
bpytop.py
53
bpytop.py
|
@ -2555,10 +2555,10 @@ class CpuCollector(Collector):
|
||||||
cls.sensor_method = ""
|
cls.sensor_method = ""
|
||||||
if SYSTEM == "MacOS":
|
if SYSTEM == "MacOS":
|
||||||
try:
|
try:
|
||||||
if which("osx-cpu-temp") and subprocess.check_output("osx-cpu-temp", text=True).rstrip().endswith("°C"):
|
if which("coretemp") and subprocess.check_output(["coretemp", "-p"], text=True).strip().replace("-", "").isdigit():
|
||||||
|
cls.sensor_method = "coretemp"
|
||||||
|
elif which("osx-cpu-temp") and subprocess.check_output("osx-cpu-temp", text=True).rstrip().endswith("°C"):
|
||||||
cls.sensor_method = "osx-cpu-temp"
|
cls.sensor_method = "osx-cpu-temp"
|
||||||
if which("coretemp") and subprocess.check_output("coretemp", text=True).split()[0].strip().replace("-", "").isdigit():
|
|
||||||
cls.sensor_method += "+coretemp"
|
|
||||||
except: pass
|
except: pass
|
||||||
elif hasattr(psutil, "sensors_temperatures"):
|
elif hasattr(psutil, "sensors_temperatures"):
|
||||||
try:
|
try:
|
||||||
|
@ -2670,28 +2670,29 @@ class CpuCollector(Collector):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if cls.sensor_method.startswith("osx-cpu-temp") or cls.sensor_method.startswith("+coretemp"):
|
if cls.sensor_method == "coretemp":
|
||||||
if cls.sensor_method.startswith("+coretemp"):
|
temp = max(0, int(subprocess.check_output(["coretemp", "-p"], text=True).strip()))
|
||||||
temp = max(0, round(float(subprocess.check_output(["coretemp", "-c 0", "-r 3"], text=True).split()[0].strip())))
|
cores = [max(0, int(x)) for x in subprocess.check_output("coretemp", text=True).split()]
|
||||||
|
if len(cores) < THREADS:
|
||||||
|
cls.cpu_temp[0].append(temp)
|
||||||
|
for n, t in enumerate(cores, start=1):
|
||||||
|
try:
|
||||||
|
cls.cpu_temp[n].append(t)
|
||||||
|
cls.cpu_temp[THREADS // 2 + n].append(t)
|
||||||
|
except IndexError:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
temp = max(0, round(float(subprocess.check_output("osx-cpu-temp", text=True).strip()[:-2])))
|
cores.insert(0, temp)
|
||||||
if cls.sensor_method.endswith("+coretemp"):
|
for n, t in enumerate(cores):
|
||||||
cores = [max(0, round(float(x))) for x in subprocess.check_output(["coretemp", "-r 3"], text=True).split()]
|
try:
|
||||||
if len(cores) < THREADS:
|
cls.cpu_temp[n].append(t)
|
||||||
cls.cpu_temp[0].append(temp)
|
except IndexError:
|
||||||
for n, t in enumerate(cores, start=1):
|
break
|
||||||
try:
|
if not cls.cpu_temp_high:
|
||||||
cls.cpu_temp[n].append(t)
|
cls.cpu_temp_high = 85
|
||||||
cls.cpu_temp[THREADS // 2 + n].append(t)
|
cls.cpu_temp_crit = 100
|
||||||
except IndexError:
|
elif cls.sensor_method == "osx-cpu-temp":
|
||||||
break
|
temp = max(0, round(float(subprocess.check_output("osx-cpu-temp", text=True).strip()[:-2])))
|
||||||
else:
|
|
||||||
cores.insert(0, temp)
|
|
||||||
for n, t in enumerate(cores):
|
|
||||||
try:
|
|
||||||
cls.cpu_temp[n].append(t)
|
|
||||||
except IndexError:
|
|
||||||
break
|
|
||||||
if not cls.cpu_temp_high:
|
if not cls.cpu_temp_high:
|
||||||
cls.cpu_temp_high = 85
|
cls.cpu_temp_high = 85
|
||||||
cls.cpu_temp_crit = 100
|
cls.cpu_temp_crit = 100
|
||||||
|
@ -2703,7 +2704,6 @@ class CpuCollector(Collector):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errlog.exception(f'{e}')
|
errlog.exception(f'{e}')
|
||||||
cls.got_sensors = False
|
cls.got_sensors = False
|
||||||
#CONFIG.check_temp = False
|
|
||||||
CpuBox._calc_size()
|
CpuBox._calc_size()
|
||||||
else:
|
else:
|
||||||
if not cores:
|
if not cores:
|
||||||
|
@ -2714,9 +2714,6 @@ class CpuCollector(Collector):
|
||||||
for n in range(len(cls.cpu_temp)):
|
for n in range(len(cls.cpu_temp)):
|
||||||
del cls.cpu_temp[n][0]
|
del cls.cpu_temp[n][0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _draw(cls):
|
def _draw(cls):
|
||||||
CpuBox._draw_fg()
|
CpuBox._draw_fg()
|
||||||
|
|
Loading…
Reference in New Issue