Skip to content

Commit

Permalink
add comments and fix return when no gpu is found
Browse files Browse the repository at this point in the history
  • Loading branch information
HR05 committed Nov 14, 2024
1 parent a5bc588 commit 98d9956
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bitbots_misc/system_monitor/system_monitor/cpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down
9 changes: 7 additions & 2 deletions bitbots_misc/system_monitor/system_monitor/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion bitbots_msgs/msg/Workload.msg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98d9956

Please sign in to comment.