내용은 다시 추가할께요.

 

#! /bin/sh
## SIMPLE, EXTRACT HEAP MEMORY USE RATIO FROM GC LOGS.  by jeikina.

### ENV. ###
FILENAME=$1
WORKDIR=$PWD/gcwork_tmp
DATE_POSTFIX=`echo $FILENAME | cut -d"." -f3 | cut -c1-8`

YGEN_FILE="younggen_${DATE_POSTFIX}.txt"
OGEN_FILE="paroldgen_${DATE_POSTFIX}.txt"
HEAPTOT_FILE="heap_total_${DATE_POSTFIX}.txt"
############

### make working dir. ###
if [ -d $WORKDIR ]
then
 echo " @ Work Directory is $WORKDIR ! Check the output files... "
else
 echo " !! There is no gcwork_tmp directory !! making... "
 mkdir -p $WORKDIR/mov_tmp
 ls -altrd $WORKDIR
fi
######################

## Young Gen Space Use Ratio ##
_GET_YGS()
{
if [ -f $WORKDIR/$YGEN_FILE ]
then
 echo " @ ($YGEN_FILE) filename is already exist! Old file will be Move to (mov_tmp) Directory..."
 mv $WORKDIR/$YGEN_FILE $WORKDIR/mov_tmp
 grep -v "Full GC" $FILENAME | grep ^[0-9] | awk '{print $4}' | cut -d"(" -f2 | sed 's/K)]//g'> $WORKDIR/$YGEN_FILE
else
 grep -v "Full GC" $FILENAME | grep ^[0-9] | awk '{print $4}' | cut -d"(" -f2 | sed 's/K)]//g'> $WORKDIR/$YGEN_FILE
fi
}

## Old Gen Space Use Ratio ##
_GET_OGS()
{
if [ -f $WORKDIR/$OGEN_FILE ]
then
 echo " @ ($OGEN_FILE) filename is already exist! Old file will be Move to (mov_tmp) Directory..."
 mv $WORKDIR/$OGEN_FILE $WORKDIR/mov_tmp
 grep ParOldGen $FILENAME | grep ^[0-9] | awk '{print $7}' | cut -d"(" -f2 | sed 's/K)]//g' > $WORKDIR/$OGEN_FILE
else
 grep ParOldGen $FILENAME | grep ^[0-9] | awk '{print $7}' | cut -d"(" -f2 | sed 's/K)]//g' > $WORKDIR/$OGEN_FILE
fi
}

## Total Heap Space Use Ratio ##
_GET_HEAPTOT()
{
if [ -f $WORKDIR/$HEAPTOT_FILE ]
then
 echo " @ ($HEAPTOT_FILE) filename is already exist! Old file will be Move to (mov_tmp) Directory..."
 mv $WORKDIR/$HEAPTOT_FILE $WORKDIR/mov_tmp
 grep -v "Full GC" $FILENAME | grep ^[0-9] | awk '{print $5}'| cut -d"(" -f2 | sed 's/K),//g' > $WORKDIR/$HEAPTOT_FILE
 grep -i "full gc" $FILENAME | awk '{print $8}' | cut -d"(" -f2 | sed 's/K)*//g' >> $WORKDIR/$HEAPTOT_FILE
else
 grep -v "Full GC" $FILENAME | grep ^[0-9] | awk '{print $5}'| cut -d"(" -f2 | sed 's/K),//g' > $WORKDIR/$HEAPTOT_FILE
 grep -i "full gc" $FILENAME | awk '{print $8}' | cut -d"(" -f2 | sed 's/K)*//g' >> $WORKDIR/$HEAPTOT_FILE
fi
}

_OUTPUT_SORT()
{
 YGEN_MIN_USE=`sort -n $WORKDIR/$YGEN_FILE | head -1`
 YGEN_MAX_USE=`sort -n $WORKDIR/$YGEN_FILE | tail -1`
 OGEN_MIN_USE=`sort -n $WORKDIR/$OGEN_FILE | head -1`
 OGEN_MAX_USE=`sort -n $WORKDIR/$OGEN_FILE | tail -1`
 HEAPTOT_MIN_USE=`sort -n $WORKDIR/$HEAPTOT_FILE | head -1`
 HEAPTOT_MAX_USE=`sort -n $WORKDIR/$HEAPTOT_FILE | tail -1`

 echo
 echo "----------------------------------------------------------------------"
 echo "  @ Young Generation Use Ratio (min/max) : $YGEN_MIN_USE / $YGEN_MAX_USE KB"
 echo "  @ Old Generation Use Ratio (min/max) : $OGEN_MIN_USE / $OGEN_MAX_USE KB"
 echo "  @ Total Heap Use Ratio (min/max) : $HEAPTOT_MIN_USE / $HEAPTOT_MAX_USE KB"
 echo "----------------------------------------------------------------------"

}

_GET_FULLGC_TIME()
{
 FGC_TIME_MIN=`grep -i "full gc" $FILENAME | awk '{print $(11)}' | sort -n | head -1`
 FGC_TIME_MAX=`grep -i "full gc" $FILENAME | awk '{print $(11)}' | sort -n | tail -1`

 echo "  @ Full GC Duration Time : ${FGC_TIME_MIN} ~ ${FGC_TIME_MAX} secs"
 echo
}

## RUN ##################################################################
_GET_YGS
_GET_OGS
_GET_HEAPTOT

_OUTPUT_SORT
_GET_FULLGC_TIME
#########################################################################