cpu-hogs: no separator a reader splits on, cgroups read as bytes, and bench.sh says why it failed

printable() let U+2028 and U+2029 through, which str.splitlines() in bench.sh takes for line ends: a busy process whose name held one vanished from the report, which then claimed a quiet box (code review, 2026-10-26). Anything not printable becomes a space now. cgroup() read /proc/<pid>/cgroup as strict text, the failure fixed for stat in df39e91: it reads bytes too. bench.sh threw away a failing cpu-hogs.py's output, so a window out of 0.5 to 60 s or a crash read only as "cpu-hogs failed (exit 2)": its last line is given now. And tests/test_bench_median.py runs bench.sh with the docker that lists no container, as the other two do. Three checks fail on the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-10-26 23:14:43 +01:00
1 parent d27f4524e9
commit 3fe1188a4d
5 files changed
+31 -9

No files matched your search

+6 -4
View File
@@ -19,13 +19,14 @@ HOGS_WINDOW="${HOGS_WINDOW:-3}"
# A cpu-hogs that died must never read as a quiet box (revue 627, 2026-10-26): the
# "2>/dev/null || true" used to swallow every failure (missing file, crash, a non-numeric
# window from the caller) and the report then claimed nothing outside the engine held a core.
# Its last line says why it failed (a window out of 0.5 to 60 s, a crash), which the report gives.
if HOGS="$(python3 "$(dirname "$0")/cpu-hogs.py" --window "$HOGS_WINDOW" 2>&1)"; then
HOGS_FAILED=0
HOGS_FAILED=0; HOGS_ERR=""
else
HOGS_FAILED=$?; HOGS=""
HOGS_FAILED=$?; HOGS_ERR="$(printf '%s\n' "$HOGS" | tail -n 1)"; HOGS=""
fi
KEY="$(cat "$KEY_FILE")" PORT="$PORT" HOGS="$HOGS" HOGS_FAILED="$HOGS_FAILED" HOGS_WINDOW="$HOGS_WINDOW" python3 - <<'PYEOF'
KEY="$(cat "$KEY_FILE")" PORT="$PORT" HOGS="$HOGS" HOGS_FAILED="$HOGS_FAILED" HOGS_ERR="$HOGS_ERR" HOGS_WINDOW="$HOGS_WINDOW" python3 - <<'PYEOF'
import json, os, statistics, time, urllib.request
KEY, PORT = os.environ["KEY"], os.environ["PORT"]
@@ -141,7 +142,8 @@ print(f"{reference}\n")
# pid, share of a core, name and command line, tab-separated, from cpu-hogs.py
HOGS = [line.split("\t") for line in os.environ.get("HOGS", "").splitlines() if line.count("\t") == 3]
if os.environ.get("HOGS_FAILED", "0") != "0":
print(f"busy before the run: cpu-hogs failed (exit {os.environ['HOGS_FAILED']}), the quiet outside the engine is NOT proven, do not publish these numbers as clean\n")
why = "".join(c if c.isprintable() else " " for c in os.environ.get("HOGS_ERR", ""))[:200]
print(f"busy before the run: cpu-hogs failed (exit {os.environ['HOGS_FAILED']}{': ' + why if why else ''}), the quiet outside the engine is NOT proven, do not publish these numbers as clean\n")
elif HOGS:
print(f"busy before the run, outside the engine (half a core or more over {os.environ['HOGS_WINDOW']} s):")
# its pid and name, never its command line: this report gets pasted in public, and a command line can
+6 -4
View File
@@ -56,8 +56,8 @@ def engine_ids():
def cgroup(pid, proc="/proc"):
try:
with open(f"{proc}/{pid}/cgroup") as f:
return f.read()
with open(f"{proc}/{pid}/cgroup", "rb") as f: # bytes, as stat: a path is not always UTF-8
return f.read().decode(errors="replace")
except OSError:
return ""
@@ -100,8 +100,10 @@ def hogs(window=3.0, floor=0.5, proc="/proc"):
def printable(text):
"""A field of the tab-separated output: no tab or newline to split the line (bench.sh keeps lines of four
fields, and a busy process with a tab in its argv vanished from its report), and no control character a
terminal would act on (an argv can carry an escape sequence) (verification, 2026-10-26)."""
return "".join(" " if ord(c) < 32 or 127 <= ord(c) < 160 else c for c in text)
terminal would act on (an argv can carry an escape sequence) (verification, 2026-10-26). Nothing that is
not printable: U+2028 and U+2029 end a line for splitlines() too, and a name holding one hid its busy
process from bench.sh's report (code review, 2026-10-26)."""
return "".join(c if c.isprintable() else " " for c in text)
def main(argv):
+6
View File
@@ -183,6 +183,12 @@ def main():
out = run_bench("qwen3.8-27b", window="not-a-number")
if "cpu-hogs failed" not in out:
fails.append(f"a failing cpu-hogs did not say so:\n{out[:400]}")
# and why: its error was thrown away with its output (code review, 2026-10-26)
if "invalid float value" not in out:
fails.append(f"a failing cpu-hogs did not say why:\n{out[:400]}")
out = run_bench("qwen3.8-27b", window="0.3")
if "must be 0.5 to 60 s" not in out or "cpu-hogs failed (exit 2" not in out:
fails.append(f"a window under 0.5 s did not fail with its reason:\n{out[:400]}")
if "nothing outside the engine held half a core" in out:
fails.append("a failing cpu-hogs still let the quiet-box claim through")
+8 -1
View File
@@ -62,9 +62,16 @@ class TheMedian(unittest.TestCase):
os.makedirs(os.path.join(home, ".config", "qwen38"))
with open(os.path.join(home, ".config", "qwen38", "api-key"), "w") as f:
f.write("test-key\n")
# cpu-hogs.py asks docker which containers are the engine's: the offline suite asks no docker
# (TESTING.md), so a docker that lists none comes first on PATH (code review, 2026-10-26)
os.makedirs(os.path.join(home, "bin"))
with open(os.path.join(home, "bin", "docker"), "w") as f:
f.write("#!/bin/sh\nexit 0\n")
os.chmod(os.path.join(home, "bin", "docker"), 0o755)
try:
r = subprocess.run(["bash", str(BENCH)], capture_output=True, text=True, timeout=120,
env={**os.environ, "PORT": str(srv.server_port), "HOME": home})
env={**os.environ, "PORT": str(srv.server_port), "HOME": home,
"PATH": os.path.join(home, "bin") + os.pathsep + os.environ.get("PATH", "")})
finally:
srv.shutdown()
srv.server_close()
+5
View File
@@ -127,6 +127,11 @@ class OnThisMachine(unittest.TestCase):
self.assertEqual(len(mine[0]), 4, mine)
self.assertNotIn("\x1b", r.stdout)
def test_no_line_or_paragraph_separator_reaches_the_output(self):
# U+2028 and U+2029 end a line for str.splitlines(), which bench.sh reads with: a name holding one
# hid its busy process from the report (code review, 2026-10-26)
self.assertEqual(hogs.printable("spin\u2028x\u2029y\x85z\tw"), "spin x y z w")
def test_a_window_too_short_or_long_is_refused(self):
# a window of 0 turned one clock tick into several cores: ghosts above 100 % (code review, 2026-10-26)
for window in ("0", "0.1", "nan", "inf", "61"):