Skip to content

Commit

Permalink
Add cmdline information to CPU usage stats in get_cpu_stats() functio…
Browse files Browse the repository at this point in the history
…n and display it in the System page's ffmpeg table with a copy-to-clipboard button (blakeblackshear#6430)
  • Loading branch information
skrashevich committed May 15, 2023
1 parent 181b53a commit 5fb96c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion frigate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,11 @@ def get_cpu_stats() -> dict[str, dict]:
docker_memlimit = get_docker_memlimit_bytes() / 1024
total_mem = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") / 1024

for process in psutil.process_iter(["pid", "name", "cpu_percent"]):
for process in psutil.process_iter(["pid", "name", "cpu_percent", "cmdline"]):
pid = process.info["pid"]
try:
cpu_percent = process.info["cpu_percent"]
cmdline = process.info["cmdline"]

with open(f"/proc/{pid}/stat", "r") as f:
stats = f.readline().split()
Expand Down Expand Up @@ -837,6 +838,7 @@ def get_cpu_stats() -> dict[str, dict]:
"cpu": str(cpu_percent),
"cpu_average": str(round(cpu_average_usage, 2)),
"mem": f"{mem_pct}",
"cmdline": " ".join(cmdline),
}
except:
continue
Expand Down
10 changes: 9 additions & 1 deletion web/src/routes/System.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,15 @@ export default function System() {
</Thead>
<Tbody>
<Tr key="ffmpeg" index="0">
<Td>ffmpeg</Td>
<Td>ffmpeg
<Button
className="rounded-full"
type="text"
color="gray"
aria-label={cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cmdline']}
onClick={() => copy(cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cmdline'])}
><About className="w-3" /></Button>
</Td>
<Td>{cameras[camera]['ffmpeg_pid'] || '- '}</Td>
<Td>{cameras[camera]['camera_fps'] || '- '}</Td>
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cpu'] || '- '}%</Td>
Expand Down

0 comments on commit 5fb96c7

Please sign in to comment.