Finding Memory Usage, CPU utilization, Execution time for running a python script
For time profiling
cd
into the dir that containsexample.py
(lets call thisexampledir
).- run
python -m cProfile -o example.profile example.py
- download RunSnake and unpack it anywhere
cd
into the dir where you unpacked RunSnake- run
python runsnake.py exampledir/example.profile
For CPU Profiling
- Use
psutil
- create a new
psutil.Process
withmyProcess = psutil.Process(os.getpid())
- call
myProcess.get_memory_info()
ormyProcess.get_ext_memory_info()
ormyProcess.get_memory_percent()
as required
- create a new
For memory profiling
- install meliae with
easy_install
orpip
- Add the following lines of code to the top of
example.py
:
from meliae import scanner # [[source](http://www.vrplumber.com/programming/runsnakerun/)]
scanner.dump_all_objects( filename ) # you can pass a file-handle if you prefer
- run
runsnakemem fpath
, wherefpath
is the path to the file that you used in the code above.
This should get you a visual memory profiler similar to What you got with RunSnakeRun.
Hope this helps