-
-
Save markito/438f2e35bfcf23c6da9b to your computer and use it in GitHub Desktop.
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 | |
| if [ "$#" -ne 1 ]; then | |
| echo "Usage: $0 jps-filter-grep-expr" | |
| exit 1 | |
| fi | |
| jps_filter=$1 | |
| # extract the PID of the java process | |
| java_app_pid=$(jps -lvm | grep ${jps_filter} | awk '{print $1}') | |
| # get 10 top consuming threads | |
| top_consuming_threads=$(top -n1 -H -p ${java_app_pid} | \ | |
| egrep java | egrep -o '^[^0-9]*[0-9]+ ' | \ | |
| sed -r 's/[^0-9]+//g' | head) | |
| temp_file=$(mktemp) | |
| # create jstack_output | |
| jstack ${java_app_pid} > ${temp_file} | |
| # print for every thread the current stack trace | |
| for thread in ${top_consuming_threads}; do | |
| echo "Stack trace for Thread '${thread}':" | |
| printf -v thread_hex "%x" $thread | |
| grep -A10 "nid=0x${thread_hex}" ${temp_file} | |
| echo | |
| done; | |
| rm ${temp_file} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment