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 upload(stats, name, argv, host, auth, forest=None): try: profiles = stats.get_tree()._serialize() except EmptyProfileFile: # yes an empty profile is possible. # i.e. if we only want to upload the jitlog profiles = [] data = { "VM": stats.interp, "profiles": profiles, "argv": "%s %s" % (name, argv), "version": 2, } data = json.dumps(data).encode('utf-8') base_headers = {} if auth: base_headers = {'AUTHORIZATION': "Token %s" % auth} # XXX http only for now # upload the json profile headers = base_headers.copy() headers['Content-Type'] = 'application/json' url = get_url(host, "api/profile/") r = requests.post(url, data=data, headers=headers) if r.status_code != 200: sys.stderr.write("VMProf log: Server rejected profile. status: %d, msg: '%s'\n" % \ (r.status_code,r.text)) profile_checksum = '' else: profile_checksum = r.text[1:-1] sys.stderr.write("VMProf log: %s/#/%s\n" % (host.rstrip("/"), profile_checksum)) if forest: 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() url = get_url(host, "api/jitlog/%s/" % profile_checksum) jitlog.upload(forest.filepath, url) forest.unlink_jitlog()
def upload(stats, name, argv, host, auth, forest=None): try: profiles = stats.get_tree()._serialize() except EmptyProfileFile: # yes an empty profile is possible. # i.e. if we only want to upload the jitlog profiles = [] data = { "VM": stats.interp, "profiles": profiles, "argv": "%s %s" % (name, argv), "version": 2, } data = json.dumps(data).encode('utf-8') base_headers = {} if auth: base_headers = {'AUTHORIZATION': "Token %s" % auth} # XXX http only for now # upload the json profile headers = base_headers.copy() headers['Content-Type'] = 'application/json' url = get_url(host, "api/profile/") r = requests.post(url, data=data, headers=headers) if r.status_code != 200: sys.stderr.write("VMProf log: Server rejected profile. status: %d, msg: '%s'\n" % \ (r.status_code,r.text)) profile_checksum = '' else: profile_checksum = r.text[1:-1] sys.stderr.write("VMProf log: %s/#/%s\n" % (host.rstrip("/"), profile_checksum)) if forest: url = get_url(host, "api/jitlog/%s/" % profile_checksum) jitlog.upload(forest.filepath, url) forest.unlink_jitlog()