Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cpu monitor
$ SAMPLE_SIZE=3
DELAY_SECS=1
TOP_APP_NUM=5 # number of apps to sum up
$ /usr/bin/top -s $DELAY_SECS -l $SAMPLE_SIZE -n $TOP_APP_NUM -F -o cpu -stats cpu,pid,command | \
grep -A$TOP_APP_NUM "%CPU"
%CPU PID COMMAND
0.0 99989 fish
0.0 99752 mdworker_shared
0.0 99640 CategoriesServic
0.0 99567 writeconfig
0.0 99297 passd
--
%CPU PID COMMAND
32.4 151 WindowServer
11.9 92892 iTerm2
7.4 0 kernel_task
7.0 215 coreaudiod
5.3 86486 Melodics
--
%CPU PID COMMAND
40.9 151 WindowServer
13.6 0 kernel_task
11.8 92892 iTerm2
11.5 1 launchd
7.7 215 coreaudiod
$ /usr/bin/top -s $DELAY_SECS -l $SAMPLE_SIZE -n $TOP_APP_NUM -F -o cpu -stats cpu,pid,command | \
grep -A$TOP_APP_NUM "%CPU" | \
grep -v CPU
0.0 99640 CategoriesServic
0.0 99567 writeconfig
0.0 99297 passd
0.0 99209 media-indexer
0.0 99117 PrintUITool
--
32.7 151 WindowServer
12.3 92892 iTerm2
7.5 215 coreaudiod
6.7 0 kernel_task
5.3 86486 Melodics
--
37.9 151 WindowServer
12.2 95222 Activity Monitor
12.1 92892 iTerm2
8.5 215 coreaudiod
7.2 86486 Melodics
$ /usr/bin/top -s $DELAY_SECS -l $SAMPLE_SIZE -n $TOP_APP_NUM -F -o cpu -stats cpu,pid,command | \
grep -A$TOP_APP_NUM "%CPU" | \
grep -v CPU | \
grep -v "^--"
0.0 99640 CategoriesServic
0.0 99567 writeconfig
0.0 99297 passd
0.0 99209 media-indexer
0.0 99117 PrintUITool
32.8 151 WindowServer
12.8 92892 iTerm2
7.5 215 coreaudiod
5.5 86486 Melodics
5.1 0 kernel_task
33.0 95222 Activity Monitor
31.4 151 WindowServer
10.4 92892 iTerm2
8.5 372 top
7.5 215 coreaudiod
$ /usr/bin/top -s $DELAY_SECS -l $SAMPLE_SIZE -n $TOP_APP_NUM -F -o cpu -stats cpu,pid,command | \
grep -A$TOP_APP_NUM "%CPU" | \
grep -v CPU | \
grep -v "^--" | \
awk '{arr[$2]+=$1;arr2[$2]=$3} END {for (key in arr) printf("%s\t%s\n", arr2[key], arr[key])}'
kernel_task 5.7
WindowServer 71.2
coreaudiod 15.5
top 7.4
Melodics 5.6
iTerm2 19.7
Activity 15.8
PrintUITool 0
media-indexer 0
passd 0
writeconfig 0
CategoriesServic 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment