Last active
March 30, 2022 20:20
-
-
Save wcoastsands/6534ff4aca83963cca3a8a57559c2457 to your computer and use it in GitHub Desktop.
Thermal bench test for Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOURCE="${BASH_SOURCE[0]}" | |
# Resolve $SOURCE until the file is no longer a symlink. | |
while [ -h "$SOURCE" ]; do | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
SOURCE="$(readlink "$SOURCE")" | |
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" | |
# If $SOURCE was a relative symlink, we need to resolve it | |
# relative to the path where the symlink file was located. | |
done | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
# Default interval time in seconds. | |
INTERVAL=5 | |
# Regular expression to validate argument as a number. | |
REGEX='^[0-9]+([.][0-9]+)?$' | |
if [[ $1 =~ $REGEX ]]; then | |
INTERVAL=$1 | |
elif [ ! -z "$1" ]; then | |
echo "Iteratively reports the thermal status of the system." | |
echo | |
echo "Usage:" | |
echo " ./rpi-thermal-monitor.sh [help|interval]" | |
echo | |
echo "Examples:" | |
echo " ./rpi-thermal-monitor.sh" | |
echo " ./rpi-thermal-monitor.sh 10" | |
echo " ./rpi-thermal-monitor.sh 1.5" | |
echo " ./rpi-thermal-monitor.sh help" | |
echo | |
echo "Options:" | |
echo " help Displays this documentation." | |
echo " interval Sets the interval time in seconds between status updates." | |
echo | |
echo "By default, the update interval time is set to $INTERVAL seconds." | |
echo | |
echo "See 'rpi-thermal-status.sh help' for more details." | |
exit | |
fi | |
clear | |
while true; do | |
$DIR/rpi-thermal-status.sh inline | |
echo -ne "-- Press [CTRL+C] to quit.\r" | |
sleep $INTERVAL | |
done | |
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CPU=$(</sys/class/thermal/thermal_zone0/temp) | |
CPU="temp=$(echo "scale=1; $CPU/1000" | bc)'C" | |
GPU=$(/opt/vc/bin/vcgencmd measure_temp) | |
FREQUENCY=$(/opt/vc/bin/vcgencmd measure_clock arm) | |
THROTTLED=$(/opt/vc/bin/vcgencmd get_throttled) | |
if [ "$1" = "inline" ]; then | |
echo "$(date) @ $(hostname) cpu_$CPU gpu_$GPU $FREQUENCY $THROTTLED" | |
elif [ -n "$1" ]; then | |
echo "Reports the current temperatures, frequency, and throttled state of the system." | |
echo | |
echo "Usage:" | |
echo " ./rpi-thermal-status.sh [help|inline]" | |
echo | |
echo "Examples:" | |
echo " ./rpi-thermal-status.sh" | |
echo " ./rpi-thermal-status.sh inline" | |
echo " ./rpi-thermal-status.sh help" | |
echo | |
echo "Options:" | |
echo " help Displays this documentation." | |
echo " inline Generates output using a single-line format." | |
echo | |
echo "By default, output is generated in a multi-line format. Use the \"inline\" option" | |
echo "to generate output in a single-line format instead." | |
echo | |
echo "The throttled state of the system is described as a bit pattern." | |
echo | |
echo "Bit Meaning" | |
echo " 0 Under-voltage detected" | |
echo " 1 Arm frequency capped" | |
echo " 2 Currently throttled" | |
echo " 3 Soft temperature limit active" | |
echo " 16 Under-voltage has occurred" | |
echo " 17 Arm frequency capped has occurred" | |
echo " 18 Throttling has occurred" | |
echo " 19 Soft temperature limit has occurred" | |
echo | |
echo "For example:" | |
echo " The hex value 0x60002 equates to 0110 0000 0000 0000 0010 in binary." | |
echo " The active bits (written as 1) are at binary index 1, 17, and 18 (right to left)." | |
echo " Therefore, in this example the arm frequency is currently capped (1), " | |
echo " and has previously been both capped (17) and throttled (18)." | |
else | |
echo "$(date) @ $(hostname)" | |
echo "----------------------------------" | |
echo "CPU Temp => $CPU" | |
echo "GPU Temp => $GPU" | |
echo "Frequency => $FREQUENCY" | |
echo "Throttled => $THROTTLED" | |
fi | |
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOURCE="${BASH_SOURCE[0]}" | |
# Resolve $SOURCE until the file is no longer a symlink. | |
while [ -h "$SOURCE" ]; do | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
SOURCE="$(readlink "$SOURCE")" | |
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" | |
# If $SOURCE was a relative symlink, we need to resolve it | |
# relative to the path where the symlink file was located. | |
done | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
# The number of tests to perform. | |
COUNT=8 | |
# Regular expression to validate argument as an interger. | |
REGEX='^[0-9]+$' | |
if [[ $1 =~ $REGEX ]]; then | |
COUNT=$1 | |
elif [ -n "$1" ]; then | |
echo "Performs a series of bench tests, and reports the thermal status after each iteration." | |
echo | |
echo "Usage:" | |
echo " ./rpi-thermal-test.sh [help|count]" | |
echo | |
echo "Examples:" | |
echo " ./rpi-thermal-test.sh" | |
echo " ./rpi-thermal-test.sh 3" | |
echo " ./rpi-thermal-test.sh help" | |
echo | |
echo "Options:" | |
echo " help Displays this documentation." | |
echo " count Sets the number of bench tests to perform." | |
echo | |
echo "By default, a count of $COUNT bench tests will be performed. The results at line 0 are initial readings " | |
echo "to establish a baseline for comparison with results of following bench tests." | |
echo | |
echo "See 'rpi-thermal-status.sh help' for more details." | |
exit | |
fi | |
echo "Running thermal bench test..." | |
uptime | |
echo "0. $($DIR/rpi-thermal-status.sh inline)" | |
for i in $(seq 1 $COUNT) | |
do | |
echo -ne "-- Performing test $i of $COUNT. Please wait, or press [CTRL+C] to quit.\r" | |
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run >/dev/null 2>&1 | |
echo "$i. $($DIR/rpi-thermal-status.sh inline)" | |
done | |
uptime | |
echo "Done." | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output from
rpi-thermal-test.sh
when run on a Kano Computer Kit Touch with Raspberry Pi model 3B:In this sample, the throttled status indicates frequency capping occurred during the test, with throttling toward the end, while also indicating that reports of under-voltage, arm frequency capping, and throttling had previously occurred. The results at line 0 are initial readings to establish a baseline for the following bench tests.
Use the
help
option to view documentation:See
vcgencmd
documentation for more info.