I want to profile time and memory usage of class method. I didn't find an out of box solution for this (are there such modules?), and I decided to use timeit
for time profiling and memory_usage
from memory_profiler
module.
I faced a problem of profiling methods with memory_profiler
. I've tried different variants, and none of them worked.
When I try to use partial from functools
, I get this error:
File "/usr/lib/python2.7/site-packages/memory_profiler.py", line 126, in memory_usage
aspec = inspect.getargspec(f)
File "/usr/lib64/python2.7/inspect.py", line 815, in getargspec
raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <functools.partial object at 0x252da48> is not a Python function
By the way, exactly the same approach works fine with timeit
function.
When I try to use lambda
as was I got this error:
File "/usr/lib/python2.7/site-packages/memory_profiler.py", line 141, in memory_usage
ret = parent_conn.recv()
IOError: [Errno 4] Interrupted system call
How can I handle class methods with memory_profiler?
PS: I have memory-profiler (0.26) (installed with pip).
UPD: It's actually bug. You can check status here: https://github.com/pythonprofilers/memory_profiler/issues/47
get_memory_info()
is deprecated. Usememory_info()
instead. And note that it will return a named tuple, with much more than only two values. See psutil.readthedocs.io/en/latest/#psutil.Process.memory_info – Swank