"Stephen J. Turnbull" <stephen(a)xemacs.org>, on 08 Feb 2002 at 14:56:48
+0900 you wrote:
Sorry, I know nothing about profiling C yet, I guess it's time
to
learn.
Well, if you take the tack I just tried, you'll soon find out that
XEmacs is NOT set up to work with gprof. This is what I've done so
far.
1) Configure with --cflags="-g -pg" and --ldflags="-pg".
2) Edit src/Makefile.in so that it does not explicitly specify the crt
files to link with. I wasn't sure what would cause problems and what
wouldn't, so I:
a) Removed "-lgcc -lc -lgcc /usr/lib/crtn.o" from the end of ld_libs_all
b) Removed the -nostdlib flag from LD
c) Emptied start_files and lib_cc
(Is there some platform on which all this is necessary? Letting the
compiler sort all of this out certainly works fine on Linux and
Solaris, as far as I can tell.)
3) Watch temacs dump perfectly good profiling data ... and then watch
xemacs run, exit normally, and fail to write any profiling data. I
thought at first that maybe XEmacs was calling _exit() instead of
exit(). There are a number of places in the source where _exit() is
used instead of exit():
a) callproc.c: child_setup, relocate_fd
b) ecrt0.c: various startup routines
c) process-unix.c: unix_create_process
d) sysdep.c: sys_subshell, mkdir, rmdir
But, no, XEmacs is exiting via Fkill_emacs, which definitely calls
exit(). It took me awhile to figure this one out, but I finally got
it. I've been bitten by the dumping process. The glibc code for
__gmon_start__ looks like this:
------------------------------------------------------------------------
void
__gmon_start__ (void)
{
#ifdef HAVE_INITFINI
/* Protect from being called more than once. Since crti.o is linked
into every shared library, each of their init functions will call us. */
static int called;
if (called)
return;
called = 1;
#endif
/* Start keeping profiling records. */
__monstartup ((u_long) &_start, (u_long) &etext);
/* Call _mcleanup before exiting; it will write out gmon.out from the
collected data. */
atexit (&_mcleanup);
}
------------------------------------------------------------------------
So temacs, before dumping, has called = 0, and sets it to 1. The
value of 1 is then dumped, so xemacs enters __gmon_start__, says
"I've been here before!", and leaves.
Argh! This is going to make it kind of hard to profile XEmacs 21.1,
where --pdump is not available. Anyway, I used hexl mode to edit the
binary and changed the dumped value back to 0. Now I am getting profile
data out of xemacs. But this took so much time that I don't have time
to do the same to XEmacs 21.4 now. I'll get back to you later on that.
--
Jerry James