From cabffca5108d9c1b32df117d1450930e698e0d1f Mon Sep 17 00:00:00 2001 From: aiminick Date: Sat, 3 Apr 2021 02:01:25 +0800 Subject: [PATCH] Create get_throttled.sh --- scripts/get_throttled.sh | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 scripts/get_throttled.sh diff --git a/scripts/get_throttled.sh b/scripts/get_throttled.sh new file mode 100644 index 0000000..a7e3a1e --- /dev/null +++ b/scripts/get_throttled.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +ISSUES_MAP=( \ + [0]="Under-voltage detected" \ + [1]="Arm frequency capped" \ + [2]="Currently throttled" + [3]="Soft temperature limit active" \ + [16]="Under-voltage has occurred" \ + [17]="Arm frequency capping has occurred" \ + [18]="Throttling has occurred" \ + [19]="Soft temperature limit has occurred") + +HEX_BIN_MAP=( \ + ["0"]="0000" \ + ["1"]="0001" \ + ["2"]="0010" \ + ["3"]="0011" \ + ["4"]="0100" \ + ["5"]="0101" \ + ["6"]="0110" \ + ["7"]="0111" \ + ["8"]="1000" \ + ["9"]="1001" \ + ["A"]="1010" \ + ["B"]="1011" \ + ["C"]="1100" \ + ["D"]="1101" \ + ["E"]="1110" \ + ["F"]="1111" \ +) + +THROTTLED_OUTPUT=$(vcgencmd get_throttled) +IFS='x' +read -a strarr <<< "$THROTTLED_OUTPUT" +THROTTLED_CODE_HEX=${strarr[1]} + +# Display current issues +echo "Current issues:" +CURRENT_HEX=${THROTTLED_CODE_HEX:4:1} +CURRENT_BIN=${HEX_BIN_MAP[$CURRENT_HEX]} +if [ $CURRENT_HEX = "0" ]; then + echo "No throttling issues detected." +else + bit_n=0 + for (( i=${#CURRENT_BIN}-1; i>=0; i--)); do + if [ "${CURRENT_BIN:$i:1}" = "1" ]; then + echo "~ ${ISSUES_MAP[$bit_n]}" + bit_n=$((bit_n+1)) + fi + done +fi + +echo "" + +# Display past issues +echo "Previously detected issues:" +PAST_HEX=${THROTTLED_CODE_HEX:0:1} +PAST_BIN=${HEX_BIN_MAP[$PAST_HEX]} +if [ $PAST_HEX = "0" ]; then + echo "No throttling issues detected." +else + bit_n=16 + for (( i=${#PAST_BIN}-1; i>=0; i--)); do + if [ "${PAST_BIN:$i:1}" = "1" ]; then + echo "~ ${ISSUES_MAP[$bit_n]}" + bit_n=$((bit_n+1)) + fi + done +fi