Skip to content

Commit 2ab027b

Browse files
authored
Merge pull request #333 from mathoudebine/feature/add-fps-meter
2 parents 22f0c42 + dbc5c35 commit 2ab027b

File tree

8 files changed

+85
-3
lines changed

8 files changed

+85
-3
lines changed

library/sensors/sensors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Gpu(ABC):
5656
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
5757
pass
5858

59+
@staticmethod
60+
@abstractmethod
61+
def fps() -> int:
62+
pass
63+
5964
@staticmethod
6065
@abstractmethod
6166
def is_available() -> bool:

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ class Gpu(sensors.Gpu):
241241
# GPU to use is detected once, and its name is saved for future sensors readings
242242
gpu_name = ""
243243

244+
# Latest FPS value is backed up in case next reading returns no value
245+
prev_fps = 0
246+
244247
@classmethod
245248
def stats(cls) -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
246249
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuAmd, cls.gpu_name)
@@ -274,6 +277,27 @@ def stats(cls) -> Tuple[float, float, float, float]: # load (%) / used mem (%)
274277

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

280+
@classmethod
281+
def fps(cls) -> int:
282+
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuAmd, cls.gpu_name)
283+
if gpu_to_use is None:
284+
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuNvidia, cls.gpu_name)
285+
if gpu_to_use is None:
286+
gpu_to_use = get_hw_and_update(Hardware.HardwareType.GpuIntel, cls.gpu_name)
287+
if gpu_to_use is None:
288+
# GPU not supported
289+
return -1
290+
291+
for sensor in gpu_to_use.Sensors:
292+
if sensor.SensorType == Hardware.SensorType.Factor and "FPS" in str(sensor.Name):
293+
# If a reading returns a value <= 0, returns old value instead
294+
if int(sensor.Value) > 0:
295+
cls.prev_fps = int(sensor.Value)
296+
return cls.prev_fps
297+
298+
# No FPS sensor for this GPU model
299+
return -1
300+
277301
@classmethod
278302
def is_available(cls) -> bool:
279303
cls.gpu_name = get_gpu_name()

library/sensors/sensors_python.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
112112
else:
113113
return math.nan, math.nan, math.nan, math.nan
114114

115+
@staticmethod
116+
def fps() -> int:
117+
# Not supported by Python libraries
118+
return -1
119+
115120
@staticmethod
116121
def is_available() -> bool:
117122
global DETECTED_GPU
@@ -164,6 +169,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
164169

165170
return load, memory_percentage, memory_used_mb, temperature
166171

172+
@staticmethod
173+
def fps() -> int:
174+
# Not supported by Python libraries
175+
return -1
176+
167177
@staticmethod
168178
def is_available() -> bool:
169179
try:
@@ -229,6 +239,11 @@ def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / u
229239
# Memory absolute (M) and relative (%) usage not supported by pyadl
230240
return load, math.nan, math.nan, temperature
231241

242+
@staticmethod
243+
def fps() -> int:
244+
# Not supported by Python libraries
245+
return -1
246+
232247
@staticmethod
233248
def is_available() -> bool:
234249
try:

library/sensors/sensors_stub_random.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class Gpu(sensors.Gpu):
5252
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
5353
return random.uniform(0, 100), random.uniform(0, 100), random.uniform(300, 16000), random.uniform(30, 90)
5454

55+
@staticmethod
56+
def fps() -> int:
57+
return random.randint(20, 120)
58+
5559
@staticmethod
5660
def is_available() -> bool:
5761
return True

library/sensors/sensors_stub_static.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
MEMORY_TOTAL_SIZE_GB = 64
3535
GPU_MEM_TOTAL_SIZE_GB = 32
3636
NETWORK_SPEED_BYTES = 1061000000
37+
GPU_FPS = 120
3738

3839

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

68+
@staticmethod
69+
def fps() -> int:
70+
return GPU_FPS
71+
6772
@staticmethod
6873
def is_available() -> bool:
6974
return True

library/stats.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ def temperature():
223223
)
224224

225225

226-
def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
226+
def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature, fps):
227227
theme_gpu_data = config.THEME_DATA['STATS']['GPU']
228+
228229
gpu_percent_graph_data = theme_gpu_data['PERCENTAGE']['GRAPH']
229230
gpu_percent_radial_data = theme_gpu_data['PERCENTAGE']['RADIAL']
230231
gpu_percent_text_data = theme_gpu_data['PERCENTAGE']['TEXT']
231-
232232
if math.isnan(load):
233233
load = 0
234234
if gpu_percent_graph_data['SHOW'] or gpu_percent_text_data['SHOW'] or gpu_percent_radial_data['SHOW']:
@@ -260,6 +260,12 @@ def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
260260
logger.warning("Your GPU temperature is not supported yet")
261261
gpu_temp_text_data['SHOW'] = False
262262

263+
gpu_fps_text_data = theme_gpu_data['FPS']['TEXT']
264+
if fps < 0:
265+
if gpu_fps_text_data['SHOW']:
266+
logger.warning("Your GPU FPS is not supported yet")
267+
gpu_fps_text_data['SHOW'] = False
268+
263269
# logger.debug(f"GPU Load: {load}")
264270
display_themed_progress_bar(gpu_percent_graph_data, load)
265271

@@ -299,12 +305,20 @@ def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
299305
unit="°C"
300306
)
301307

308+
display_themed_value(
309+
theme_data=gpu_fps_text_data,
310+
value=int(fps),
311+
min_size=4,
312+
unit=" FPS"
313+
)
314+
302315

303316
class Gpu:
304317
@staticmethod
305318
def stats():
306319
load, memory_percentage, memory_used_mb, temperature = sensors.Gpu.stats()
307-
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature)
320+
fps = sensors.Gpu.fps()
321+
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature, fps)
308322

309323
@staticmethod
310324
def is_available():

res/themes/default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ STATS:
5050
TEXT:
5151
SHOW: False
5252
SHOW_UNIT: False
53+
FPS:
54+
TEXT:
55+
SHOW: False
56+
SHOW_UNIT: False
5357
MEMORY:
5458
INTERVAL: 5
5559
SWAP:

res/themes/theme_example.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ STATS:
273273
FONT_COLOR: 200, 200, 200
274274
# BACKGROUND_COLOR: 50, 50, 50
275275
BACKGROUND_IMAGE: background.png
276+
FPS:
277+
TEXT:
278+
SHOW: False
279+
SHOW_UNIT: True
280+
X: 115
281+
Y: 231
282+
FONT: roboto/Roboto-Bold.ttf
283+
FONT_SIZE: 13
284+
FONT_COLOR: 200, 200, 200
285+
# BACKGROUND_COLOR: 50, 50, 50
286+
BACKGROUND_IMAGE: background.png
276287
MEMORY:
277288
# In seconds. Longer intervals cause this to refresh more slowly.
278289
# Setting to lower values will display near real time data,

0 commit comments

Comments
 (0)