Saturday, 17 November 2012

Thread Dump and Heap Dump

# Get the PID - Process Id using JPS

jps -v | grep server_name | awk '{ print $1 }'

# Take the Thread Dump

jstack PID >> thread_dumps.log

# Take the Heap Dump

jmap -dump:file=Heap_Dump.log PID


Simple JSTACK Script

#!/bin/bash
if [ $# -eq 0 ]; then
    echo >&2 "Usage: jstackSeries <pid> <run_user> [ <count> [ <delay> ] ]"
    echo >&2 "    Defaults: count = 10, delay = 0.5 (seconds)"
    exit 1
fi
pid=$1          # required
user=$2         # required
count=${3:-10}  # defaults to 10 times
delay=${4:-30} # defaults to 30 seconds
while [ $count -gt 0 ]
do
    sudo -u $user jstack -l $pid >jstack.$pid.$(date +%H%M%S.%N)
    sleep $delay
    let count--
    echo -n "."
done

No comments:

Post a Comment