SCD recently
installed version 6.4 of the Totalview debugger on babyblue. This version
has the ability to track memory usage and to detect memory leaks.
Leak detection
The following example checks for leaks from the first executable
line of our sample program test.f
to the end of the program.
In order to use Totalview for memory leak detection, you will need
to compile your code with -g
and to link in the totalview malloc replacement library.
Compile and link:
xlf90 -o test
-g test.f -L /usr/local/tvheap_mr \
-L /usr/local/totalview/toolworks/totalview.6.4.0-2/rs6000/lib \
/usr/local/totalview/toolworks/totalview.6.4.0-2/rs6000/lib/aix_malloctype.o
#for 64-bit,
replace aix_malloctype.o with aix_malloctype64_5.o
After starting Totalview, load the program (under the File->New
Program) menu to obtain a view of the source code (Figure 1).

Select
Tools->Command Line
to bring up a command line window. Type the following at the command
line to set a breakpoint, enable memory debugging, and run to the breakpoint:
dbreak 9 (a
STOP sign shows to the left of line 9 of the source)
dheap -enable
dgo
Now type:
dheap -leaks
Figure 2 below shows that 18 leaks were detected (two leaks each
time through the loop). Nine leaks from array foo2
(at line 25 inside subroutine loknlod)
are responsible for two-thirds of the memory leaks, while the second
nine leaks are from a smaller array foo
(at line 19).

Memory usage
It can be useful to have an indication of the high-water memory mark
for your program. After running the program to the stop point, you
can select the Tools->Memory Usage menu option. Figure 3
indicates that the memory usage for the program was about 929628 bytes
(under the Heap column).

Further information
For further usage information and other new features, please see
the User Guide link at
http://www.etnus.com/Support/docs/
or direct questions to SCD Consulting (consult1@ucar.edu,
303-497-1278).
Juli Rew
|