Skip to content

Instantly share code, notes, and snippets.

@tmoreira2020
Created November 14, 2011 18:52
Show Gist options
  • Save tmoreira2020/1364754 to your computer and use it in GitHub Desktop.
Save tmoreira2020/1364754 to your computer and use it in GitHub Desktop.
Gets a thread dump and memory photo of a Java application
#!/bin/bash
if [ -n "$1" ]; then
for (( ; ; ))
do
echo "infinite loops [ hit CTRL+C to stop]"
pid=`jps | grep $1 | awk '{print $1}'`
echo "Getting dump from process $pid"
jstat -gcutil $pid 250 3 >> dump-memory-$pid.txt
jstack -l $pid >> dump-thread-$pid.trc
jstat -gcutil $pid 250 3 | grep -v YGC >> dump-memory-$pid.txt
time=20;
echo "Sleeping for $time seconds"
sleep $time;
done
else
You have to provide a process name, like "Bootstrap".
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment