Created
September 19, 2019 10:16
-
-
Save abdullah-shiwani/8a8dab8374da190ab26c2e5057c40cf9 to your computer and use it in GitHub Desktop.
To get the heap information a Java process.
This file contains 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 | |
PID=$1 | |
if [[ -z "${PID}" ]]; then | |
echo "Please provide the process id" | |
exit 1 | |
fi | |
SIZE=`jstat -gc $PID | tail -1 | awk '{split($0,a," "); sum=(a[1]+a[2]+a[5]+a[7])/1024; print sum"MB"}'` | |
if [[ -z "$SIZE" ]]; then | |
exit 1 | |
fi | |
USED=`jstat -gc $PID | tail -1 | awk '{split($0,a," "); sum=(a[3]+a[4]+a[6]+a[8])/1024; print sum"MB"}'` | |
MAX=`jstat -gccapacity $PID | tail -1 | awk '{split($0,a," "); sum=(a[2]+a[8])/1024; print sum"MB"}'` | |
CPU=`ps -p $PID -o %cpu | tail -1` | |
echo " Max Heap | Current Heap | Used Heap | CPU%" | |
echo "--------------------------------------------------" | |
printf "%-9s | %-12s | %-9s | %s\n\n" $MAX $SIZE $USED $CPU |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment