Skip to content

Commit 3c6494f

Browse files
committed
Reformat code, fix CPU clock (use max of core clocks, ignore effective clocks)
1 parent a074cb9 commit 3c6494f

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

external/LibreHardwareMonitor/test_librehardwaremonitor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Use this file to display all hardware & sensors available from LibreHardwareMonitor on your computer
22
# Windows only - needs administrative rights
33
import ctypes
4-
import sys
5-
import clr
64
import os
5+
import sys
6+
7+
import clr # Clr is from pythonnet package. Do not install clr package
78
from win32api import *
89

910
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
@@ -32,8 +33,8 @@
3233
ms_file_version = File_information['FileVersionMS']
3334
ls_file_version = File_information['FileVersionLS']
3435
print("Found HidSharp %s" % ".".join([str(HIWORD(ms_file_version)), str(LOWORD(ms_file_version)),
35-
str(HIWORD(ls_file_version)),
36-
str(LOWORD(ls_file_version))]))
36+
str(HIWORD(ls_file_version)),
37+
str(LOWORD(ls_file_version))]))
3738

3839
handle = Hardware.Computer()
3940
handle.IsCpuEnabled = True

library/sensors/sensors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file defines all supported hardware in virtual classes and their abstract methods to access sensors
2+
# To be overriden by child sensors classes
3+
14
from abc import ABC, abstractmethod
25
from typing import Tuple
36

@@ -83,5 +86,6 @@ def disk_free() -> int: # In bytes
8386
class Net(ABC):
8487
@staticmethod
8588
@abstractmethod
86-
def stats(if_name, interval) -> Tuple[int, int, int, int]: # up rate (B/s), uploaded (B), dl rate (B/s), downloaded (B)
89+
def stats(if_name, interval) -> Tuple[
90+
int, int, int, int]: # up rate (B/s), uploaded (B), dl rate (B/s), downloaded (B)
8791
pass

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import clr # from pythonnet package, not clr package !
1+
# This file will use LibreHardwareMonitor.dll library to get hardware sensors
2+
# Some metrics are still fetched by psutil when not available on LibreHardwareMonitor
3+
# For Windows platforms only
4+
25
import ctypes
36
import math
47
import os
58
import sys
69
from typing import Tuple
7-
from statistics import mean
8-
from win32api import *
910

11+
import clr # Clr is from pythonnet package. Do not install clr package
1012
import psutil
13+
from win32api import *
1114

1215
import library.sensors.sensors as sensors
1316
from library.log import logger
@@ -99,9 +102,12 @@ def frequency() -> float:
99102
frequencies = []
100103
cpu = get_hw_and_update(Hardware.HardwareType.Cpu)
101104
for sensor in cpu.Sensors:
102-
if sensor.SensorType == Hardware.SensorType.Clock and "Core #" in str(sensor.Name):
103-
frequencies.append(float(sensor.Value))
104-
return mean(frequencies)
105+
if sensor.SensorType == Hardware.SensorType.Clock:
106+
# Keep only real core clocks, ignore effective core clocks
107+
if "Core #" in str(sensor.Name) and "Effective" not in str(sensor.Name):
108+
frequencies.append(float(sensor.Value))
109+
# Take the highest core clock as "CPU clock"
110+
return max(frequencies)
105111

106112
@staticmethod
107113
def load() -> Tuple[float, float, float]: # 1 / 5 / 15min avg:

library/sensors/sensors_python.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file will use Python libraries (psutil, GPUtil, etc.) to get hardware sensors
2+
# For all platforms (Linux, Windows, macOS) but not all HW is supported
3+
14
import math
25
from typing import Tuple
36
from enum import IntEnum, auto

library/sensors/sensors_stub.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from typing import Tuple
1+
# This file will use randomly generated data instead of real hardware sensors
2+
# For all platforms (Linux, Windows, macOS)
3+
24
import random
5+
from typing import Tuple
36

47
import library.sensors.sensors as sensors
58

library/stats.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ def temperature():
176176
THEME_DATA['STATS']['CPU']['TEMPERATURE']['TEXT'].get("BACKGROUND_IMAGE",
177177
None))
178178
)
179-
# TODO: Built in function for *nix in psutil, for Windows can use WMI or a third party library
180179

181180

182181
def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):

0 commit comments

Comments
 (0)