Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make host:port for tracer configurable #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/starkware/cairo/lang/tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def trace_runner(runner):
trace = runner.relocated_trace

run_tracer(
"localhost", 8100,
TracerData(
program=runner.program,
memory=memory,
Expand All @@ -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__)))

Expand Down Expand Up @@ -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()

Expand All @@ -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.")

Expand All @@ -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


Expand Down
15 changes: 13 additions & 2 deletions src/starkware/cairo/lang/vm/cairo_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down