def main(): parser = build_argparser() args = parser.parse_args(sys.argv[1:]) web = args.web if args.input: assert args.query is not None, "Using -i requires you to specify -q" forest = parse_jitlog(args.input) q = query.new_unsafe_query(args.query) objs = q(forest) pretty_printer.write(sys.stdout, objs) sys.exit(0) if args.upload: # parse_jitlog will append source code to the binary forest = parse_jitlog(args.program) if forest.exception_raised(): print("ERROR:", forest.exception_raised()) sys.exit(1) if forest.extract_source_code_lines(): # only copy the tags if the jitlog has no source code yet! forest.copy_and_add_source_code_tags() jitlog_upload(forest.filepath, get_url(args.web_url, "api/jitlog//")) sys.exit(0) if not _jitlog: if '__pypy__' in sys.builtin_module_names: sys.stderr.write( "No _jitlog module. This PyPy version is too old!\n") else: sys.stderr.write( "No _jitlog module. Use PyPy instead of CPython!\n") if not web: prof_file = args.output else: prof_file = tempfile.NamedTemporaryFile(delete=False) prof_name = prof_file.name fd = os.open(prof_name, os.O_WRONLY | os.O_TRUNC | os.O_CREAT) _jitlog.enable(fd) try: sys.argv = [args.program] + args.args sys.path.insert(0, os.path.dirname(args.program)) runpy.run_path(args.program, run_name='__main__') except BaseException as e: if not isinstance(e, (KeyboardInterrupt, SystemExit)): raise # not need to close fd, will be here _jitlog.disable() if web: forest = parse_jitlog(prof_name) if forest.extract_source_code_lines(): # only copy the tags if the jitlog has no source code yet! forest.copy_and_add_source_code_tags() jitlog_upload(forest.filepath, get_url(args.web_url, "api/jitlog//")) forest.unlink_jitlog() # free space!
def main(): parser = build_argparser() args = parser.parse_args(sys.argv[1:]) web = args.web if args.input: assert args.query is not None, "Using -i requires you to specify -q" forest = parse_jitlog(args.input) q = query.new_unsafe_query(args.query) objs = q(forest) pretty_printer.write(sys.stdout, objs) sys.exit(0) if args.upload: # parse_jitlog will append source code to the binary forest = parse_jitlog(args.program) if forest.exception_raised(): print("ERROR:", forest.exception_raised()) sys.exit(1) if forest.extract_source_code_lines(): # only copy the tags if the jitlog has no source code yet! forest.copy_and_add_source_code_tags() jitlog_upload(forest.filepath, get_url(args.web_url, "api/jitlog//")) sys.exit(0) if not _jitlog: if '__pypy__' in sys.builtin_module_names: sys.stderr.write("No _jitlog module. This PyPy version is too old!\n") else: sys.stderr.write("No _jitlog module. Use PyPy instead of CPython!\n") if not web: prof_file = args.output else: prof_file = tempfile.NamedTemporaryFile(delete=False) prof_name = prof_file.name fd = os.open(prof_name, os.O_WRONLY | os.O_TRUNC | os.O_CREAT) _jitlog.enable(fd) try: sys.argv = [args.program] + args.args sys.path.insert(0, os.path.dirname(args.program)) runpy.run_path(args.program, run_name='__main__') except BaseException as e: if not isinstance(e, (KeyboardInterrupt, SystemExit)): raise # not need to close fd, will be here _jitlog.disable() if web: forest = parse_jitlog(prof_name) if forest.extract_source_code_lines(): # only copy the tags if the jitlog has no source code yet! forest.copy_and_add_source_code_tags() jitlog_upload(forest.filepath, get_url(args.web_url, "api/jitlog//")) forest.unlink_jitlog() # free space!
def main(): parser = build_argparser() args = parser.parse_args(sys.argv[1:]) web = args.web if args.query is not None: from jitlog import prettyprinter as pp sys.stderr.write("Parsing jitlog...") sys.stderr.flush() forest = parse_jitlog(args.program) sys.stderr.write("done\n") query_str = args.query or "traces()" q = query.new_unsafe_query(query_str) objs = q(forest) color = True pp_clazz = pp.ColoredPrettyPrinter if color else pp.PrettyPrinter with pp_clazz() as ppinst: for trace in objs: ppinst.trace(sys.stdout, trace) if args.query is None: sys.stderr.write("-" * 10 + '\n') sys.stderr.write("Display the jitlog with an empty query (defaults to -q 'traces()'). " "Add -q 'your query' if you want to narrow down the output\n") sys.exit(0) if args.upload: host, auth = args.web_url, args.web_auth service = Service(host, auth) service.post({ Service.FILE_JIT_PROFILE: args.program }) sys.exit(0) if not _jitlog: if '__pypy__' in sys.builtin_module_names: sys.stderr.write("No _jitlog module. This PyPy version is too old!\n") else: sys.stderr.write("No _jitlog module. Use PyPy instead of CPython!\n") if not web: prof_file = args.output else: prof_file = tempfile.NamedTemporaryFile(delete=False) prof_name = prof_file.name fd = os.open(prof_name, os.O_WRONLY | os.O_TRUNC | os.O_CREAT) _jitlog.enable(fd) try: sys.argv = [args.program] + args.args sys.path.insert(0, os.path.dirname(args.program)) runpy.run_path(args.program, run_name='__main__') except BaseException as e: if not isinstance(e, (KeyboardInterrupt, SystemExit)): raise # not need to close fd, will be here _jitlog.disable() if web: forest = parse_jitlog(prof_name) if forest.extract_source_code_lines(): # only copy the tags if the jitlog has no source code yet! forest.copy_and_add_source_code_tags() host, auth = args.web_url, args.web_auth service = Service(host, auth) service.post({ Service.FILE_JIT_PROFILE: forest.filepath }) forest.unlink_jitlog() # free space!
def q(self, forest, text): return query.new_unsafe_query(text)(forest)