Skip to content

Instantly share code, notes, and snippets.

@abdullah-shiwani
Created September 19, 2019 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullah-shiwani/1fe3380d93927d3682e48639d8a6b367 to your computer and use it in GitHub Desktop.
Save abdullah-shiwani/1fe3380d93927d3682e48639d8a6b367 to your computer and use it in GitHub Desktop.
To get the heap information a Java process.
#!/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