Skip to content

Instantly share code, notes, and snippets.

@samba
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samba/b3455ee1a9e95df45362 to your computer and use it in GitHub Desktop.
Save samba/b3455ee1a9e95df45362 to your computer and use it in GitHub Desktop.
Python profiling shortcut
#!/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