Rewrite cpu function to fix issues with speeds lowe than 1ghz

This commit is contained in:
dylan 2016-04-04 21:18:17 +10:00
parent 8d4057b1b8
commit d1c3f30ba7

View file

@ -941,42 +941,12 @@ getwmtheme () {
getcpu () {
case "$os" in
"Linux")
# Get cpu name
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
# Get cpu speed
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
case "$speed_type" in
current) speed_type="scaling_cur_freq" ;;
min) speed_type="scaling_min_freq" ;;
max) speed_type="scaling_max_freq" ;;
bios) speed_type="bios_limit" ;;
scaling_current) speed_type="scaling_cur_freq" ;;
scaling_min) speed_type="scaling_min_freq" ;;
scaling_max) speed_type="scaling_max_freq" ;;
esac
read -r speed < \
/sys/devices/system/cpu/cpu0/cpufreq/${speed_type}
speed=$((speed / 100000))
else
speed=$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
speed=$((speed / 100))
fi
speed=${speed:0:1}.${speed:1}
cpu="$cpu @ ${speed}GHz"
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
;;
"Mac OS X")
cpu="$(sysctl -n machdep.cpu.brand_string)"
cores=$(sysctl -n hw.ncpu)
;;
*"BSD" | "Windows")
"Linux" | *"BSD" | "Windows")
case "$distro" in
"OpenBSD"* | "FreeBSD"*)
# Get cpu name
@ -993,28 +963,46 @@ getcpu () {
cores=$(sysctl -n hw.ncpu)
;;
"NetBSD"* | "Windows"*)
*)
# Get cpu name
cpu="$(grep -F 'model name' /proc/cpuinfo)"
cpu=${cpu/model name*: }
cpu=${cpu/ @*}
cpu=${cpu// }
cpu=${cpu% }
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
# Get cpu speed
speed="$(grep -F 'cpu MHz' /proc/cpuinfo)"
speed=${speed/cpu MHz*: }
speed=${speed/\.}
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
case "$speed_type" in
current) speed_type="scaling_cur_freq" ;;
min) speed_type="scaling_min_freq" ;;
max) speed_type="scaling_max_freq" ;;
bios) speed_type="bios_limit" ;;
scaling_current) speed_type="scaling_cur_freq" ;;
scaling_min) speed_type="scaling_min_freq" ;;
scaling_max) speed_type="scaling_max_freq" ;;
esac
read -r speed < \
/sys/devices/system/cpu/cpu0/cpufreq/${speed_type}
speed=$((speed / 100000))
else
speed=$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
case "$distro" in
"NetBSD"*) speed=$((speed / 10000)) ;;
*) speed=$((speed / 100)) ;;
esac
fi
# Fix for speeds under 1ghz
if [ -z "${speed:1}" ]; then
speed="0.${speed}"
else
speed=${speed:0:1}.${speed:1}
fi
case "$distro" in
"NetBSD"*) speed=$((speed / 10000)) ;;
"Windows"*) speed=$((speed / 100000)) ;;
esac
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
;;
esac
speed=${speed:0:1}.${speed:1}
cpu="$cpu @ ${speed}GHz"
;;
esac