#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2006,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

# "@(#)82   1.1   src/rsct/pts/pam/tools/hats_cpu_check.sh, topology.services, rsct_relgh, relghs001a 8/28/06 18:51:06"

#########################################################################
#                                                                       #
# CPU usage debugging script.                                           #
#                                                                       #
# This script is run by Topology Services in the case of high CPU       #
# usage to gather debugging information.  A script is more practical    #
# in this case than trying to gather data from within the binary; both  #
# because we are not sure what the condition of hatsd will be, and so   #
# that it can be customized on-site by customers or IBM support.        #
#                                                                       #
#########################################################################

# Output directory -- customize for local use.
OUTPUTDIR=/tmp/hats_cpu_check


# subdirectory for this iteration:
NEWDIR=${OUTPUTDIR}/`date +%m%d.9/13/07M%S`
mkdir -p $NEWDIR

OSNAME=`uname -s 2> /dev/null`

FILE1=${NEWDIR}/ps.out
if [[ $OSname = "AIX" ]]
then
   FILE2=${NEWDIR}/hatsd_stack1.out
   FILE3=${NEWDIR}/hatsd_stack2.out
fi

date > $FILE1
ps waux >> $FILE1

if [[ $OSname = "AIX" ]]
then

   date > $FILE2
   print "                SLOT NAME     STATE    TID PRI   RQ CPUID  CL WCHAN" >> $FILE2
   echo "th *"|kdb|grep hatsd >> $FILE2
   echo >> $FILE2
   echo "th *"|kdb|grep hatsd|awk '{print "stack " $2}'|kdb >> $FILE2

fi

sleep 10

echo >> $FILE1
date >> $FILE1
ps waux >> $FILE1

if [[ $OSname = "AIX" ]]
then

   date > $FILE3
   print "                SLOT NAME     STATE    TID PRI   RQ CPUID  CL WCHAN" >> $FILE3
   echo "th *"|kdb|grep hatsd >> $FILE3
   echo >> $FILE3
   echo "th *"|kdb|grep hatsd|awk '{print "stack " $2}'|kdb >> $FILE3

fi

