Created
August 10, 2012 16:57
-
-
Save cluePrints/3315611 to your computer and use it in GitHub Desktop.
Script to gather info about a java process - useful for producing informative bug reports.
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 | |
# | |
# Quickly collect information about a java process: | |
# - heap dump | |
# - stack trace | |
# | |
# Set this to control number of snapshots kept: | |
# | |
MAX_DUMPS=5 | |
# | |
# | |
# | |
PID=$1 | |
DUMP_SUFFIX="dump"`date +%Y-%m-%d_%H%M_%S_p$PID` | |
function performDump() { | |
jstack -l $PID > "${DUMP_SUFFIX}.stack" | |
jmap -dump:file=${DUMP_SUFFIX}.hprof,live $PID | |
} | |
function cleanDumps() { | |
DUMP_FILES=`ls -la dump* | awk '{print $9}' | sort -r` | |
let DUMP_FILES_LIMIT=($MAX_DUMPS-1)*2 | |
COUNT=0 | |
for DUMP_FILE in $DUMP_FILES | |
do | |
let COUNT=$COUNT+1 | |
if [ $COUNT -gt $DUMP_FILES_LIMIT ] | |
then | |
rm $DUMP_FILE | |
fi | |
done | |
} | |
cleanDumps | |
performDump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment