Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc778eb

Browse files
committed
Add main program similar to pdb.
1 parent 7a73ef8 commit cc778eb

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/profile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! /usr/local/bin/python
12
#
23
# Class for profiling python code. rev 1.0 6/2/94
34
#
@@ -612,3 +613,21 @@ def snapshot_stats(self):
612613
#****************************************************************************
613614
def Stats(*args):
614615
print 'Report generating functions are in the "pstats" module\a'
616+
617+
618+
# When invoked as main program, invoke the profiler on a script
619+
if __name__ == '__main__':
620+
import sys
621+
import os
622+
if not sys.argv[1:]:
623+
print "usage: profile.py scriptfile [arg] ..."
624+
sys.exit(2)
625+
626+
filename = sys.argv[1] # Get script filename
627+
628+
del sys.argv[0] # Hide "profile.py" from argument list
629+
630+
# Insert script directory in front of module search path
631+
sys.path.insert(0, os.path.dirname(filename))
632+
633+
run('execfile(' + `filename` + ')')

0 commit comments

Comments
 (0)