def test_enable(self): import _jitlog, struct tmpfile = open(self.tmpfilename, 'wb') fileno = tmpfile.fileno() _jitlog.enable(fileno) _jitlog.disable() # no need to clsoe tmpfile, it is done by jitlog with open(self.tmpfilename, 'rb') as fd: assert fd.read(1) == self.mark_header assert fd.read(2) == self.version assert bool(ord(fd.read(1))) == self.is_32bit strcount, = struct.unpack('<i', fd.read(4)) machine = fd.read(strcount) assert machine == self.machine # resoperations count, = struct.unpack('<h', fd.read(2)) opnames = set() for i in range(count): opnum = struct.unpack('<h', fd.read(2)) strcount, = struct.unpack('<i', fd.read(4)) opname = fd.read(strcount) opnames.append((opnum, opname)) for opnum, opname in opnames: # must be known resoperation assert opnum in self.resops # the name must equal assert self.resops[opnum] == opname
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(): args = vmprof.cli.parse_args(sys.argv[1:]) # None means default on this platform native = None if args.no_native: native = False if args.web: output_mode = OUTPUT_WEB elif args.output: output_mode = OUTPUT_FILE else: output_mode = OUTPUT_CLI if output_mode == OUTPUT_FILE: prof_file = args.output prof_name = prof_file.name else: prof_file = tempfile.NamedTemporaryFile(delete=False) prof_name = prof_file.name vmprof.enable(prof_file.fileno(), args.period, args.mem, args.lines, native=native) if args.jitlog and _jitlog: fd = os.open(prof_name + '.jit', os.O_WRONLY | os.O_TRUNC | os.O_CREAT) _jitlog.enable(fd) # invoke the user program: 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 # vmprof.disable() if args.jitlog and _jitlog: _jitlog.disable() prof_file.close() show_stats(prof_name, output_mode, args) if output_mode != OUTPUT_FILE: os.unlink(prof_name)
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!