Last active
August 29, 2015 14:00
-
-
Save samba/b3455ee1a9e95df45362 to your computer and use it in GitHub Desktop.
Python profiling shortcut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
'''USAGE: | |
pyprofile.sh run yourscript.py {your arguments} # Runs your program & stores statistics | |
pyprofile.sh show # Reports your statistics | |
Within the report mode, use 'help' to learn additional commands. | |
Initial recommendation: | |
sort cumtime ncalls # List function calls by total time spent in each function | |
stats 30 # Show top 30 function calls (by sorted metric, descending) | |
''' | |
BUILDSTAT=/tmp/build-statistics | |
main () { | |
mode=$1; shift; | |
case $mode in | |
run) python -m cProfile -o ${BUILDSTAT} -s 'cumulative' "$@";; | |
show) python -m pstats ${BUILDSTAT};; | |
esac | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment