Created
November 19, 2015 01:29
-
-
Save harlowja/d2b5fc5282c76f10bc3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from eventlet.green import profile | |
import eventlet | |
eventlet.monkey_patch(all=True) | |
def main(): | |
import os, sys | |
from optparse import OptionParser | |
usage = "eProfile.py [-o output_file_path] scriptfile [arg] ..." | |
parser = OptionParser(usage=usage) | |
parser.allow_interspersed_args = False | |
parser.add_option('-o', '--outfile', dest="outfile", | |
help="Save stats to <outfile>", default=None) | |
if not sys.argv[1:]: | |
parser.print_usage() | |
sys.exit(2) | |
(options, args) = parser.parse_args() | |
sys.argv[:] = args | |
if len(args) > 0: | |
progname = args[0] | |
sys.path.insert(0, os.path.dirname(progname)) | |
with open(progname, 'rb') as fp: | |
code = compile(fp.read(), progname, 'exec') | |
globs = { | |
'__file__': progname, | |
'__name__': '__main__', | |
'__package__': None, | |
'__cached__': None, | |
} | |
profile.runctx(code, globs, None, filename=options.outfile) | |
else: | |
parser.print_usage() | |
return parser | |
# When invoked as main program, invoke the profiler on a script | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment