Skip to content

Instantly share code, notes, and snippets.

@msiebuhr
Created March 1, 2011 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msiebuhr/848832 to your computer and use it in GitHub Desktop.
Save msiebuhr/848832 to your computer and use it in GitHub Desktop.
Starts a process and log it's memory use while it's running.
#!/bin/bash
# Measure the memory usage of process with PID
# Execute whatever's given on the command-line
$* > /dev/null &
sleep 1
# Monitor it
PID=$!
FILENAME=${1}_${PID}_`date --iso`.txt
ITERATION=1
STATUS_FILE=/proc/${PID}/status
if [[ -e $STATUS_FILE ]]; then
echo RUNNING!
echo -n > $FILENAME
fi
while [[ -e $STATUS_FILE ]]; do
VmSize=`awk '/VmSize/ {print $2}' $STATUS_FILE`
echo $ITERATION $VmSize >> $FILENAME
echo -n .
let ITERATION++
sleep 10
done
kill -9 $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment