Created
January 24, 2014 21:16
-
-
Save yadudoc/8606635 to your computer and use it in GitHub Desktop.
Memory usage tracking script for swift runs.
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 | |
get_last_swift() | |
{ | |
ps -u $USER | grep swift | head -n 1 | awk -F ' ' '{print $1}' | |
} | |
timestamp() | |
{ | |
#UNIXTIMESTAMP | |
#date +"%s" | |
date -u | |
} | |
track_mem_usage() | |
{ | |
PID=$(get_last_swift) | |
echo "last swift : $PID" | |
[ ! -z $1 ] && PID=$1 | |
JAVAPID=($(pgrep -P $PID)) | |
CPID=($(pstree -p $PID | head -n 1 | grep -o "\([0-9]*\)")) | |
PID_STRING="" | |
for pid in ${CPID[*]} | |
do | |
PID_STRING="$PID_STRING -p $pid " | |
done | |
pstree -p $PID | head -n 1 | |
echo "Tracking PIDs: $PID_STRING" | |
echo "====================================================" | |
while : | |
do | |
ps -p $PID &> /dev/null | |
[ $? != 0 ] && break | |
#timestamp | |
#top -b -n 1 $PID_STRING | awk 'java {print $* systime()}' | |
top -b -n 1 $PID_STRING | tail -n +8 | sed '/^$/d' | sed -e "s/^/$(date +"%T")\ /" | |
sleep 2 | |
done | |
} | |
track_mem_usage $1 | tee mem_usage.$RANDOM.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment