pyinstrument icon indicating copy to clipboard operation
pyinstrument copied to clipboard

Expose interval option in command-line interface

Open matt-graham opened this issue 3 years ago • 1 comments

Related to the discussion in #169, I've found that the memory overhead of using pyinstrument to profile long-running (several hours run time) scripts using the command-line interface with the default sampling interval of 0.001 s can result in runs prematurely terminating with an out-of-memory error. Given there will be (tens of) millions of stack samples being recorded in this case, that there are issues with memory consumption in such cases is not surprising, but also this suggests a much longer sampling interval would be appropriate in such cases while still giving reasonable low-variance estimates. This PR exposes the existing interval argument to the Profiler class in the command-line interface to allow easier adjustment of the sampling interval without needing to use the Python interface directly.

matt-graham avatar Aug 09 '22 10:08 matt-graham

Not sure if the failing test_interval test on macos-latest, 3.11-dev was due to the larger interval in test_interval (0.005s) compared to the default (0.001s) meaning there is a non-negligible probability of some of the function calls not being captured and its just chance this was only on the macos-latest, 3.11-dev run, or there is something more specific going on here. I have tried reducing the interval down to 0.002s to see if that helps and also fixed the missing new line at end of file causing the pre-commit fail.

matt-graham avatar Aug 09 '22 11:08 matt-graham