Fix usage on BSD

This commit is contained in:
Dylan Araps 2016-06-13 21:21:32 +10:00
parent d3c2216f48
commit 1be5423b1d
1 changed files with 11 additions and 16 deletions

View File

@ -1161,28 +1161,23 @@ getcpu () {
getcpu_usage () {
case "$os" in
"Linux" | "Mac OS X" | "iPhone OS")
# Get cores if unset
if [ -z "$cores" ]; then
case "$os" in
"Linux") cores="$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)" ;;
"Mac OS X") cores="$(sysctl -n hw.ncpu)" ;;
esac
fi
cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')"
cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))"
;;
"Windows")
cpu_usage="$(wmic cpu get loadpercentage /value)"
cpu_usage="${cpu_usage/LoadPercentage'='}"
cpu_usage="${cpu_usage//[[:space:]]}"
;;
"BSD")
# BSD support coming soon.
return
"Linux" | "Mac OS X" | "iPhone OS" | "BSD")
# Get cores if unset
if [ -z "$cores" ]; then
case "$os" in
"Linux") cores="$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)" ;;
"Mac OS X" | "BSD") cores="$(sysctl -n hw.ncpu)" ;;
esac
fi
cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')"
cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))"
;;
esac