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