-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory usage does not work with class methods? #47
Comments
Thanks for the report, that's indeed a nasty bug. |
Thank you for your answer! Offtopic: memory_list = memory_usage((func, (), {}))
memory = max(memory_list) - min(memory_list) I thought about measuring memory with console API and decorators, parsing output, ... But that is silly. |
@rominf A quick and probably dirty way to do what you want. First install psutil. This assumes that your function does not return anything (as in your example). Adjust as necessary. The function below takes a callable (the def call_with_memory(fn, *args, **kwargs):
process = psutil.Process(os.getpid())
start_rss, start_vms = process.get_memory_info()
fn(*args, **kwargs)
end_rss, end_vms = process.get_memory_info()
return (end_rss - start_rss), (end_vms - start_vms) |
@sjagoe Thank you for suggestion. Unfortunately it doesn't work as I want: it returns def f():
s = 'a'*10000 it returns (0, 0), not something like (in C style) |
@rominf This discussion no longer belongs here. You can contact me by email (see my profile). |
@fabianp Apologies for allowing this issue-hijacking for going on so long. I have moved my information to the SO thread. I would suggest deleting the off topic comments here given that the same content is in the linked SO thread. |
@sjagoe no problem, I'm just sorry I don't have time to look into this at the moment. |
This is missing a SSCCE. |
I want to profile time and memory usage of class method.
When I try to use
partial
fromfunctools
I got this error:By the way exactly the same approach works fine with
timeit
function.When I try to use
lambda
as was I got this error:How can I handle class methods with memory_profiler? Are there any (even dirty) ways?
I asked this question on SO: http://stackoverflow.com/questions/16593246/how-to-use-memory-profiler-python-module-with-class-methods
UPD: fixed broken link to SO
The text was updated successfully, but these errors were encountered: