samba
4/30/2014 - 4:29 PM

Python profiling shortcut

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 "$@"