diff --git a/frigate/test/test_gpu_stats.py b/frigate/test/test_gpu_stats.py new file mode 100644 index 000000000..1ff4e122c --- /dev/null +++ b/frigate/test/test_gpu_stats.py @@ -0,0 +1,21 @@ +import unittest +from unittest.mock import MagicMock, patch + +from frigate.util import get_amd_gpu_stats + + +class TestGpuStats(unittest.TestCase): + + def setUp(self): + self.nvidia_results = "name, utilization.gpu [%], utilization.memory [%]\nNVIDIA GeForce RTX 3050, 41 %, 1 %\n" + self.amd_results = "Unknown Radeon card. <= R500 won't work, new cards might.\nDumping to -, line limit 1.\n1664070990.607556: bus 10, gpu 4.17%, ee 0.00%, vgt 0.00%, ta 0.00%, tc 0.00%, sx 0.00%, sh 0.00%, spi 0.83%, smx 0.00%, cr 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 60.37% 294.04mb, gtt 0.33% 52.21mb, mclk 100.00% 1.800ghz, sclk 26.65% 0.533ghz\n" + + @patch("subprocess.run") + def test_amd_gpu_stats(self, sp): + process = MagicMock() + process.returncode = 0 + process.stdout = self.amd_results + sp.return_value = process + amd_stats = get_amd_gpu_stats() + print(amd_stats) + pass \ No newline at end of file diff --git a/frigate/util.py b/frigate/util.py index 96316eb84..bb95d44e5 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -800,9 +800,9 @@ def get_amd_gpu_stats() -> dict[str, str]: for hw in usages: if "gpu" in hw: - results["gpu_usage"] = f"{hw.strip().split(' ')[1].split(' ')[0]} %" + results["gpu_usage"] = f"{hw.strip().split(' ')[1].replace('%', '')} %" elif "vram" in hw: - results["memory_usage"] = f"{hw.strip().split(' ')[1].split(' ')[0]} %" + results["memory_usage"] = f"{hw.strip().split(' ')[1].replace('%', '')} %" return results @@ -826,9 +826,9 @@ def get_intel_gpu_stats() -> dict[str, str]: for hw in usages: if "gpu" in hw: - results["gpu_usage"] = f"{hw.strip().split(' ')[1].replace('%', '')} %" + results["gpu_usage"] = f"{hw.strip().split(' ')[1].split(' ')[0]} %" elif "vram" in hw: - results["memory_usage"] = f"{hw.strip().split(' ')[1].replace('%', '')} %" + results["memory_usage"] = f"{hw.strip().split(' ')[1].split(' ')[0]} %" return results