From 98d99566bb64ce3c1198340a08f90d0975ceba53 Mon Sep 17 00:00:00 2001 From: Hannes Richardt Date: Thu, 14 Nov 2024 19:38:26 +0100 Subject: [PATCH] add comments and fix return when no gpu is found --- bitbots_misc/system_monitor/system_monitor/cpus.py | 5 +++-- bitbots_misc/system_monitor/system_monitor/gpu.py | 9 +++++++-- bitbots_msgs/msg/Workload.msg | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bitbots_misc/system_monitor/system_monitor/cpus.py b/bitbots_misc/system_monitor/system_monitor/cpus.py index 391a3a2b0..cb933e686 100644 --- a/bitbots_misc/system_monitor/system_monitor/cpus.py +++ b/bitbots_misc/system_monitor/system_monitor/cpus.py @@ -36,7 +36,8 @@ def collect_all(): def _get_cpu_stats(): """ read and parse /proc/stat - :returns timings which contains accumulative busy and total cpu time + + :returns: timings which contains accumulative busy and total cpu time """ timings = {} with open("/proc/stat") as file_obj: @@ -51,7 +52,7 @@ def _get_cpu_stats(): def _calculate_usage(cpu_num, total, busy): """ - calculate usage percentage based on busy/total time + calculate usage percentage based on busy/total time(load, vram_used, vram_total, temperature) """ diff_total = total - _prev_total[cpu_num] diff_busy = busy - _prev_busy[cpu_num] diff --git a/bitbots_misc/system_monitor/system_monitor/gpu.py b/bitbots_misc/system_monitor/system_monitor/gpu.py index 64ea77e3e..2f440c031 100644 --- a/bitbots_misc/system_monitor/system_monitor/gpu.py +++ b/bitbots_misc/system_monitor/system_monitor/gpu.py @@ -2,13 +2,18 @@ def collect_all(): + """ + use pyamdgpuinfo to get gpu metrics + + :return: (load, vram_used, vram_total, temperature) + """ if pyamdgpuinfo.detect_gpus() == 0: - return 0 + return (0, 0, 0, 0) gpu = pyamdgpuinfo.get_gpu(0) load = gpu.query_load() vram_total = gpu.memory_info["vram_size"] vram_used = gpu.query_vram_usage() - temperature = int(gpu.query_temperature()) + temperature = gpu.query_temperature() return (load, vram_used, vram_total, temperature) diff --git a/bitbots_msgs/msg/Workload.msg b/bitbots_msgs/msg/Workload.msg index 0dffaea0f..cdde1e0bf 100644 --- a/bitbots_msgs/msg/Workload.msg +++ b/bitbots_msgs/msg/Workload.msg @@ -7,7 +7,7 @@ float32 cpu_usage_overall float32 gpu_load int64 gpu_vram_used int64 gpu_vram_total -int32 gpu_temperature +float32 gpu_temperature int64 memory_available int64 memory_used