Forked from griffman/Track CPU usage by PID over time
Last active
March 6, 2019 10:23
-
-
Save iAladdin/37d3590290da5a5072a5b64225c1299e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- Version history --- | |
# track cpu usage all the time. $1 is logfile name. | |
# --- Version history --- | |
# Usage: cputrack [PID] [filename] | |
# replace [PID] with process ID # | |
# replace [filename] with base file name to use (no extension) | |
filepath=/Users/ialaddin # modify as desired | |
interval=20 # reports per minute | |
timelimit=6000 # how long to run, in seconds | |
mydate=`date "+%H:%M:%S"` # the timestamp | |
freq=$((60/$interval)) # for sleep function | |
while [ "$SECONDS" -le "$timelimit" ] ; do | |
ps ax -opcpu -ocomm | sort -nrk 3,3 | head -n 10 | sed "s/^/$mydate /" >> $filepath/$1.txt | |
sleep 3 | |
mydate=`date "+%H:%M:%S"` | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment