diff options
author | Guido van Rossum <guido@python.org> | 1996-10-01 02:55:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-10-01 02:55:54 (GMT) |
commit | cc778ebd62a5e256c6cf44b32f417658cce1751c (patch) | |
tree | 2cb8356983a03102a3fab70c716561cbf2b8fa54 /Lib/profile.py | |
parent | 7a73ef852f504a4c6110eeefb22150a2121c68e4 (diff) | |
download | cpython-cc778ebd62a5e256c6cf44b32f417658cce1751c.zip cpython-cc778ebd62a5e256c6cf44b32f417658cce1751c.tar.gz cpython-cc778ebd62a5e256c6cf44b32f417658cce1751c.tar.bz2 |
Add main program similar to pdb.
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-x | Lib/profile.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/profile.py b/Lib/profile.py index 7f4abed..51e95cb 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -1,3 +1,4 @@ +#! /usr/local/bin/python # # Class for profiling python code. rev 1.0 6/2/94 # @@ -612,3 +613,21 @@ class HotProfile(Profile): #**************************************************************************** def Stats(*args): print 'Report generating functions are in the "pstats" module\a' + + +# When invoked as main program, invoke the profiler on a script +if __name__ == '__main__': + import sys + import os + if not sys.argv[1:]: + print "usage: profile.py scriptfile [arg] ..." + sys.exit(2) + + filename = sys.argv[1] # Get script filename + + del sys.argv[0] # Hide "profile.py" from argument list + + # Insert script directory in front of module search path + sys.path.insert(0, os.path.dirname(filename)) + + run('execfile(' + `filename` + ')') |