-
Notifications
You must be signed in to change notification settings - Fork 381
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
Added windows support #1
Conversation
… falling back to the original subprocess method if psutil is not installed.
I did not know about psutil. Looks really nice! |
It is! A lot of code that relies on subprocess and UNIX tools can make use of it instead. Please consider merging this, I haven't tested it on a Linux system but I am assuming it works as expected. |
Great. I'm just busy with other things right now but the code is fine On 4/25/12, orf
|
raise NotImplementedError('Only UNIX supported at the moment') | ||
process = psutil.Process(pid) | ||
return float((float(process.get_memory_info()[0]) / 1024)) / 1024 | ||
except ImportError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as float(process.get_memory_info()[0]) / (1024 ** 2)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, and that way looks a lot nicer as well, or though the output is still the same. Your way is also twice as fast according to the timeit module.
Also initiating a Process object is fairly expensive (which I was not expecting):
>>> timeit.Timer("p = psutil.Process(1344)", "import psutil").timeit()
5.5183132777421235
It would probably be best to only create it once. I can send a new pull request if you want, or change it after its been merged? It will still be faster than launching "ps" every time _get_memory() gets called though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, OK great. I'll make those trivial changes.
I'd like to include you in a THANKS section, what name should I use ? do you have a webpage?
Cheers,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, Use Tom. My website is http://tomforb.es
Thanks!
It's in. thanks! |
making mprof.py compatible with python 2.6
The psutil module can be used to make memory_profiler cross platform. This patch does this, falling back to the original subprocess method if psutil is not available.