mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-26 19:06:11 +01:00
Fix intel gpu stats (#4581)
* Fix return code for timeout call * Rewrit intel gpu logic * Fix test and output
This commit is contained in:
parent
94a2b6bb88
commit
007fa75294
@ -35,11 +35,11 @@ class TestGpuStats(unittest.TestCase):
|
|||||||
@patch("subprocess.run")
|
@patch("subprocess.run")
|
||||||
def test_intel_gpu_stats(self, sp):
|
def test_intel_gpu_stats(self, sp):
|
||||||
process = MagicMock()
|
process = MagicMock()
|
||||||
process.returncode = 0
|
process.returncode = 124
|
||||||
process.stdout = self.intel_results
|
process.stdout = self.intel_results
|
||||||
sp.return_value = process
|
sp.return_value = process
|
||||||
intel_stats = get_intel_gpu_stats()
|
intel_stats = get_intel_gpu_stats()
|
||||||
assert intel_stats == {
|
assert intel_stats == {
|
||||||
"gpu": "10.73 %",
|
"gpu": "1.34 %",
|
||||||
"mem": "- %",
|
"mem": "- %",
|
||||||
}
|
}
|
||||||
|
@ -797,7 +797,7 @@ def get_intel_gpu_stats() -> dict[str, str]:
|
|||||||
"""Get stats using intel_gpu_top."""
|
"""Get stats using intel_gpu_top."""
|
||||||
intel_gpu_top_command = [
|
intel_gpu_top_command = [
|
||||||
"timeout",
|
"timeout",
|
||||||
"0.1s",
|
"0.5s",
|
||||||
"intel_gpu_top",
|
"intel_gpu_top",
|
||||||
"-J",
|
"-J",
|
||||||
"-o",
|
"-o",
|
||||||
@ -812,27 +812,39 @@ def get_intel_gpu_stats() -> dict[str, str]:
|
|||||||
capture_output=True,
|
capture_output=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if p.returncode != 0:
|
# timeout has a non-zero returncode when timeout is reached
|
||||||
|
if p.returncode != 124:
|
||||||
logger.error(p.stderr)
|
logger.error(p.stderr)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
readings = json.loads(f"[{p.stdout}]")
|
reading = "".join(p.stdout.split())
|
||||||
results: dict[str, str] = {}
|
results: dict[str, str] = {}
|
||||||
|
|
||||||
for reading in readings:
|
# render is used for qsv
|
||||||
if reading.get("engines", {}).get("Video/0", {}).get(
|
render = []
|
||||||
"busy", 0
|
for result in re.findall('"Render/3D/0":{[a-z":\d.,%]+}', reading):
|
||||||
) or reading.get("engines", {}).get("Video/1", {}).get("busy", 0):
|
packet = json.loads(result[14:])
|
||||||
gpu_usage = round(
|
single = packet.get("busy", 0.0)
|
||||||
float(reading.get("engines", {}).get("Video/0", {}).get("busy", 0))
|
render.append(float(single))
|
||||||
+ float(
|
|
||||||
reading.get("engines", {}).get("Video/1", {}).get("busy", 0)
|
|
||||||
),
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
results["gpu"] = f"{gpu_usage} %"
|
|
||||||
break
|
|
||||||
|
|
||||||
|
if render:
|
||||||
|
render_avg = sum(render) / len(render)
|
||||||
|
else:
|
||||||
|
render_avg = 1
|
||||||
|
|
||||||
|
# video is used for vaapi
|
||||||
|
video = []
|
||||||
|
for result in re.findall('"Video/\d":{[a-z":\d.,%]+}', reading):
|
||||||
|
packet = json.loads(result[10:])
|
||||||
|
single = packet.get("busy", 0.0)
|
||||||
|
video.append(float(single))
|
||||||
|
|
||||||
|
if video:
|
||||||
|
video_avg = sum(video) / len(video)
|
||||||
|
else:
|
||||||
|
video_avg = 1
|
||||||
|
|
||||||
|
results["gpu"] = f"{round((video_avg + render_avg) / 2, 2)} %"
|
||||||
results["mem"] = "- %"
|
results["mem"] = "- %"
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user