mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-08-03 16:52:36 -04:00
The OpenBSD fallback in CpuUsage never produced usable numbers: - The averaging was wrong. "$user = $user ? $user : ($user + $1)/2" halves the value on the first matching line (since $user is 0 there) and then discards every later line instead of averaging the cores. Sum the matched lines and divide by the count. - The regex hard-coded the double-space padding top uses for two-digit values, so a line containing 100.0% would not match. Match on \s+. - The regex only accepted per-core "CPU0 states:" lines, but OpenBSD top prints a single aggregate "CPU states:" line unless asked otherwise. Accept both. Extract the parsing into parse_bsd_top_cpu() so it can be tested without running top, and cover it: aggregate line, per-core averaging, padding and tab variation, and non-matching Linux/FreeBSD output. Tests: prove -Iscripts/ZoneMinder/lib scripts/ZoneMinder/t/server_cpu.t -> 16/16 pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CuqKActdr5XtySk7C6i3Vm