Created
October 28, 2009 19:31
-
-
Save griffman/220745 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 --- | |
# 0.4: added variable to store file path, and $2 for base file name | |
# added variable to store desired reporting interval | |
# 0.3: added $1 to send in process ID at run time. | |
# 0.2: switched to $SECONDS for the loop. works. | |
# 0.1: didn't work well at all. | |
# --- Version history --- | |
# Usage: cputrack [PID] [filename] | |
# replace [PID] with process ID # | |
# replace [filename] with base file name to use (no extension) | |
filepath=/Users/your_user/Desktop # 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 -p$1 -opid -opcpu -ocomm -c | grep $1 | sed "s/^/$mydate /" >> $filepath/$2.txt | |
sleep 3 | |
mydate=`date "+%H:%M:%S"` | |
done |
Shouldn't the "sleep" call be for $freq and not 3?
Here's my fork: https://gist.github.com/mrnohr/ba7bf61c3f91c071f08d
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, nice script. I have a couple of questions:
memorytrack "myexec myarg1 myarg2" [filename]
I guess the question I really have is how to get a PID automatically from a command-line call. =)