mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 10:33:11 +03:00
Clean up trailing whitespaces in cpu stats process cmdline (#22089)
The psutil library reads the process commandline as by opening /proc/pid/cmdline which returns a buffer that is larger than just the program cmdline due to rounded memory allocation sizes. That means that if the library does not detect a Null-terminated string it keeps appending empty strings which add up as whitespaces when joined.
This commit is contained in:
parent
9c3a74b4f5
commit
b4eac11cbd
@ -121,7 +121,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
|||||||
pid = str(process.info["pid"])
|
pid = str(process.info["pid"])
|
||||||
try:
|
try:
|
||||||
cpu_percent = process.info["cpu_percent"]
|
cpu_percent = process.info["cpu_percent"]
|
||||||
cmdline = process.info["cmdline"]
|
cmdline = " ".join(process.info["cmdline"]).rstrip()
|
||||||
|
|
||||||
with open(f"/proc/{pid}/stat", "r") as f:
|
with open(f"/proc/{pid}/stat", "r") as f:
|
||||||
stats = f.readline().split()
|
stats = f.readline().split()
|
||||||
@ -155,7 +155,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
|||||||
"cpu": str(cpu_percent),
|
"cpu": str(cpu_percent),
|
||||||
"cpu_average": str(round(cpu_average_usage, 2)),
|
"cpu_average": str(round(cpu_average_usage, 2)),
|
||||||
"mem": f"{mem_pct}",
|
"mem": f"{mem_pct}",
|
||||||
"cmdline": clean_camera_user_pass(" ".join(cmdline)),
|
"cmdline": clean_camera_user_pass(cmdline),
|
||||||
}
|
}
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user