|
12 | 12 |
|
13 | 13 | def main(*args, config_file_name: str = "", output_dir: str = "", web_port: int = 8080): |
14 | 14 | """Run benchmark with integrated web monitoring""" |
15 | | - |
| 15 | + |
16 | 16 | # Validate required arguments |
17 | 17 | if not output_dir: |
18 | 18 | print("Error: output_dir is required") |
19 | | - print("Usage: uv run main.py run-gaia-with-monitor --output_dir=path --config_file_name=name") |
| 19 | + print( |
| 20 | + "Usage: uv run main.py run-gaia-with-monitor --output_dir=path --config_file_name=name" |
| 21 | + ) |
20 | 22 | return 1 |
21 | | - |
| 23 | + |
22 | 24 | # Create output directory if it doesn't exist |
23 | 25 | os.makedirs(output_dir, exist_ok=True) |
24 | | - |
| 26 | + |
25 | 27 | print("=" * 50) |
26 | 28 | print("Benchmark Runner with Monitor") |
27 | 29 | print("=" * 50) |
28 | 30 | print(f"Output directory: {output_dir}") |
29 | 31 | print(f"Config name: {config_file_name}") |
30 | 32 | print(f"Web port: {web_port}") |
31 | 33 | print("=" * 50) |
32 | | - |
| 34 | + |
33 | 35 | # Global variables for process management |
34 | 36 | benchmark_process: Optional[subprocess.Popen] = None |
35 | 37 | monitor_process: Optional[subprocess.Popen] = None |
36 | | - |
| 38 | + |
37 | 39 | def cleanup_processes(): |
38 | 40 | """Clean up running processes""" |
39 | 41 | print("\nShutting down processes...") |
40 | | - |
| 42 | + |
41 | 43 | if benchmark_process and benchmark_process.poll() is None: |
42 | 44 | print(f"Stopping benchmark (PID: {benchmark_process.pid})...") |
43 | 45 | benchmark_process.terminate() |
44 | 46 | try: |
45 | 47 | benchmark_process.wait(timeout=5) |
46 | 48 | except subprocess.TimeoutExpired: |
47 | 49 | benchmark_process.kill() |
48 | | - |
| 50 | + |
49 | 51 | if monitor_process and monitor_process.poll() is None: |
50 | 52 | print(f"Stopping monitor (PID: {monitor_process.pid})...") |
51 | 53 | monitor_process.terminate() |
52 | 54 | try: |
53 | 55 | monitor_process.wait(timeout=5) |
54 | 56 | except subprocess.TimeoutExpired: |
55 | 57 | monitor_process.kill() |
56 | | - |
| 58 | + |
57 | 59 | print("Cleanup complete.") |
58 | | - |
| 60 | + |
59 | 61 | def signal_handler(signum, frame): |
60 | 62 | """Handle Ctrl+C gracefully""" |
61 | 63 | cleanup_processes() |
62 | 64 | sys.exit(0) |
63 | | - |
| 65 | + |
64 | 66 | # Set up signal handlers |
65 | 67 | signal.signal(signal.SIGINT, signal_handler) |
66 | 68 | signal.signal(signal.SIGTERM, signal_handler) |
67 | | - |
| 69 | + |
68 | 70 | try: |
69 | 71 | # Start benchmark |
70 | 72 | print("Starting benchmark...") |
71 | 73 | benchmark_cmd = [ |
72 | | - "uv", "run", "main.py", "common-benchmark", |
| 74 | + "uv", |
| 75 | + "run", |
| 76 | + "main.py", |
| 77 | + "common-benchmark", |
73 | 78 | f"--config_file_name={config_file_name}", |
74 | | - f"output_dir={output_dir}" |
| 79 | + f"output_dir={output_dir}", |
75 | 80 | ] |
76 | 81 | benchmark_process = subprocess.Popen(benchmark_cmd) |
77 | 82 | print(f"Benchmark started with PID: {benchmark_process.pid}") |
78 | | - |
| 83 | + |
79 | 84 | # Wait a moment for benchmark to initialize |
80 | 85 | time.sleep(3) |
81 | | - |
| 86 | + |
82 | 87 | # Start monitor |
83 | 88 | print("Starting web monitor...") |
84 | 89 | monitor_cmd = [ |
85 | | - "uv", "run", "utils/progress_check/gaia_web_monitor.py", |
| 90 | + "uv", |
| 91 | + "run", |
| 92 | + "utils/progress_check/gaia_web_monitor.py", |
86 | 93 | output_dir, |
87 | | - f"--web-port={web_port}" |
| 94 | + f"--web-port={web_port}", |
88 | 95 | ] |
89 | 96 | monitor_process = subprocess.Popen(monitor_cmd) |
90 | 97 | print(f"Monitor started with PID: {monitor_process.pid}") |
91 | 98 | print(f"Web dashboard available at: http://localhost:{web_port}") |
92 | | - |
| 99 | + |
93 | 100 | print("\n" + "=" * 50) |
94 | 101 | print("Both processes are running!") |
95 | 102 | print("Press Ctrl+C to stop both processes") |
96 | 103 | print("Monitor will continue running even if benchmark finishes") |
97 | 104 | print("=" * 50) |
98 | | - |
| 105 | + |
99 | 106 | # Monitor the processes |
100 | 107 | while True: |
101 | 108 | time.sleep(5) |
102 | | - |
| 109 | + |
103 | 110 | # Check if benchmark process is still running |
104 | 111 | if benchmark_process and benchmark_process.poll() is not None: |
105 | 112 | print("Benchmark process ended") |
106 | 113 | benchmark_process = None |
107 | | - |
| 114 | + |
108 | 115 | # Check if monitor process is still running |
109 | 116 | if monitor_process and monitor_process.poll() is not None: |
110 | 117 | print("Monitor process died unexpectedly. Restarting...") |
111 | 118 | monitor_process = subprocess.Popen(monitor_cmd) |
112 | 119 | print(f"Monitor restarted with PID: {monitor_process.pid}") |
113 | | - |
| 120 | + |
114 | 121 | except KeyboardInterrupt: |
115 | 122 | cleanup_processes() |
116 | | - |
| 123 | + |
117 | 124 | return 0 |
118 | 125 |
|
119 | 126 |
|
120 | 127 | if __name__ == "__main__": |
121 | 128 | import fire |
| 129 | + |
122 | 130 | fire.Fire(main) |
0 commit comments