Files
zoneminder/scripts
Isaac Connor ae82307be6 fix: correct BSD top cpu parsing in Server::CpuUsage
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
2026-07-20 22:45:41 -04:00
..
2016-11-07 16:08:43 -05:00
2023-07-05 01:03:48 +02:00
2020-06-30 18:58:46 -04:00
2023-07-05 01:03:48 +02:00
2024-11-05 13:12:12 -05:00