Skip to content

Instantly share code, notes, and snippets.

@thomashartm
Last active August 12, 2016 13:52
Show Gist options
  • Save thomashartm/0a5ea8ac492a73f80a9232034e3dd2e9 to your computer and use it in GitHub Desktop.
Save thomashartm/0a5ea8ac492a73f80a9232034e3dd2e9 to your computer and use it in GitHub Desktop.
Create threaddumps of all running aem processes
#!/bin/bash
# Call as follows to generate 15 TDs for all instances with a break of 5 seconds:
# ./aem_threadumps.sh 15 5
# Call as follows to generate 15 TDs for all instances with a break of 5 seconds and write them in a distinct working directory
# ./aem_threadumps.sh 15 5 /home/user/data
if [ $# -eq 0 ]; then
echo >&2 "Creates threaddumps for running aem instances "
echo >&2 " Usage: td [ [ ] ]"
echo >&2 " Defaults: count = 10, delay = 1 (seconds)"
exit 1
fi
count=${1:-10} # defaults to 10 times
delay=${2:-1} # defaults to 1 second
function createThreadDumps(){
local p=$1
local c=$2
local d=$3
echo >&2 "jstack $p times: [$count] delay: [$delay]"
while [ $c -gt 0 ]
do
jstack $p >jstack.$p.$(date +%H%M%S.%3N).log
sleep $d
let c--
echo -n "."
done
}
cd "$(dirname "$3")"
for line in $(jps -l | grep aem | grep -v grep | awk '{print $1}')
do
createThreadDumps $line $count $delay
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment