-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel-benchmark.sh
executable file
·91 lines (77 loc) · 2.63 KB
/
kernel-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
#!/bin/bash
# Number of builds to average
NUM_BUILDS=32
INTERRUPTED=false
BUILD_COUNT=0
RUNS=0
MASTER="master"
if [ $(cat /etc/os-release | grep VERSION_CODENAME | grep -c jammy) -gt 0 ]; then
MASTER="master_jammy"
fi
PKG_LIST=("git" "build-essential" "debhelper" "devscripts" "gcc-12" "makedumpfile" "libcap-dev"
"libelf-dev" "libnewt-dev" "libiberty-dev" "default-jdk-headless" "java-common"
"libdw-dev" "libpci-dev" "pkg-config" "python3-dev" "flex" "bison" "libunwind8-dev"
"liblzma-dev" "libssl-dev" "libaudit-dev" "bc" "libudev-dev" "uuid-dev" "libnuma-dev"
"dkms" "pahole" "dwarves" "clang-15" "libclang1-15" "rustc" "rust-src" "bindgen"
"libstdc++-12-dev" "xmlto" "sharutils" "asciidoc" "python3-docutils" "gawk")
./install.sh "${PKG_LIST[@]}"
# Path to the kernel source directory
KERNEL_DIR=~/linux
if [ ! -d "$KERNEL_DIR" ]; then
pushd ~/
git clone --branch $MASTER https://github.com/pop-os/linux.git
popd
fi
if [ -f ~/.runs ]; then
RUNS=$(cat ~/.runs)
fi
RUNS=$((RUNS+1))
echo $RUNS > ~/.runs
# Log file for build times
LOG_FILE="${HOME}/kernel_build_times-${RUNS}.log"
if [ -f "$LOG_FILE" ]; then
rm -rvf "$LOG_FILE"
fi
ctrl_c() {
if ! $INTERRUPTED; then
# Calculate the average build time
average_time=$(awk '{sum += $1} END {print sum/NR}' $LOG_FILE)
echo "Average build time over $BUILD_COUNT builds: $average_time seconds"
echo "Average build time over $BUILD_COUNT builds: $average_time seconds" >> $LOG_FILE
fi
INTERRUPTED=true
}
echo "Starting kernel build benchmark..."
trap ctrl_c INT TERM EXIT
# Function to clean and build the kernel
build_kernel() {
# Make sure we're in the kernel directory
local iteration=$1
cd $KERNEL_DIR
make mrproper
git reset --hard HEAD
git restore .
# Build the kernel and measure the time
TIMEFORMAT=%R # Set time format to output seconds only
local build_time=$( { time ./rebuild.sh > /dev/null 2>&1; } 2>&1 )
if ! $INTERRUPTED; then
echo "Build $iteration took $build_time seconds"
echo "$build_time" >> $LOG_FILE
fi
}
# Perform the builds
for i in $(seq 1 $NUM_BUILDS); do
echo "Building kernel: Attempt $i of $NUM_BUILDS"
build_kernel $i
if $INTERRUPTED; then
break
fi
BUILD_COUNT=$i
done
if ! $INTERRUPTED; then
# Calculate the average build time
average_time=$(awk '{sum += $1} END {print sum/NR}' $LOG_FILE)
echo "Average build time over $BUILD_COUNT builds: $average_time seconds"
echo "Average build time over $BUILD_COUNT builds: $average_time seconds" >> $LOG_FILE
INTERRUPTED=true
fi