Skip to content

Instantly share code, notes, and snippets.

@roworu
Last active December 22, 2023 09:43
Show Gist options
  • Save roworu/e8876e567244ea06417aa8784bcc0a49 to your computer and use it in GitHub Desktop.
Save roworu/e8876e567244ea06417aa8784bcc0a49 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create the results file with current date
current_dir=$(pwd "$0")
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
results_file="${current_dir}/results_${timestamp}.txt"
collect_results() {
# Get system information
kernel_version=$(uname -r)
cpu_name=$(cat /proc/cpuinfo | grep "model name" | uniq | cut -d ":" -f 2 | sed 's/^[ \t]*//')
memory=$(free -h | awk 'NR==2{print $2}')
cores=$(nproc)
echo "System Information:" > "$results_file"
echo "Kernel Version: $kernel_version" >> "$results_file"
echo "CPU Name: $cpu_name" >> "$results_file"
echo "Memory: $memory" >> "$results_file"
echo "Number of Cores: $cores" >> "$results_file"
echo "---------------------------------" >> "$results_file"
echo "" >> "$results_file"
# Append iteration times and average times to the results file
echo "Iteration Times:" >> "$results_file"
for ((i=0; i<num_iterations; i++))
do
echo "Iteration $((i+1)):" >> "$results_file"
echo "Extraction Time: ${extract_times[$i]} seconds" >> "$results_file"
echo "Build Time: ${build_times[$i]} seconds" >> "$results_file"
echo "" >> "$results_file"
done
echo "---------------------------------" >> "$results_file"
echo "Average Times:" >> "$results_file"
echo "Average Extraction Time: ${average_extract_time} seconds" >> "$results_file"
echo "Average Build Time: ${average_build_time} seconds" >> "$results_file"
}
# Number of iterations for compiling the kernel
declare -a extract_times
declare -a build_times
num_iterations=3
# Parse command-line options
while getopts ":n:" opt; do
case $opt in
n)
num_iterations=$OPTARG
echo "Using num_iterations = $OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG. Usage: $0 -n <num_iterations>" >&2
exit 1
;;
esac
done
# Download the kernel (if not downloaded already)
if [ ! -f "${current_dir}/linux-5.15.144.tar.xz" ]; then
echo "Downloading ..."
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.144.tar.xz -O ${current_dir}/linux-5.15.144.tar.xz
fi
for ((i=0; i<num_iterations; i++))
do
# Start time after downloading
extract_start_time=$(date +%s)
tar -xvf ${current_dir}/linux-5.15.144.tar.xz &> /dev/null
extract_end_time=$(date +%s)
extract_duration=$((extract_end_time - extract_start_time))
cd ${current_dir}/linux-5.15.144
make defconfig &> /dev/null
# Measure time to compile (excluding download and extraction times)
compile_start_time=$(date +%s)
make -j"$(nproc)" &> /dev/null
compile_end_time=$(date +%s)
compile_duration=$((compile_end_time - compile_start_time))
# Delete build folder after each iteration
rm -rf ${current_dir}/linux-5.15.144
cd $current_dir
# Record times for download, extraction, and build
extract_times[$i]=$extract_duration
build_times[$i]=$compile_duration
# Calculate average times
total_extract_time=0
total_build_time=0
for ((j=0; j<=i; j++))
do
total_extract_time=$((total_extract_time + extract_times[$j]))
total_build_time=$((total_build_time + build_times[$j]))
done
average_extract_time=$((total_extract_time / (i+1)))
average_build_time=$((total_build_time / (i+1)))
done
collect_results
echo "Results saved to: $results_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment