1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#!/usr/bin/env bash
## pyprofile: profile Python script
## $Revision$
## Copyright 2011 Michael M. Hoffman <mmh1@uw.edu>
## Modified by Tao Liu: Correctly get the command name.
set -o nounset
set -o pipefail
set -o errexit
if [ $# -lt 2 ]; then
echo usage: "$0" PROF CMDLINE...
exit 2
fi
PROF=$1
MAIN=`basename $2`
CMD=( $@ )
CMD=${CMD[@]: 1}
# run CMD with cProfile
python3 -m cProfile -o $PROF $CMD
# brief the profile
./pyprofile_stat $PROF tottime > ${PROF/.prof/}.tottime
./pyprofile_stat $PROF calls > ${PROF/.prof/}.calls
./pyprofile_stat $PROF cumulative > ${PROF/.prof/}.cumulative
echo "check ${PROF/.prof/}.tottime, ${PROF/.prof/}.calls, and ${PROF/.prof/}.cumulative"
|