From 497ebf63f2f44d956c7916c565919e1c04ccecf2 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sat, 24 Sep 2022 17:57:11 -0600 Subject: [PATCH] Add util to get radeontop results --- frigate/util.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/frigate/util.py b/frigate/util.py index 9f7f419bf..287d32008 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -734,6 +734,37 @@ def escape_special_characters(path: str) -> str: # path does not have user:pass return path +def get_amd_gpu_stats() -> dict[str, str]: + """Get stats using radeontop.""" + radeontop_command = [ + "radeontop", + "-d", + "-", + "-l", + "1" + ] + + p = sp.run( + radeontop_command, + encoding="ascii", + capture_output=True, + ) + + if p.returncode != 0: + logger.error(p.stderr) + return None + else: + usages = p.stdout.split(",") + results: dict[str, str] = {} + + for hw in usages: + if "gpu" in hw: + results["gpu_usage"] = hw.strip().split(" ")[1] + elif "vram" in hw: + results["gpu_usage"] = hw.strip().split(" ")[1] + + return results + def get_cpu_stats() -> dict[str, dict]: """Get cpu usages for each process id"""