You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix two more divide-by-zero bugs found by the formalization audit (#1078)
* Fix divide-by-zero in per-stack CPU normalization (--stacks + memory-only)
The stacks-normalization loop in ScaleneJSON.output_profiles divided each
recorded stack's timings by stats.cpu_stats.total_cpu_samples with no guard.
That denominator can be 0.0 while stats.stacks is non-empty: a memory-only
run with --stacks records stack entries (from the CPU sampler's stack
collection) while it is *memory* activity -- not CPU activity -- that passes
the 'nothing to output' gate at the top of output_profiles. With no CPU
sample ever recorded, total_cpu_samples stays at its initial 0.0 and the loop
raises ZeroDivisionError.
The sibling per-file/per-line CPU normalizations (~556, ~1259, ~1337) already
guard this; this site was missed. Same bug class as the leak-velocity divide
(#1077). Found by re-running the formalization audit's 'every denominator is
a claim to verify' sweep across the output path (formal/README.md 'Bugs the
formalization found', now three).
Guard the loop on total_cpu_samples (raw stack entries preserved when 0).
Regression test drives the full output_profiles path, so it crashes pre-fix
and passes after.
* Fix CLI-renderer twin of the leak-velocity divide-by-zero
Bug #1 (fixed in #1077) was an unguarded leak_velocity / stats.elapsed_time
in the JSON renderer. Scalene has three separate output renderers
(Scalene-Debugging.md); the CLI renderer scalene_output.py:699 (scalene view
--cli) carried the identical unguarded divide, which #1077 did not touch.
Same reachability as #1: compute_leaks gates on allocation growth rate, not
wall-clock time, so a leak can be reported on a sub-millisecond run where
elapsed_time is still 0.0 -> ZeroDivisionError.
Found by re-running the denominator audit across the CLI output path (the
other output.py divides at ~339/~379/~416/~657 are already guarded). Guard
the velocity denominator, mirroring the #1077 json.py fix. Regression test
added. Also updates formal/README.md + HANDOFF.md (now four bugs found).
The takeaway, now recorded in HANDOFF: a fix in one renderer does not cover
its siblings -- audit all three.
0 commit comments