def upload(name, filename, host, auth): service = Service(host, auth) interpname = platform.python_implementation() service.post({Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': name, 'VM': interpname })
def upload_stats(filename, web_url, web_auth): sys.stderr.write("Compiling and uploading to {}...\n".format(web_url)) service = Service(web_url, web_auth) service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + ".jit", "VM": platform.python_implementation(), })
def show_stats(filename, output_mode, args): if output_mode == OUTPUT_FILE: return elif output_mode == OUTPUT_CLI: stats = vmprof.read_profile(filename) vmprof.cli.show(stats) elif output_mode == OUTPUT_WEB: host, auth = args.web_url, args.web_auth service = Service(host, auth) service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': ' '.join(sys.argv[:]), 'VM': platform.python_implementation() })
def main(): parser = argparse.ArgumentParser() parser.add_argument("profile") parser.add_argument("--web-url", default='http://vmprof.com', help='Target host') parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server') args = parser.parse_args() host, auth = args.web_url, args.web_auth filename = args.profile service = Service(host, auth) interpname = platform.python_implementation() service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': interpname + ' -m vmprof.upload ' + filename, 'VM': interpname })
def show_stats(filename, output_mode, args): if output_mode == OUTPUT_FILE: return elif output_mode == OUTPUT_CLI: stats = vmprof.read_profile(filename) vmprof.cli.show(stats) elif output_mode == OUTPUT_WEB: host, auth = args.web_url, args.web_auth service = Service(host, auth) service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': ' '.join(sys.argv[:]), 'VM': platform.python_implementation() })
def main(): parser = argparse.ArgumentParser() parser.add_argument("profile") parser.add_argument("--web-url", default='http://vmprof.com', help='Target host') parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server') args = parser.parse_args() host, auth = args.web_url, args.web_auth filename = args.profile service = Service(host, auth) interpname = platform.python_implementation() service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': interpname + ' -m vmprof.upload ' + filename, 'VM': interpname })
def profile_vmprof(name, env): if vmprof is None: print('vmprof not found. Please install vmprof and try again.') return func = create_bench(name, env) gc.collect() # # Based on: https://github.com/vmprof/vmprof-python/blob/master/vmprof/__main__.py # prof_file = tempfile.NamedTemporaryFile(delete=False) filename = prof_file.name vmprof.enable(prof_file.fileno()) try: for __ in range(1000000): func() except BaseException as e: if not isinstance(e, (KeyboardInterrupt, SystemExit)): raise vmprof.disable() service = Service('vmprof.com') service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': ' '.join(sys.argv[:]), 'VM': platform.python_implementation(), }) prof_file.close()
def profile_vmprof(name, env): if vmprof is None: print('vmprof not found. Please install vmprof and try again.') return func = create_bench(name, env) gc.collect() # # Based on: https://github.com/vmprof/vmprof-python/blob/master/vmprof/__main__.py # prof_file = tempfile.NamedTemporaryFile(delete=False) filename = prof_file.name vmprof.enable(prof_file.fileno()) try: for __ in range(1000000): func() except BaseException as e: if not isinstance(e, (KeyboardInterrupt, SystemExit)): raise vmprof.disable() service = Service('vmprof.com') service.post({ Service.FILE_CPU_PROFILE: filename, Service.FILE_JIT_PROFILE: filename + '.jit', 'argv': ' '.join(sys.argv[:]), 'VM': platform.python_implementation(), }) prof_file.close()
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!