Mprof 3.0 --- a memory allocation profiler and leak detector.

This commit is contained in:
Jeffrey Hsu 1994-11-05 09:56:06 +00:00
parent f96b5063af
commit 6fc17874fd
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=321
5 changed files with 369 additions and 0 deletions

22
devel/mprof/Makefile Normal file
View file

@ -0,0 +1,22 @@
# New ports collection makefile for: mprof
# Version required: 3.0
# Date created: Sat Nov 5 01:16:33 PST 1994
# Whom: hsu
#
# $Id$
#
DISTNAME= mprof-3.0
MASTER_SITES= ftp://cs.colorado.edu/pub/misc/
EXTRACT_SUFX= .tar.Z
WRKSRC= ${WRKDIR}
install:
@if [ ! -e ${PREFIX}/bin ]; then mkdir -p ${PREFIX}/bin; fi
@if [ ! -e ${PREFIX}/lib ]; then mkdir -p ${PREFIX}/lib; fi
@if [ ! -e ${PREFIX}/man/man1 ]; then mkdir -p ${PREFIX}/man/man1; fi
install -c -m 555 ${WRKSRC}/mprof ${PREFIX}/bin
install -c -m 555 ${WRKSRC}/libc_mp.a ${PREFIX}/lib
install -c -m 555 ${WRKSRC}/mprof.1 ${PREFIX}/man/man1
.include <bsd.port.mk>

245
devel/mprof/files/patch-01 Normal file
View file

@ -0,0 +1,245 @@
*** ../m/mprof_mon.c Tue Apr 20 13:36:09 1993
--- mprof_mon.c Fri Sep 17 17:09:01 1993
***************
*** 411,417 ****
#ifdef sun
on_exit(mprof_exit, NULL);
#endif
! #ifdef mips
atexit(mprof_exit);
#endif
--- 411,417 ----
#ifdef sun
on_exit(mprof_exit, NULL);
#endif
! #if defined(mips) || defined(__FreeBSD__)
atexit(mprof_exit);
#endif
*** ../m/mprof.h Tue Apr 20 13:36:07 1993
--- mprof.h Fri Sep 17 16:53:52 1993
***************
*** 109,115 ****
extern char *strdup();
! #if (defined(vax) || (defined(sun) && !defined(sun4)))
#define get_current_fp(first_local) ((unsigned)&(first_local) + 4)
#endif
--- 109,115 ----
extern char *strdup();
! #if (defined(vax) || (defined(sun) && !defined(sun4))) || defined(__FreeBSD__)
#define get_current_fp(first_local) ((unsigned)&(first_local) + 4)
#endif
***************
*** 120,126 ****
#define ret_addr_from_fp(fp) (unsigned)(((struct frame *)(fp))->fr_savpc)
#endif
!
/* for ultrix 0x38, 4.3 bsd 0x3d, other?
*/
--- 120,130 ----
#define ret_addr_from_fp(fp) (unsigned)(((struct frame *)(fp))->fr_savpc)
#endif
! #if defined(__FreeBSD__)
! #define prev_fp_from_fp(fp) *((unsigned *) fp)
! #define ret_addr_from_fp(fp) *((unsigned *) (fp+4))
! #endif
!
/* for ultrix 0x38, 4.3 bsd 0x3d, other?
*/
***************
*** 134,137 ****
--- 138,145 ----
#ifdef mips
#define CRT0_ADDRESS 0x0 /* to be filled in later */
+ #endif
+
+ #ifdef __FreeBSD__
+ #define CRT0_ADDRESS 0x10d3
#endif
*** ../m/mpgraph.c Tue Apr 20 13:36:04 1993
--- mpgraph.c Wed Sep 15 23:27:07 1993
***************
*** 114,120 ****
vertex from, to;
mpdata data;
int mark;
! struct edge_struct *save
} *edge, edge_item;
edge
--- 114,120 ----
vertex from, to;
mpdata data;
int mark;
! struct edge_struct *save;
} *edge, edge_item;
edge
*** /dev/null Wed Sep 29 11:23:25 1993
--- Makefile Wed Sep 15 23:25:14 1993
***************
*** 0 ****
--- 1,151 ----
+ # %M% %I% %G% %U%
+ # Copyright (c) 1987, Benjamin G. Zorn
+ #
+ # Makefile for MPROF data generation
+ #
+
+ CC = cc
+
+ # mips CFLAGS = -I. -g -DDEBUG
+ # sun4 CFLAGS = -I. -g -Dsun4
+ # sun3,vax, i386 CFLAGS = -I. -g
+
+ # sun4 ASFLAGS = -P -Dsun4
+ # sun3,vax,mips, i386 ASFLAGS =
+
+ CFLAGS = -I. -g
+ ASFLAGS =
+ BIN = .
+ MPLIB = $(BIN)/libc_mp.a
+ LINTFLAGS = -bhx
+
+ # sun4,mips ASM_SRC = md.s
+ # sun4,mips ASM_OBJ = md.o
+ # vax,sun3 ASM_SRC =
+ # vax,sun3 ASM_OBJ =
+
+ ASM_SRC =
+ ASM_OBJ =
+
+ MPROF_MON_SRCS = leak.c malloc.c mpattach.c mprof_mon.c mpstruct.c $(ASM_SRC)
+ MPROF_MON_OBJS = leak.o malloc.o mpattach.o mprof_mon.o mpstruct.o $(ASM_OBJ)
+
+ MPROF_SRCS = mprof.c mpstruct.c mpgraph.c
+ MPROF_OBJS = mprof.o mpstruct.o mpgraph.o
+
+ DOC_SRC = mprof.1
+ DOC_OBJS = mprof.man
+
+ DISTNAME = mprof-3.0
+
+ TEST_SRCS = test1.c test2.c
+ TEST_OBJS = test1.o test2.o
+
+ all: mprof $(MPROF_MON_OBJS) $(DOC_OBJS) $(MPLIB)
+
+ mips $(MPLIB): $(MPROF_MON_OBJS)
+ ar cr libc_mp.a $(MPROF_MON_OBJS)
+ ranlib libc_mp.a
+
+ # sun3, sun4 LIB_REPLACE = memalign.o
+ # vax LIB_REPLACE = exit.o
+ # mips LIB_REPLACE =
+
+ LIB_REPLACE = exit.o
+
+ #$(MPLIB): $(MPROF_MON_OBJS)
+ # cp /lib/libc.a libc_mp.a
+ # ar d libc_mp.a malloc.o valloc.o $(LIB_REPLACE)
+ # ar r libc_mp.a $(MPROF_MON_OBJS)
+ # ranlib libc_mp.a
+
+ test: $(TEST_OBJS) test1-demo test2-demo
+
+ mprof-mon-lint:
+ lint $(LINTFLAGS) $(MPROF_MON_SRCS) > mprof.lint
+
+ mprof-lint:
+ lint $(LINTFLAGS) $(MPROF_SRCS) > mprof.lint
+
+ clean:
+ rm -f *.o mprof.lint mprof-mon.lint \
+ $(DOC_OBJS) \
+ $(TEST_OBJS) \
+ test1 test1.data test1.mprof \
+ test2 test2.data test2.mprof \
+ libc_mp.a mprof mprof.data
+
+ leak.o: leak.c
+ mprof_mon.o: mprof_mon.c
+ mpstruct.o: mpstruct.c
+ mpgraph.o: mpgraph.c
+ mprof.o: mprof.c
+ md.o: md.s
+ $(AS) $(ASFLAGS) -o md.o md.s
+
+ malloc.o: malloc.c
+ $(CC) $(CFLAGS) -Dmalloc=__malloc__ -Dfree=__free__ -Drealloc=__realloc__ malloc.c -c
+
+ mprof: $(MPROF_OBJS)
+ $(CC) $(CFLAGS) -o mprof $(MPROF_OBJS)
+
+ mprof.man: mprof.1
+ nroff -man mprof.1 > mprof.man
+
+ dist: MANIFEST
+ tar cvf $(DISTNAME).tar `cat MANIFEST`
+ compress $(DISTNAME).tar
+
+ #
+ # Examples to test if MPROF is installed correctly
+ #
+
+ # A very simple test (tests calloc and valloc)
+
+ test1-demo: test1.data
+ $(BIN)/mprof -normal test1 test1.data > test1.mprof
+
+ test1.mprof: test1.data
+ $(BIN)/mprof -normal test1 test1.data > test1.mprof
+
+ test1.data: test1
+ test1
+ cp mprof.data test1.data
+
+ test1: test1.o $(MPLIB)
+ $(CC) $(CFLAGS) -o test1 test1.o $(MPLIB)
+
+ test1.o: test1.c
+
+
+ # test2 program (example from paper)
+
+ test2-demo: test2.data
+ $(BIN)/mprof -normal test2 test2.data > test2.mprof
+
+ test2.mprof: test2.data
+ $(BIN)/mprof -normal test2 test2.data > test2.mprof
+
+ test2.data: test2
+ test2
+ cp mprof.data test2.data
+
+ test2: test2.o $(MPLIB)
+ $(CC) $(CFLAGS) -o test2 test2.o $(MPLIB)
+
+ test2.o: test2.c
+
+
+ ###
+ leak.o: /usr/include/stdio.h mprof.h /usr/include/sys/types.h \
+ /usr/include/frame.h
+ malloc.o: /usr/include/sys/types.h /usr/include/stdio.h
+ mprof.o: /usr/include/stdio.h /usr/include/sys/file.h /usr/include/ctype.h \
+ /usr/include/a.out.h /usr/include/sys/exec.h /usr/include/stab.h \
+ mprof.h /usr/include/sys/types.h /usr/include/frame.h
+ mprof_mon.o: /usr/include/stdio.h /usr/include/sys/file.h mprof.h \
+ /usr/include/sys/types.h /usr/include/frame.h
+ mpstruct.o: /usr/include/stdio.h mprof.h /usr/include/sys/types.h \
+ /usr/include/frame.h
+ mpgraph.o: /usr/include/stdio.h mprof.h /usr/include/sys/types.h \
+ /usr/include/frame.h

1
devel/mprof/pkg-comment Normal file
View file

@ -0,0 +1 @@
Memory Profiler and Leak Detector, version 3.0

97
devel/mprof/pkg-descr Normal file
View file

@ -0,0 +1,97 @@
MPROF -- memory profiler (version 3.0)
To use mprof, you must link the library libc_mp.a (found in the mprof
directory) into your application (this library is the C library with
the definitions of malloc and free replaced). Profiling starts
automatically when malloc is first called. Profile data is written to
the file "mprof.data". There are several functions that users can
call to change the name of the output file, etc. See the man page in
mprof.man.
Simply by linking in the new malloc and executing your application, a
file called ``mprof.data'' will be created in the current directory.
This is the data file that mprof uses to build its dynamic call graph.
Call the program mprof with the following arguments:
mprof [ options ] [ executable-file (a.out) ] [ data-file (mprof.data) ]
The output contains four tables, the fields of which are described in
the man page in mprof.man. Further documentation is available in a
paper which describes the implementation of mprof (published in the
1988 summer USENIX conference) . The LaTeX source of that paper is
located in mprof.tex. The printable DVI file is located in mprof.dvi.
There are currently four makefiles, for the VAX, Sun-3, Sun-4, and
MIPS (specifically, the Decstation 3100 and 5000). To remake mprof,
copy the appropriate file to `Makefile'. If you need to recompile
mprof for any reason, type ``make all'' in this directory. To remove
.o files, type ``make clean'' in this directory. mprof has been
tested on VAX (4.3 BSD and Ultrix using gcc and cc), SUN-3 (gcc and
cc), Sun-4 (cc) computers, and Decstation 3100 (gcc and cc). To test
if mprof works in simple cases, type `make test'.
Mprof does not use Kyoto Common Lisp anymore. To use mprof, all you
need is a C compiler.
The current incarnation of mprof does not handle calls to Sun calls to
valloc or memalign correctly. The calls will be profiled, but if your
program calls valloc or memalign and tries to later free that memory,
mprof will cause it to core dump. On the VAX, memory allocated by
valloc cannot be freed, and so valloc can be profiled correctly on the
VAX. A version of malloc.c is provided with mprof. If this version
is not compatible with the version used on your machine, you may need
to replace this file. If you have problems like this, please let me
know so I can keep a record of the bugs encountered.
My thanks to Stuart Sechrest, Fred Douglis, Dain Samples, John
Ousterhout, Luigi Semenzato, Richard Tuck, Robert Scheifler, Mark
Eichin, Pat Stephenson, and Steven Sargent for their interest and
comments.
My special thanks to Jeffrey Hsu who did the tricky port of mprof to
the MIPS architecture.
In the future (although the exact date is uncertain) I plan to make
the following improvements to mprof:
1. Add code to detect duplicate frees.
2. Fix up the type determination code in mpfilt (see BUGS section in
the man page for mprof).
If you have any questions or comments, please feel free to contact me.
-Ben Zorn
e-mail: zorn@boulder.colorado.edu
phone: 303-492-4398
Differences between version 2.0 and 2.1:
1. In mpfilt.c, the variable stab_i was being incremented without
checking for an overflow. Overflow checks were added.
2. A user discovered that a value of 5000 for ST_SIZE in mpfilt.c was
too small. Large programs may require a larger value for ST_SIZE.
Differences between version 2.1 and 2.2:
1. mprof now runs on the Decstation 3100 (a MIPS machine).
2. A bug that prevented mprof from working in version 4.0 of the Sun
operating system was fixed.
Difference between version 2.2 and 3.0:
1. All analysis is now done in C.
2. The file mprof.c was renamed mprof_mon.c and the file mpfilt.c was
renamed mprof.c.
3. The old C-shell script ``mprof'' is not needed anymore. The file
analysis.lsp is also not needed. It's functionality is now provided
in the file mpgraph.c.
4. Small bugs previously reported were fixed.

4
devel/mprof/pkg-plist Normal file
View file

@ -0,0 +1,4 @@
@cwd /usr/local
bin/mprof
lib/libc_mp.a
man/man1/mprof.1