File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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#****************************************************************************
613614def 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` + ')' )
You can’t perform that action at this time.
0 commit comments