-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrun_benchmark.sh
More file actions
executable file
·67 lines (58 loc) · 2.1 KB
/
run_benchmark.sh
File metadata and controls
executable file
·67 lines (58 loc) · 2.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
#!/usr/bin/env bash
# Run a Krasis benchmark and exit (don't start the server).
# Usage: ./run_benchmark.sh <server.py args...>
#
# Runs server.py --benchmark, waits for benchmark completion,
# then cleanly shuts down (SIGTERM first, then SIGKILL).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON="/home/main/miniconda3/envs/krasis/bin/python"
if [[ ! -f "$PYTHON" ]]; then
echo "ERROR: Python not found at $PYTHON"
echo "See DEV.md for environment setup."
exit 1
fi
LOGFILE=$(mktemp /tmp/krasis_bench_XXXXXX.log)
echo "Benchmark output: $LOGFILE"
# Cleanup function to ensure process is killed on script exit
cleanup() {
if [[ -n "${PID:-}" ]] && kill -0 "$PID" 2>/dev/null; then
echo "Cleaning up benchmark process $PID..."
kill -TERM "$PID" 2>/dev/null || true
# Wait up to 5 seconds for graceful shutdown
for i in $(seq 1 10); do
kill -0 "$PID" 2>/dev/null || break
sleep 0.5
done
# Force kill if still running
if kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID" 2>/dev/null || true
fi
wait "$PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
# Run server with --benchmark, capture output
"$PYTHON" -m krasis.server --benchmark "$@" > >(tee "$LOGFILE") 2>&1 &
PID=$!
echo "Server PID: $PID"
# Wait for benchmark to complete (look for "Benchmark archived" or server start)
while kill -0 "$PID" 2>/dev/null; do
if grep -q "Benchmark archived to\|starting server on" "$LOGFILE" 2>/dev/null; then
echo ""
echo "Benchmark complete. Stopping server..."
# SIGTERM triggers our cleanup handler in server.py
kill -TERM "$PID" 2>/dev/null || true
wait "$PID" 2>/dev/null || true
PID="" # Prevent cleanup trap from double-killing
echo "Done. Full output in: $LOGFILE"
exit 0
fi
sleep 2
done
# Process exited on its own (error or benchmark completed)
EXITCODE=$?
PID="" # Prevent cleanup trap from killing dead process
echo "Process exited with code $EXITCODE"
echo "Full output in: $LOGFILE"
exit $EXITCODE