Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions library/sensors/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Gpu(ABC):
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
pass

@staticmethod
@abstractmethod
def fps() -> int:
pass

@staticmethod
@abstractmethod
def is_available() -> bool:
Expand Down
24 changes: 24 additions & 0 deletions library/sensors/sensors_librehardwaremonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ class Gpu(sensors.Gpu):
# GPU to use is detected once, and its name is saved for future sensors readings
gpu_name = ""

# Latest FPS value is backed up in case next reading returns no value
prev_fps = 0

@classmethod
def stats(cls) -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuAmd, cls.gpu_name)
Expand Down Expand Up @@ -274,6 +277,27 @@ def stats(cls) -> Tuple[float, float, float, float]: # load (%) / used mem (%)

return load, (used_mem / total_mem * 100.0), used_mem, temp

@classmethod
def fps(cls) -> int:
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuAmd, cls.gpu_name)
if gpu_to_use is None:
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuNvidia, cls.gpu_name)
if gpu_to_use is None:
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuIntel, cls.gpu_name)
if gpu_to_use is None:
# GPU not supported
return -1

for sensor in gpu_to_use.Sensors:
if sensor.SensorType == Hardware.SensorType.Factor and "FPS" in str(sensor.Name):
# If a reading returns a value <= 0, returns old value instead
if int(sensor.Value) > 0:
cls.prev_fps = int(sensor.Value)
return cls.prev_fps

# No FPS sensor for this GPU model
return -1

@classmethod
def is_available(cls) -> bool:
cls.gpu_name = get_gpu_name()
Expand Down
15 changes: 15 additions & 0 deletions library/sensors/sensors_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
else:
return math.nan, math.nan, math.nan, math.nan

@staticmethod
def fps() -> int:
# Not supported by Python libraries
return -1

@staticmethod
def is_available() -> bool:
global DETECTED_GPU
Expand Down Expand Up @@ -164,6 +169,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u

return load, memory_percentage, memory_used_mb, temperature

@staticmethod
def fps() -> int:
# Not supported by Python libraries
return -1

@staticmethod
def is_available() -> bool:
try:
Expand Down Expand Up @@ -229,6 +239,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
# Memory absolute (M) and relative (%) usage not supported by pyadl
return load, math.nan, math.nan, temperature

@staticmethod
def fps() -> int:
# Not supported by Python libraries
return -1

@staticmethod
def is_available() -> bool:
try:
Expand Down
4 changes: 4 additions & 0 deletions library/sensors/sensors_stub_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Gpu(sensors.Gpu):
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
return random.uniform(0, 100), random.uniform(0, 100), random.uniform(300, 16000), random.uniform(30, 90)

@staticmethod
def fps() -> int:
return random.randint(20, 120)

@staticmethod
def is_available() -> bool:
return True
Expand Down
5 changes: 5 additions & 0 deletions library/sensors/sensors_stub_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
MEMORY_TOTAL_SIZE_GB = 64
GPU_MEM_TOTAL_SIZE_GB = 32
NETWORK_SPEED_BYTES = 1061000000
GPU_FPS = 120


class Cpu(sensors.Cpu):
Expand Down Expand Up @@ -64,6 +65,10 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
return PERCENTAGE_SENSOR_VALUE, PERCENTAGE_SENSOR_VALUE, \
GPU_MEM_TOTAL_SIZE_GB / 100 * PERCENTAGE_SENSOR_VALUE * 1000, TEMPERATURE_SENSOR_VALUE

@staticmethod
def fps() -> int:
return GPU_FPS

@staticmethod
def is_available() -> bool:
return True
Expand Down
20 changes: 17 additions & 3 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ def temperature():
)


def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature, fps):
theme_gpu_data = config.THEME_DATA['STATS']['GPU']

gpu_percent_graph_data = theme_gpu_data['PERCENTAGE']['GRAPH']
gpu_percent_radial_data = theme_gpu_data['PERCENTAGE']['RADIAL']
gpu_percent_text_data = theme_gpu_data['PERCENTAGE']['TEXT']

if math.isnan(load):
load = 0
if gpu_percent_graph_data['SHOW'] or gpu_percent_text_data['SHOW'] or gpu_percent_radial_data['SHOW']:
Expand Down Expand Up @@ -260,6 +260,12 @@ def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
logger.warning("Your GPU temperature is not supported yet")
gpu_temp_text_data['SHOW'] = False

gpu_fps_text_data = theme_gpu_data['FPS']['TEXT']
if fps < 0:
if gpu_fps_text_data['SHOW']:
logger.warning("Your GPU FPS is not supported yet")
gpu_fps_text_data['SHOW'] = False

# logger.debug(f"GPU Load: {load}")
display_themed_progress_bar(gpu_percent_graph_data, load)

Expand Down Expand Up @@ -299,12 +305,20 @@ def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
unit="°C"
)

display_themed_value(
theme_data=gpu_fps_text_data,
value=int(fps),
min_size=4,
unit=" FPS"
)


class Gpu:
@staticmethod
def stats():
load, memory_percentage, memory_used_mb, temperature = sensors.Gpu.stats()
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature)
fps = sensors.Gpu.fps()
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature, fps)

@staticmethod
def is_available():
Expand Down
4 changes: 4 additions & 0 deletions res/themes/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ STATS:
TEXT:
SHOW: False
SHOW_UNIT: False
FPS:
TEXT:
SHOW: False
SHOW_UNIT: False
MEMORY:
INTERVAL: 5
SWAP:
Expand Down
11 changes: 11 additions & 0 deletions res/themes/theme_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ STATS:
FONT_COLOR: 200, 200, 200
# BACKGROUND_COLOR: 50, 50, 50
BACKGROUND_IMAGE: background.png
FPS:
TEXT:
SHOW: False
SHOW_UNIT: True
X: 115
Y: 231
FONT: roboto/Roboto-Bold.ttf
FONT_SIZE: 13
FONT_COLOR: 200, 200, 200
# BACKGROUND_COLOR: 50, 50, 50
BACKGROUND_IMAGE: background.png
MEMORY:
# In seconds. Longer intervals cause this to refresh more slowly.
# Setting to lower values will display near real time data,
Expand Down