Skip to content

Commit

Permalink
Add support for nvidia decoder and encoder utilization stats (blakebl…
Browse files Browse the repository at this point in the history
…ackshear#8150)

* Add encoder and decoder stats to nvidia hwaccel stats

* Fix

* Fix
  • Loading branch information
NickM-27 committed Oct 13, 2023
1 parent e32bd4a commit 9b687d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frigate/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ async def set_gpu_stats(
stats[nvidia_usage[i]["name"]] = {
"gpu": str(round(float(nvidia_usage[i]["gpu"]), 2)) + "%",
"mem": str(round(float(nvidia_usage[i]["mem"]), 2)) + "%",
"enc": str(round(float(nvidia_usage[i]["enc"]), 2)) + "%",
"dec": str(round(float(nvidia_usage[i]["dec"]), 2)) + "%",
}

else:
Expand Down
14 changes: 14 additions & 0 deletions frigate/util/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def get_nvidia_gpu_stats() -> dict[int, dict]:
handle = nvml.nvmlDeviceGetHandleByIndex(i)
meminfo = try_get_info(nvml.nvmlDeviceGetMemoryInfo, handle)
util = try_get_info(nvml.nvmlDeviceGetUtilizationRates, handle)
enc = try_get_info(nvml.nvmlDeviceGetEncoderUtilization, handle)
dec = try_get_info(nvml.nvmlDeviceGetDecoderUtilization, handle)
if util != "N/A":
gpu_util = util.gpu
else:
Expand All @@ -303,10 +305,22 @@ def get_nvidia_gpu_stats() -> dict[int, dict]:
else:
gpu_mem_util = -1

if enc != "N/A":
enc_util = enc[0]
else:
enc_util = -1

if dec != "N/A":
dec_util = dec[0]
else:
dec_util = -1

results[i] = {
"name": nvml.nvmlDeviceGetName(handle),
"gpu": gpu_util,
"mem": gpu_mem_util,
"enc": enc_util,
"dec": dec_util,
}
except Exception:
pass
Expand Down
4 changes: 4 additions & 0 deletions web/src/routes/System.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,16 @@ export default function System() {
<Tr>
<Th>GPU %</Th>
<Th>Memory %</Th>
{'dec' in gpu_usages[gpu] && (<Th>Decoder %</Th>)}
{'enc' in gpu_usages[gpu] && (<Th>Encoder %</Th>)}
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>{gpu_usages[gpu]['gpu']}</Td>
<Td>{gpu_usages[gpu]['mem']}</Td>
{'dec' in gpu_usages[gpu] && (<Td>{gpu_usages[gpu]['dec']}</Td>)}
{'enc' in gpu_usages[gpu] && (<Td>{gpu_usages[gpu]['enc']}</Td>)}
</Tr>
</Tbody>
</Table>
Expand Down

0 comments on commit 9b687d7

Please sign in to comment.