pythonprofilers / memory_profiler

Monitor Memory usage of Python code
http://pypi.python.org/pypi/memory_profiler
Other
4.39k stars 380 forks source link

feat(peak): adds --func optional argument #330

Closed william-silversmith closed 2 years ago

william-silversmith commented 3 years ago

Hi,

I was attempting to use mprof to benchmark some algorithmic code and realized for some of my tests, the setup was using more memory than the code itself, so I couldn't get an accurate measurement using mprof peak alone. Therefore, I introduced the ability to filter by function to help isolate the effect.

This doesn't support multiprocessing (because the .dat doesn't have entries for FUNC for child processes as far as I know. Hope this is a good contribution to mprof!


Filter the peak memory usage by function. This doesn't isolate the contribution of the function by itself, but it screens out noise from setting up the test so an accurate result can be obtained by mprof peak if the test is otherwise well isolated.

Example usage:

mprof peak --func some.function file.dat

The function name is the fully qualified python import name. You can also figure it out by grepping the dat file for FUNC entries.

fabianp commented 2 years ago

looks good to me, thanks!

william-silversmith commented 2 years ago

Thank you Fabian!