mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-07 02:18:07 +01: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:
@@ -121,7 +121,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
||||
pid = str(process.info["pid"])
|
||||
try:
|
||||
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:
|
||||
stats = f.readline().split()
|
||||
@@ -155,7 +155,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": clean_camera_user_pass(" ".join(cmdline)),
|
||||
"cmdline": clean_camera_user_pass(cmdline),
|
||||
}
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user