This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark.sh
119 lines (92 loc) · 4.1 KB
/
benchmark.sh
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
#!/bin/bash
# Exit immediately on error
set -e
# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "yq could not be found. Please install yq."
exit 1
fi
# Path to the benchmark yml file
BENCHMARK_FILE=$1
if [ -z "$BENCHMARK_FILE" ]; then
echo "Usage: $0 <path_to_benchmark.yml>"
exit 1
fi
# Extract some root variables from the benchmark yml file
SPIN_DURATION=$(yq -r '.camera_spin_duration' "$BENCHMARK_FILE")
# Background load var
BACKGROUND_LOAD=$(yq -r '.background_load' "$BENCHMARK_FILE")
# Clone the repository
git clone https://github.com/sched-ext/scx.git /tmp/scx || true
# Create scx build target dir
# This means target is shared between builds (different schedulers, different branches)
# so dependencies are not built multiple times and time is saved...
export CARGO_TARGET_DIR=/tmp/scx_cargo_build_target
mkdir -p "$CARGO_TARGET_DIR"
# Zoom out max + it wakes device if it's kind of asleep
echo keydown pagedown | dotoolc && sleep 5 && echo keyup pagedown | dotoolc
# Read the benchmark.yml file and process each entry
yq -c '.jobs[]' "$BENCHMARK_FILE" | while read -r benchmark; do
# Extract reset_to, build directory, and build command
resetto=$(echo "$benchmark" | yq -r '.reset_to')
build_dir=$(echo "$benchmark" | yq -r '.build.dir')
build_cmd=$(echo "$benchmark" | yq -r '.build.cmd')
# Change to the temporary directory
cd "/tmp/scx"
# Fetch the latest changes
git fetch origin
# Handle PRs differently
if [[ "$resetto" =~ ^pr/[0-9]+$ ]]; then
PR_NUMBER=${resetto#pr/}
git fetch origin pull/$PR_NUMBER/head:pr-$PR_NUMBER
git reset --hard pr-$PR_NUMBER
else
git reset --hard "$resetto"
fi
# Extract Short Commit Hash
SCH=$(git --no-pager log -1 --pretty=format:"%h" --abbrev-commit)
# Enter the build directory
cd "$build_dir"
# Execute the build command
eval "$build_cmd"
# Iterate over each run
echo "$benchmark" | yq -c '.runs[]' | while read -r run; do
run_filename=$(echo "$run" | yq -r '.filename')
run_scheduler=$(echo "$run" | yq -r '.scheduler')
# Print information:
echo -e "\n>> Reset to: $resetto\n>> Scheduler: $run_scheduler\n>> background_load: $BACKGROUND_LOAD"
git --no-pager log -1 --pretty=format:">> Full commit hash: %H%n>> Short commit hash: %h%n>> Commit message: %s%n" --abbrev-commit
# Template out filename
run_filename=$(echo "$run_filename" | sed "s/__SCH__/$SCH/g")
# Execute scheduler in the background
if [ -n "$run_scheduler" ] && [ "$run_scheduler" != "null" ]; then
eval "sudo $CARGO_TARGET_DIR/$run_scheduler" &
fi
# Execute background load command in the background
if [ -n "$BACKGROUND_LOAD" ] && [ "$BACKGROUND_LOAD" != "null" ]; then
eval "$BACKGROUND_LOAD" &
fi
######################################################
# Record benchmark data
sudo kill -CONT $(pgrep -f 'bg3.exe') # Resume the game
sleep 1
echo keydown shift+f2 | dotoolc && sleep 0.2 && echo keyup shift+f2 | dotoolc # Start recording
echo keydown delete | dotoolc && sleep $SPIN_DURATION && echo keyup delete | dotoolc # Rotate camera
echo keydown shift+f2 | dotoolc && sleep 0.2 && echo keyup shift+f2 | dotoolc # Stop recording
sleep 1
sudo kill -STOP $(pgrep -f 'bg3.exe') # Pause the game
sudo chmod -R 777 /tmp/mangohud_logs/
rm -rf /tmp/mangohud_logs/*summary.csv
mv /tmp/mangohud_logs/bg3_*.csv /tmp/mangohud_logs/$run_filename
######################################################
# Kill background load command
if [ -n "$BACKGROUND_LOAD" ] && [ "$BACKGROUND_LOAD" != "null" ]; then
sudo pkill -f "$BACKGROUND_LOAD" || true
fi
# Kill the scheduler that was running in the background
if [ -n "$run_scheduler" ] && [ "$run_scheduler" != "null" ]; then
sudo pkill -f "$run_scheduler" || true
sleep 5 # Wait for scheduler to fully unregister
fi
done
done