()
| 12 | |
| 13 | |
| 14 | def main(): |
| 15 | parser = argparse.ArgumentParser( |
| 16 | prog="megengine.tools.svg_viewer", |
| 17 | description="View SVG Graph produced bt megengine profiler", |
| 18 | ) |
| 19 | parser.add_argument("-p", "--port", type=int, default=8000, help="server port") |
| 20 | parser.add_argument( |
| 21 | "-a", "--address", type=str, default="localhost", help="server address" |
| 22 | ) |
| 23 | args = parser.parse_args() |
| 24 | address = args.address |
| 25 | port = args.port |
| 26 | src_filename = "svg_viewer.html" |
| 27 | dst_filename = "index.html" |
| 28 | src_path = os.path.join(os.path.dirname(__file__), src_filename) |
| 29 | url = "http://{}:{}/{}".format("localhost", port, dst_filename) |
| 30 | ssh_fwd_cmd = "ssh -L {}:localhost:{} <remote ip>".format(port, port) |
| 31 | with tempfile.TemporaryDirectory() as serve_dir: |
| 32 | dst_path = os.path.join(serve_dir, dst_filename) |
| 33 | os.symlink(src_path, dst_path) |
| 34 | os.chdir(serve_dir) |
| 35 | get_logger().info("cd to serve directory: {}, starting".format(serve_dir)) |
| 36 | server = http.server.HTTPServer( |
| 37 | (address, port), http.server.SimpleHTTPRequestHandler |
| 38 | ) |
| 39 | get_logger().info( |
| 40 | "server started, please visit '{}' to watch profiling result".format(url) |
| 41 | ) |
| 42 | get_logger().info( |
| 43 | "if you are in remote environment, use '{}' to forward port to local".format( |
| 44 | ssh_fwd_cmd |
| 45 | ) |
| 46 | ) |
| 47 | try: |
| 48 | server.serve_forever() |
| 49 | except KeyboardInterrupt: |
| 50 | get_logger().info("server exiting") |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
no test coverage detected