#!/bin/ksh
#set -x
## param 1: min number of times a waiter has to appear on the list to be considered as a mutex lock
## param 2: consecutive number of times to sample "output onstat -g lmx"
## param 3: wait time between samplings
## it only shows the session holding a mutex in a partition
## recomendation: waiters.sh 2 5 5
_npollings=1
_samplings=$2
_interval=$3
while true
do
while [ _npollings -lt $_samplings ]
do
onstat -g lmx
((_npollings+=1))
done | awk -v max_waiters=$1 '
BEGIN { _alertit = 0 }
/^[0-9]/ {
if ($3 in holdinglock)
holdinglock[$3]++;
else
holdinglock[$3]=1;
}
/^[ \t]+/ {
if ( $1 in waiters)
waiters[$1]++;
else
waiters[$1]=1;
}
END {
for (_waiter in waiters)
{
if (waiters[_waiter] >= max_waiters)
_alertit=1;
}
if (_alertit == 1)
for (_holder in holdinglock) {
if ( substr(_holder,1,3) == "pt_" )
printf "%s\n",substr(_holder,4);
}
}
' | while read _holder
do
date
echo "SELECT FIRST 1 t.dbsname, t.tabname FROM systabnames t where lower(hex(t.partnum)) like \"%"$_holder"%\";" | dbaccess sysmaster
done| tee -a new_mutex_counts.out
sleep $_interval
done