Profiling¶
- mew.memory.profile(entries, *, flamegraph=None, iterations=100)[source]¶
Profile each entry with memray over
iterationsmeasured loop passes.- Parameters:
flamegraph (
Path|None) – If given, additionally writes a combined HTML flame graph to this path. Note this re-executes every case under a second tracker (memray capture files cannot be merged after the fact), roughly doubling profiling time.iterations (
int) – Measured timing-loop passes per case (a warmup runs first, untracked). Many passes amortize one-time allocations, keepingallocations_per_iterationcomparable across engines.
- Return type:
- Returns:
dict[str, MemoryProfile] – Per-case profiles keyed by
entry.name(orentry.name/case:<i>for each variant of a parametrized family).
- class mew.memory.MemoryProfile(profiler, peak_bytes, total_bytes, total_allocations, iterations, allocations_per_iteration)[source]¶
Bases:
objectPer-case memory summary captured by memray.
The capture is scoped to the timing loop (
for _ in state), so fixture/setup allocations are excluded;iterationsmeasured passes run after a warmup, makingallocations_per_iterationa steady-state figure.- Variables:
peak_bytes (int) – Peak memory during the loop (
metadata.peak_memory); a high-water mark, independent of iteration count.total_bytes (int) – Tracked heap live at the high-water mark, not the cumulative sum.
total_allocations (int) – Cumulative allocation count across all
iterations. Not comparable across runs of differing iteration count; useallocations_per_iteration.iterations (int) – Number of measured timing-loop iterations the capture ran over.
allocations_per_iteration (float) –
total_allocations / iterations, the per-call count, comparable across engines regardless of speed.
- Parameters:
- mew.cpu.profile(entries, *, output=None, interval=0.0001, inner_iterations=1000)[source]¶
Profile each entry under pyinstrument.
- Parameters:
output (
Path|None) – If given, additionally writes a combined pyinstrument HTML report to this path.interval (
float) – Pyinstrument’s sampling period in seconds.inner_iterations (
int) – Times the benchmark body runs under the sampler per entry. Fast benchmarks need many iterations to accumulate samples.
- Return type:
- Returns:
dict[str, CPUProfile] – Per-case profiles keyed by
entry.name(orentry.name/case:<i>for each variant of a parametrized family).
Notes
state.pause()regions are excluded: the pause suspends the sampler, aspause()excludes setup from a timed run.
- class mew.cpu.CPUProfile(profiler, wall_time, sample_count, top_function, top_function_total_self_time)[source]¶
Bases:
objectPer-case CPU summary captured by pyinstrument.
Sampled out of the timing loop, so the figures are independent of the measured run;
state.pause()regions are excluded.- Variables:
profiler (str) – Name of the sampling backend, always
"pyinstrument".wall_time (float) – Seconds the sampled execution took, including sampler overhead.
sample_count (int) – Stack samples collected. A low count means the body is too fast for the interval; raise
inner_iterations.top_function (str) – Hottest frame by self time, as
function (file.py:lineno)."<no samples>"when nothing was captured.top_function_total_self_time (float) – Seconds of self time attributed to
top_function.
- Parameters: