To find a memory leak collect avm stats from vmstat
I normally collect a days worth of stats with sample taken every 5 minutes. Export the avm column into excel and create a graph. If you see a constantly upward graph you more than likely do have a memory leak. Now to find the offending process.
----postvg.sh------
#!/bin/ksh
#
#
# Correlate ps.before and ps.after data ..
#
# command output from ps vg
#
ONE_FILE=temp_ps_vg
print_help() {
print "Version 1.0"
print "Usage: post_vg.sh [single_file|before_ps after_ps]"
print " Post process ps vg output "
print " "
print " where, "
print " single_file contains a before and after snapshot"
print " "
print " No files specified - assume"
print " ==> ps_vg.before "
print " ==> ps_vg.after "
exit -1
}
main() {
if [[ $1 == "-?" ]]
then
print_help
exit -1
fi
if [[ $# == 2 ]]
then
cat $1 $2 > $ONE_FILE
elif [[ $# == 1 ]]
then
cat $1 > $ONE_FILE
else
cat ps_vg.before ps_vg.after > $ONE_FILE
fi
post_vg
rm $ONE_FILE
}
post_vg() {
cat $ONE_FILE | awk 'BEGIN {
list_label = "None"
}
/PID/ {
if( list_label == "None" )
list_label = "Before"
else
list_label = "After"
next
}
{
pid_list[$1]
pid_size[$1, list_label ] = $6
pid_name[$1] = $13
}
END {
printf("%15s\t%10s\t%11s\t%10s\t%10s\n", "pid", \
"Name", \
"Before Size", \
"After Size", \
"Delta")
for( pid in pid_list ) {
if( (pid,"Before") in pid_size && (pid,"After") in pid_size ) {
delta = pid_size[pid, "After"] - pid_size[pid, "Before"]
d_total += delta
printf("%15s\t%10s\t%11d\t%10d\t%10d\n", \
pid, \
pid_name[pid], \
pid_size[pid, "Before"], \
pid_size[pid, "After"], \
delta )
}
}
printf("*** Total Delta %d\n", d_total)
}'
}
main $@
----End-----
1) Issue the following command
# ps vg > ps.before
2) Wait some period of time -- perhaps 30 minutes and issue the command again.
# ps vg > ps.after
3) Now, post process the two files
# ./post_vg ps.before ps.after
Note: The script assumes that before is the first file.
The 'Delta' indicates a change in the process SIZE. One reason for an
increasaed SIZE value is a memory leak. For more information about
detecting memory leaks review the paper Methods for Identifying Memory
Leaks in AIX Systems.
Mike
"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."