Articles
Profiling CPU
With cProfile
Collect data:
python -m cProfile -o out.cprof script.py args...
Use snakeviz to visualize collected data:
pip install snakeviz
snakeviz out.cprof
Alternatives to snakeviz:
pip install pyprof2calltree
apt install qcachegrind
pyprof2calltree -k -i out.cprof
With pprofile
https://github.com/vpelletier/pprofile
With line_profiler
https://github.com/rkern/line_profiler
Profiling memory
memory_profiler
WithGlobal memory usage
Note: use the --python python3
option as indicated in this issue.
mprof run --python python3 convert.py source-data json-data
mprof plot
Optionally decorate some functions with @profile
, without importing the decorator, as explained in the README. You'll see the memory usage of those functions explicitly on the chart.
Line by line
Decorate the functions you want to profile with @profile
and run with:
python -m memory_profiler convert.py source-data json-data