diff options
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/profile.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/Lib/profile.py b/Lib/profile.py index 00a0ae9..9d7e284 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -583,31 +583,29 @@ class 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__': +def main(): usage = "profile.py [-o output_file_path] [-s sort] scriptfile [arg] ..." - if not sys.argv[1:]: - print "Usage: ", usage - sys.exit(2) - - class ProfileParser(OptionParser): - def __init__(self, usage): - OptionParser.__init__(self) - self.usage = usage - - parser = ProfileParser(usage) + parser = OptionParser(usage=usage) parser.allow_interspersed_args = False parser.add_option('-o', '--outfile', dest="outfile", help="Save stats to <outfile>", default=None) parser.add_option('-s', '--sort', dest="sort", help="Sort order when printing to stdout, based on pstats.Stats class", default=-1) - + + if not sys.argv[1:]: + parser.print_usage() + sys.exit(2) + (options, args) = parser.parse_args() sys.argv[:] = args - + if (len(sys.argv) > 0): sys.path.insert(0, os.path.dirname(sys.argv[0])) run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort) else: - print "Usage: ", usage + parser.print_usage() + return parser + +# When invoked as main program, invoke the profiler on a script +if __name__ == '__main__': + main() |