1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#!/bin/bash
# IBM "amsstat": Active Memory Sharing statistics gathering tool
#
# Copyright (c) 2009 International Business Machines.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Authors:
# Andrew Theurer <habanero@linux.vnet.ibm.com>
# Robert Jennings <rcj@linux.vnet.ibm.com>
#
# This script will gather AMS related information on supported Linux systems
# usage:
# amstat <interval in seconds>
#
# If you do not provide an interval, amsstat will display stats only once
#
# For further details on this tool and the fields it displays please
# reference man page amsstat.1
sleep_interval=$1
indent=-4
devstat_data_spacing=-30
lparcfg_data_spacing=-30
lparcfg_file=/proc/ppc64/lparcfg
# Hardcoding pseries_platform path as amstat will be placed in bin
PSERIES_PLATFORM=/usr/sbin/pseries_platform
function print_meminfo_stats {
echo "System Memory Statistics:"
OLD_IFS=${IFS}
IFS="
"
for stat in `cat /proc/meminfo`; do
IFS=${OLD_IFS}
if echo $stat | grep "^MemTotal\|^MemFree\|^Buffers\|^Cached\|^Inactive\|SwapTotal\|SwapFree" >/dev/null; then
this_stat=`echo $stat | awk -F: '{print $1}'`
this_value=`echo $stat | awk -F: '{print $2}'`
printf "%${indent}s %${lparcfg_data_spacing}s %${lparcfg_data_spacing}s\n" " " "$this_stat:" "${this_value##\ }"
fi
done
# Include Desired Memory value from /proc/ppc64/lparcfg
stat=`grep "^DesMem" $lparcfg_file`
if [ ! -z "${stat}" ]; then
this_stat=`echo $stat | awk -F= '{print $1}'`
this_value=`echo $stat | awk -F= '{print $2}'`
printf "%${indent}s %${lparcfg_data_spacing}s %${lparcfg_data_spacing}s\n" " " "$this_stat:" "$this_value MB"
fi
}
function print_entitlement_data {
echo "Entitlement Information:"
for stat in `cat $lparcfg_file`; do
if echo $stat | grep "^entitled_memory\|^mapped_entitled_memory\|^entitled_memory_weight\|entitled_memory_pool_size\|^backing_memory\|^cmo_enabled\|^cmo_faults\|^cmo_fault_time_usec\|cmo_primary_psp\|^cmo_secondary_psp\|^coalesced_bytes\|^pool_coalesced_bytes" >/dev/null; then
this_stat=`echo $stat | awk -F= '{print $1}'`
this_value=`echo $stat | awk -F= '{print $2}'`
printf "%${indent}s %${lparcfg_data_spacing}s %${lparcfg_data_spacing}s\n" " " "$this_stat:" "$this_value"
fi
done
}
function print_cmm_stats {
# CMM kernel parameters
echo "CMM Statistics:"
local path=/sys/module/cmm/parameters
pushd $path >/dev/null 2>&1
if [ $? -ne 0 ] ; then
printf "%${indent}s Could not get CMM Statistics.\n" " "
return
fi
for stat in `find . -mindepth 1 -maxdepth 1 -print`; do
printf "%${indent}s %${devstat_data_spacing}s %${devstat_data_spacing}s\n" " " "${stat#\.\/}:" "`cat $stat`"
done
popd >/dev/null
# CMM statistics
local path=/sys/devices/system/cmm/cmm0
pushd $path >/dev/null 2>&1
if [ $? -ne 0 ] ; then
return
fi
for stat in `find . -mindepth 1 -maxdepth 1 -print`; do
printf "%${indent}s %${devstat_data_spacing}s %${devstat_data_spacing}s\n" " " "${stat#\.\/}:" "`cat $stat`"
done
popd >/dev/null
}
function print_vio_bus_stats {
echo "VIO Bus Statistics:"
local found=0
local path=/sys/bus/vio
pushd $path >/dev/null 2>&1
if [ $? -ne 0 ] ; then
printf "%${indent}s Could not get VIO Bus Statistics.\n" " "
return
fi
for stat in `find . -mindepth 1 -maxdepth 1 -name "cmo*" -print`; do
found=1
printf "%${indent}s %${devstat_data_spacing}s %${devstat_data_spacing}s\n" " " "${stat#\.\/}:" "`cat $stat`"
done
popd >/dev/null
if [ "$found" -eq "0" ]; then
printf "%${indent}s No AMS Busses found.\n" " "
fi
}
function print_vio_dev_stats {
echo "VIO Device Statistics:"
local found=0
local path=/sys/bus/vio/devices
pushd $path >/dev/null 2>&1
if [ $? -ne 0 ] ; then
printf "%${indent}s Could not get VIO Device Statistics.\n" " "
return
fi
for dir in `find . -mindepth 1 -print`; do
pushd $dir >/dev/null 2>&1
if [ $? -ne 0 ] ; then
break
fi
# Skip printing devices that are not using entitlement
if [ ! -e "cmo_entitled" ]; then
popd >/dev/null
continue
fi
value=`cat cmo_entitled`
if [ ${value} -eq "0" ]; then
popd >/dev/null
continue
fi
NAME=$(cat devspec)
echo " ${NAME##/*/}:"
for stat in `find . -mindepth 1 -maxdepth 1 -name "cmo*" -print`; do
found=1
printf "%${indent}s %${devstat_data_spacing}s %${devstat_data_spacing}s\n" " " "${stat#\.\/}:" "`cat $stat`"
done
popd >/dev/null
done
popd >/dev/null
if [ "$found" -eq "0" ]; then
printf "%${indent}s No AMS devices found.\n" " "
fi
}
if [ ! -f $PSERIES_PLATFORM ]; then
echo "$PSERIES_PLATFORM does not exist"
echo "amstat: is not supported on the Unknown platform"
exit 1;
fi
. $PSERIES_PLATFORM
if [[ $platform != $PLATFORM_PSERIES_LPAR ]]; then
echo "amstat: is not supported on the $platform_name platform"
exit 1
fi
# Verify CMO is present and enabled
enabled=`cat $lparcfg_file | grep "^cmo_enabled" | awk -F= '{print $2}'`
if [ -z $enabled ]; then
echo "This system is not capable of Active Memory Sharing."
exit -1
elif [ "$enabled" -eq "0" ]; then
echo "Active Memory Sharing is not enabled on this system."
exit -1
fi
if [ -z $sleep_interval ]; then
date
print_meminfo_stats
print_entitlement_data
print_cmm_stats
print_vio_bus_stats
print_vio_dev_stats
else
while [ 1 ]; do
date
print_meminfo_stats
print_entitlement_data
print_cmm_stats
print_vio_bus_stats
print_vio_dev_stats
sleep $sleep_interval
echo
done
fi
|