Fix empty cpu speed on windows

This commit is contained in:
Dylan Araps 2016-10-02 11:40:00 +11:00
parent 515f5e0fe6
commit d77bbd9619
1 changed files with 5 additions and 3 deletions

View File

@ -667,9 +667,10 @@ getcpu() {
"Linux" | "Windows") "Linux" | "Windows")
# Get cpu name # Get cpu name
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)" cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
cpu_dir="/sys/devices/system/cpu/cpu0/cpufreq"
# Get cpu speed # Get cpu speed
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then if [ -d "$cpu_dir" ]; then
case "$speed_type" in case "$speed_type" in
current) speed_type="scaling_cur_freq" ;; current) speed_type="scaling_cur_freq" ;;
min) speed_type="scaling_min_freq" ;; min) speed_type="scaling_min_freq" ;;
@ -680,8 +681,9 @@ getcpu() {
scaling_max) speed_type="scaling_max_freq" ;; scaling_max) speed_type="scaling_max_freq" ;;
esac esac
read -t 1 -r speed < \ # Fallback to cpuinfo_max_freq if $speed_type fails
/sys/devices/system/cpu/cpu0/cpufreq/${speed_type} read -t 1 -r speed < "${cpu_dir}/${speed_type}" || \
read -t 1 -r speed < "${cpu_dir}/cpuinfo_max_freq"
speed="$((speed / 100000))" speed="$((speed / 100000))"
else else