1

I have a Python package I am benchmarking for virtual memory used.

At the moment, this isn't very precise. I submit the script e.g.

python script1.py

and look at the time and resources used in order to execute.

Is there some package/method to find out where my RAM bottlenecks are? I'm thinking of a tool like

ram_used python script1.py 

that would keep track of how much RAM is used.

Does such a thing exist?

3
  • What do you mean with RAM bottlenecks? Do you want to know where the program is using a lot of memory? Or simply how much? Commented Jul 7, 2017 at 17:05
  • The general type of tool is called a profiler, and it usually binds to your operating system, rather than a particular language. Commented Jul 7, 2017 at 17:07
  • @WillemVanOnsem Simply how much Commented Jul 7, 2017 at 17:12

2 Answers 2

2

Yes, there is - It's called memory_profiler. Once you've gone through and added the @profile decorator to the functions you would like to profile, you can use;

python -m memory_profiler example.py
Sign up to request clarification or add additional context in comments.

6 Comments

What Python version? Both 2.7 and 3.5.4 deny any knowledge of memory_profiler for me.
Have you installed it using pip? pip install -U memory_profiler works fine for me using python 2.7.1.
Thanks; my "install" command is aliased to yum; pip worked, and the profiling worked.
@TomWyllie This is exceptionally useful for checking individual functions of the Python package. However, it's a bit cumbersome to add decorators to all functions in order to check the entire package. Is there a way to check the virtual memory used for the entire package?
I've not tested this but my first idea would be to just decorate the entry point to the program, eg your if __name__ == '__main__'. Although this may not fit your use case.
|
-1

There's also memory_info psutil. https://pythonhosted.org/psutil/

Place at the beginning of the script:

import psutil
p = psutil.Process()

and given that the code is running correctly, place this on the last line:

print(p.memory_info())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.