Skip to content

Instantly share code, notes, and snippets.

@cluePrints
Created August 10, 2012 16:57
Show Gist options
  • Save cluePrints/3315611 to your computer and use it in GitHub Desktop.
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.
#!/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