Created
January 10, 2017 16:22
-
-
Save jffry/7d5cf3cc285b62485e529cca66f1b1c5 to your computer and use it in GitHub Desktop.
Log memory usage of Java every second as it's running
This file contains hidden or 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 | |
#helper that gives the current unix time, in seconds | |
function now() { | |
date -u "+%s" | |
} | |
#helper that calculates elapsed ms | |
START="$(now)" | |
function elapsed() { | |
NOW="$(now)" | |
echo $((NOW-START)) | |
} | |
#helper that prints a single line of stats about latest java proc | |
function stats() { | |
pid=$(pgrep java | tail -n 1) | |
if [ -z "$pid" ] ; then | |
echo "$(elapsed), 0, 0" | |
else | |
echo "$(elapsed), $pid, $(ps -o rss= -p $pid)" | |
fi | |
} | |
#main loop | |
echo "elapsed-sec, proc-id, mem-rss-kb" | |
while [ 1 ] ; do | |
stats | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment