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
Make memory profiling work in pytest-xdist workers
The previous commit rejected --scalene-memory with -n because worker
allocations came back as literally nothing: max_footprint_mb == 0, an
empty memory timeline, 0 MB on every line, for a workload reporting
43 MB serially. That turned out to be a fixable bug, not an inherent
limit, so this replaces the rejection with support.
Bisecting the path with probes showed the interposer was in place and
simply never recorded anything: in a worker, libscalene was loaded
(dlsym finds its symbols), DYLD_INSERT_LIBRARIES was set, args.memory
was True, the SIGXCPU handler was installed and the mapfiles existed --
but the interposer's write cursor was 0 bytes, against 8302 in the
controller. So nothing was being dropped on the Python side; nothing was
ever written.
The cause is pywhere's native TraceConfig. sampleheap.hpp only writes an
allocation record when where(...) returns non-zero, and whereInPython
returns 0 immediately when TraceConfig is null. Scalene registers that
config while preparing to run a program file; an interpreter launched as
`python -c ...` -- which is how xdist's execnet starts its workers --
never reaches that code, so the config stayed null and every allocation
went unrecorded.
Fix it where the asymmetry actually is: Scalene.set_program_path() now
re-registers the files to profile when memory profiling is on. That is
the natural home for it, since pywhere holds its own copy of the program
path, and it fixes any programmatic entry point that repoints the path
rather than just this plugin. Confirmed by hand first -- calling
_register_files_to_profile() in a worker took it from 0 bytes/0 samples
to 101752 bytes/100 samples.
`pytest --scalene-memory -n 2` now reports 43.0 MB on the allocating
line, matching the serial run exactly. All six combinations of
{--scalene, --scalene-memory} x {serial, -n 0, -n 2} verified; CPU
percentages are lower under -n 2 only because elapsed time is wall-clock
across parallel workers, which is the correct denominator.
Full suite passes on 3.12 (438) and 3.14 (450).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0 commit comments