Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scripts/cpu_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ get_percent()
case $(uname -s) in
Linux)
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
normalize_percent_len $percent
normalize_string_length $percent
;;

Darwin)
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
cpucores=$(sysctl -n hw.logicalcpu)
cpuusage=$(( cpuvalue / cpucores ))
percent="$cpuusage%"
normalize_percent_len $percent
# a/b will get a integer, no decimal, like "1%" or "99%".
# So set the length to 3 below.
normalize_string_length $percent 3
;;

CYGWIN*|MINGW32*|MSYS*|MINGW*)
Expand Down
Loading