[comp.lang.c++] Profiling C++ programs.

patrick@asur.cs.cornell.edu (Pat Stephenson) (06/24/88)

I'm using the ATT C++ translator, version 1.2.  I'd like to
profile the resulting programs, but if I give the "-p" flag,
my compile will fail in the load phase due to multiply defined
symbols.  The problem is that the C++ startup/finish routines
conflict with the profiling startup/finish routines.

Has anybody gotten "-p" (or better, "-pg") to work with att C++ ?

Pat

frans@cs.vu.nl (Frans Heeman) (12/09/88)

I tried to make a profile of a C++ program, using the -p (or -pg) flag:
	CC -p *.c
During linking, the following error was produced:
	_exit: /usr/lib/libc_p.a(exit.o): multiply defined

We are using C++ 1.2 on a SUN 3/60, running Sun UNIX 4.2,
Release 3.5EXPORT. Has anyone had this problem too, and if so, what
did you do?

agn@unh.cs.cmu.edu (Andreas Nowatzyk) (12/11/88)

This problem can be fixed by changeing the order of library calls,
for example:

	CC -g -p -o foo foo.c /usr/lib/libc_p.a -lm

works for me.

-- 
   --  Andreas Nowatzyk  (DC5ZV)

   Carnegie-Mellon University	     Arpa-net:   agn@unh.cs.cmu.edu
   Computer Science Department         Usenet:   ...!seismo!unh.cs.cmu.edu!agn
-- 

prl@iis.UUCP (Peter Lamb) (12/13/88)

In article <1790@kano.cs.vu.nl> frans@cs.vu.nl (Frans Heeman) writes:
>I tried to make a profile of a C++ program, using the -p (or -pg) flag:
>	CC -p *.c
>During linking, the following error was produced:
>	_exit: /usr/lib/libc_p.a(exit.o): multiply defined
>
The problem is that exit() is defined in /lib/mcrt0.o and /lib/gcrt0.o .

The reason for this is so that you don't have to have a different
exit() function in /lib/libc.a .

It is quite difficult to get profiling to work correctly, especially if you
want to support a number of programming environments (we have AT&T 1.2.1
on Vax, Sun, Alliant and Sequent).

I couldn't make the combination of profiling, executing destructors
and doing stdio cleanup work correctly for an exit function called
exit().

So, what I have done is to change the distributed exit.c code
to do the following:

#ifndef PROFILE_LIB

... Original AT&T code for C++ exit

#endif

void Exit(int i)
{
	dtors();
	exit(i);
}

The library must be compiled for profiling with PROFILE_LIB
defined. If you want to use profiling, you have to exit with Exit(i)
rather than exit(i).

This is *ugly*, and I would really appreciate someone giving me a better
solution.


-- 
Peter Lamb
uucp:  uunet!mcvax!ethz!prl	eunet: prl@ethz.uucp	Tel:   +411 256 5241
Integrated Systems Laboratory
ETH-Zentrum, 8092 Zurich

murphy@WISDOM.WEIZMANN.AC.IL (Nir Friedman) (04/30/91)

Hello

	I am working in C++ using g++ (ver. 1.39.0) on sun4 and sun3.
	I'm trying to 'prof' and  'gprof' on my program, since it is
	quite large (25K lines). The compiler documentation (g++.texinfo
	updated 1.37) state that the -p and -pg options are not supported
	yet. I have noticed though, that when compiling with -p the
	compiler generate calls to 'mcount' at the right locations.

	The problem is that when I run the program, no profiling happens.
	I guess this has to do with  the startup module (crt1+.o ?) of g++.

	Do you know of any way of solving this ? or any way of profiling
	C++ programs ?
	
		Thanks in advance

			Nir Friedman