diff --git a/src/starkware/cairo/lang/tracer/tracer.py b/src/starkware/cairo/lang/tracer/tracer.py index 76b4aa20..ef091d4f 100755 --- a/src/starkware/cairo/lang/tracer/tracer.py +++ b/src/starkware/cairo/lang/tracer/tracer.py @@ -26,6 +26,7 @@ def trace_runner(runner): trace = runner.relocated_trace run_tracer( + "localhost", 8100, TracerData( program=runner.program, memory=memory, @@ -41,7 +42,7 @@ def server_bind(self): self.socket.bind(self.server_address) -def run_tracer(tracer_data: TracerData): +def run_tracer(host: str, port: int, tracer_data: TracerData): # Change directory for the SimpleHTTPRequestHandler. os.chdir(os.path.abspath(os.path.dirname(__file__))) @@ -92,18 +93,17 @@ def write_json(self, json_obj): # Request was canceled. pass - def start_server(): - port = 8100 + def start_server(host: str, port: int): while True: try: - return SimpleTCPServer(("localhost", port), Handler) + return SimpleTCPServer((host, port), Handler) except OSError: pass # port was not available. Try the next one. port += 1 - httpd = start_server() - print("Running tracer on http://localhost:%d/" % httpd.server_address[1]) + httpd = start_server(host, port) + print(f"Running tracer on http://{httpd.server_address[0]}:{httpd.server_address[1]}/") print() httpd.serve_forever() @@ -117,6 +117,8 @@ def main(): ) parser.add_argument("--memory", type=str, required=True, help="A path to the memory file.") parser.add_argument("--trace", type=str, required=True, help="A path to the trace file.") + parser.add_argument("--host", default="localhost", type=str, help="Host to serve on.") + parser.add_argument("--port", default="8100", type=int, help="Port to serve on.") parser.add_argument("--air_public_input", type=str, help="A path to the AIR public input file.") parser.add_argument("--debug_info", type=str, help="A path to the run time debug info file.") @@ -130,7 +132,7 @@ def main(): debug_info_path=args.debug_info, ) - run_tracer(tracer_data) + run_tracer(args.host, args.port, tracer_data) return 0 diff --git a/src/starkware/cairo/lang/vm/cairo_run.py b/src/starkware/cairo/lang/vm/cairo_run.py index 7327802e..b453dd0f 100644 --- a/src/starkware/cairo/lang/vm/cairo_run.py +++ b/src/starkware/cairo/lang/vm/cairo_run.py @@ -148,7 +148,11 @@ def main(): default="plain", help="The layout of the Cairo AIR.", ) - parser.add_argument("--tracer", action="store_true", help="Run the tracer.") + parser.add_argument( + "--tracer", + nargs='?', + const="localhost:8100", + help="Run the tracer at the given host and port (default: localhost:8100.") parser.add_argument( "--profile_output", type=str, @@ -432,7 +436,12 @@ def cairo_run(args): debug_info_file=debug_info_file, debug_info=runner.get_relocated_debug_info() ) - if args.tracer: + if args.tracer is not None: + # Tracer set, split host and port. + splits = args.tracer.split(':') + host = splits[0] + port = int(splits[1]) + CAIRO_TRACER = "starkware.cairo.lang.tracer.tracer" subprocess.call( list( @@ -444,6 +453,8 @@ def cairo_run(args): CAIRO_TRACER, f"--program={args.program.name}", f"--trace={trace_file.name}", + f"--host={host}", + f"--port={port}", f"--memory={memory_file.name}", f"--air_public_input={args.air_public_input.name}" if args.air_public_input