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 get_lines_dir_and_traces_num(self, file_name, result_dir): line_number = [] print file_name try: f = parser.parse_jitlog(file_name) except parser.ParseException: return 0, 0 lSerializer = LogMetaSerializer() d = lSerializer.to_representation(f) tSerializer = TraceSerializer() #try: f.extract_source_code_lines() #except IndexError: # return 0,0 for i in f.traces: #print 'trace:' + str(i) + 'SSSSSSSSSSSSSSSS' dic = tSerializer.to_representation(f.traces[i]) code_dic = dic['code'] #print 'OOOOOOOOOOOOOOOOOOLLLLLLLL'+code_dic for key in code_dic: code_file_dic = code_dic[key] # print 'MMMMMMMMMMMMMMMMMMM'+key if key in result_dir.keys(): line_list = result_dir[key] else: line_list = [] for key1 in code_file_dic: if key1 not in line_list: #print 'MMMMMMMMMMMMMMMMMMM'+str(key1) line_list.append(key1) result_dir[key] = line_list return result_dir, len(f.traces)
def show_stats(filename, output_mode, args): if output_mode == OUTPUT_FILE: return stats = vmprof.read_profile(filename) forest = None jitlog_filename = filename + '.jitlog' if output_mode == OUTPUT_CLI: vmprof.cli.show(stats) elif output_mode == OUTPUT_WEB: if os.path.exists(jitlog_filename): forest = parse_jitlog(jitlog_filename) upload_stats(stats, forest, args)
def post(self, kwargs): sys.stderr.write("Uploading to %s...\n" % self.host) argv = kwargs.get('argv', '-') vm = kwargs.get('VM', 'unknown') rid = self.post_new_entry({'argv': argv, 'VM': vm}) if rid is None: raise ServiceException("could not create meta data for profiles") if Service.FILE_CPU_PROFILE in kwargs: filename = kwargs[Service.FILE_CPU_PROFILE] if os.path.exists(filename): sys.stderr.write(" => Uploading the cpu profile...\n") self.post_file(rid, filename, Service.FILE_CPU_PROFILE, compress=False) sys.stderr.write(' ' + self.get_url('#/%s' % rid) + "\n") if Service.FILE_JIT_PROFILE in kwargs: filename = kwargs[Service.FILE_JIT_PROFILE] if os.path.exists(filename): sys.stderr.write(" => Uploading the jit log...\n") forest = parse_jitlog(filename) if forest.exception_raised(): sys.stderr.write(" error: %s\n" % forest.exception_raised()) # append source code to the binary forest.extract_source_code_lines() forest.copy_and_add_source_code_tags() filename = forest.filepath response = self.post_file(rid, filename, Service.FILE_JIT_PROFILE, compress=True) forest.unlink_jitlog() json = response.json() if 'jid' in json: url = self.get_url('#/%s/traces' % json['jid']) else: url = self.get_url('#/%s' % rid) sys.stderr.write(' ' + url + "\n") self.finalize_entry(rid)
def get_lines(self, file_name): line_number = [] print file_name f = parser.parse_jitlog(file_name) lSerializer = LogMetaSerializer() d = lSerializer.to_representation(f) tSerializer = TraceSerializer() f.extract_source_code_lines() for i in f.traces: print 'trace:' + str(i) + 'SSSSSSSSSSSSSSSS' dic = tSerializer.to_representation(f.traces[i]) code_dic = dic['code'] print code_dic for key in code_dic: code_file_dic = code_dic[key] for key1 in code_file_dic: if key1 not in line_number: line_number.append(key1) return len(line_number)
def post(self, kwargs): sys.stderr.write("Uploading to %s...\n" % self.host) argv = kwargs.get('argv', '-') vm = kwargs.get('VM','unknown') rid = self.post_new_entry({'argv': argv, 'VM': vm}) if rid is None: raise ServiceException("could not create meta data for profiles") if Service.FILE_CPU_PROFILE in kwargs: filename = kwargs[Service.FILE_CPU_PROFILE] if os.path.exists(filename): sys.stderr.write(" => Uploading the cpu profile...\n") self.post_file(rid, filename, Service.FILE_CPU_PROFILE, compress=False) sys.stderr.write(' ' + self.get_url('#/%s' % rid) + "\n") if Service.FILE_JIT_PROFILE in kwargs: filename = kwargs[Service.FILE_JIT_PROFILE] if os.path.exists(filename): sys.stderr.write(" => Uploading the jit log...\n") forest = parse_jitlog(filename) if forest.exception_raised(): sys.stderr.write(" error: %s\n" % forest.exception_raised()) # append source code to the binary forest.extract_source_code_lines() forest.copy_and_add_source_code_tags() filename = forest.filepath response = self.post_file(rid, filename, Service.FILE_JIT_PROFILE, compress=True) forest.unlink_jitlog() json = response.json() if 'jid' in json: url = self.get_url('#/%s/traces' % json['jid']) else: url = self.get_url('#/%s' % rid) sys.stderr.write(' ' + url + "\n") self.finalize_entry(rid)
def get_traces_dir(self, file_name, result_dir): liine_number = [] print file_name f = parser.parse_jitlog(file_name) lSerializer = LogMetaSerializer() d = lSerializer.to_representation(f) tSerializer = TraceSerializer() f.extract_source_code_lines() for i in f.traces: #print 'trace:' + str(i) + 'SSSSSSSSSSSSSSSS' dic = tSerializer.to_representation(f.traces[i]) code_dic = dic['code'] print dic #.keys() temp_trace = {} for key in code_dic: code_file_dic = code_dic[key] temp_trace[key] = code_file_dic.keys() for key in temp_trace: if key in result_dir.keys(): trace_list = result_dir[key] else: trace_list = [] temp = {} if len(temp_trace.keys()) > 1: temp['flag'] = 1 else: temp['flag'] = 0 temp['trace'] = temp_trace if temp not in trace_list: trace_list.append(temp) result_dir[key] = trace_list return result_dir
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!