[PATCH] configure option for gprof file renaming

J. Robert von Behren jrvb at cs.berkeley.edu
Fri Jun 16 20:04:03 GMT 2000


Greetings, all.

I while back, I put posted to the list to see if people would be
interested in a patch to do some renaming of the gmon.out files
generated by gprof.  I've finally gotten around to cleaning this up
enough to make it (hopefully) useful to others.  ;-)  

The attached patch adds a configure option, --with-gprof-support=dir. 
When this is used, everything isc compiled with -pg, and a define is set
to enable the renaming function.  gmon.out file renaming is accomplished
by setting the GMON_OUT_PREFIX environment variable to
DIR/argv0.gmon.pid.  Since this feature isn't documented anywhere, a bit
of symlink mangling is also done to try to catch any systems on which
this environment variable is ignored.

The patch size grew quite large when I included some of the
autoconf-generated files, so I've left them out.  In order to use this,
you'll need to run "make distclean; autoconf; make proto" after applying
the patch.  I _think_ that should take care of everything.  ;-)  I've
attached my diff-excludes file as well, though, for reference.

Best,

-Rob
-------------- next part --------------
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/Makefile.in source.rob/Makefile.in
--- source/Makefile.in	Wed Jun 14 03:25:19 2000
+++ source.rob/Makefile.in	Wed Jun 14 10:20:05 2000
@@ -59,6 +59,9 @@
 # the directory where lock files go
 LOCKDIR = @lockdir@
 
+# directory for gmon.out files
+GMONDIR = @gmondir@
+
 # The directory where code page definition files go
 CODEPAGEDIR = $(LIBDIR)/codepages
 
@@ -77,7 +80,7 @@
 FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper $(CPPFLAGS) -DLOGFILEBASE=\"$(LOGFILEBASE)\"
 FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"  
 FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\"
-FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" -DBINDIR=\"$(BINDIR)\" -DFORMSFILE=\"$(FORMSFILE)\" -DNTDRIVERSDIR=\"$(NTDRIVERSDIR)\"
+FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" -DBINDIR=\"$(BINDIR)\" -DFORMSFILE=\"$(FORMSFILE)\" -DNTDRIVERSDIR=\"$(NTDRIVERSDIR)\" -DGMONDIR=\"$(GMONDIR)\"
 FLAGS5 = $(FLAGS1) $(FLAGS2) $(FLAGS3) $(FLAGS4) -DHAVE_INCLUDES_H
 FLAGS  = $(ISA) $(FLAGS5) $(PASSWD_FLAGS)
 FLAGS32  = $(ISA32) $(FLAGS5) $(PASSWD_FLAGS)
@@ -109,6 +112,7 @@
 	  lib/util.o lib/util_sock.o lib/util_sec.o smbd/ssl.o \
 	  lib/talloc.o lib/hash.o lib/substitute.o lib/fsusage.o \
 	  lib/ms_fnmatch.o lib/util_seaccess.o lib/select.o \
+	  lib/gprof_support.o \
 	  $(TDB_OBJ)
 
 UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/client/client.c source.rob/client/client.c
--- source/client/client.c	Sat Jun 10 22:57:54 2000
+++ source.rob/client/client.c	Sun Jun 11 14:06:43 2000
@@ -2201,6 +2201,10 @@
 	pstring new_name_resolve_order;
 	char *p;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 #ifdef KANJI
 	pstrcpy(term_code, KANJI);
 #else /* KANJI */
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/client/smbmnt.c source.rob/client/smbmnt.c
--- source/client/smbmnt.c	Mon Dec 13 05:27:02 1999
+++ source.rob/client/smbmnt.c	Mon Jun  5 09:49:28 2000
@@ -138,6 +138,9 @@
 	struct smb_mount_data data;
 	struct mntent ment;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
 	memset(&data, 0, sizeof(struct smb_mount_data));
 
 	if (argc < 2) {
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/client/smbmount.c source.rob/client/smbmount.c
--- source/client/smbmount.c	Mon May  1 19:23:36 2000
+++ source.rob/client/smbmount.c	Mon Jun  5 09:49:38 2000
@@ -627,6 +627,10 @@
 	static pstring servicesf = CONFIGFILE;
 	char *p;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	DEBUGLEVEL = 1;
 	
 	setup_logging("mount.smbfs",True);
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/configure.in source.rob/configure.in
--- source/configure.in	Fri Jun 16 12:17:34 2000
+++ source.rob/configure.in	Fri Jun 16 12:07:59 2000
@@ -1417,6 +1417,39 @@
 
 
 #################################################
+# check for special gprof output file naming support
+AC_MSG_CHECKING(whether to gprof file renaming)
+AC_ARG_WITH(gprof-support,
+[  --with-gprof-support=DIR   Include gmon.out file renaming support 
+  --without-gprof-support    Don't do gmon.out file renaming (default)],
+[ case "$withval" in
+  yes)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_GPROF_SUPPORT)
+    CFLAGS="-pg $CFLAGS"
+    LDFLAGS="-pg $LDFLAGS"
+    AC_MSG_WARN(--with-gprof-support called without argument - using default)
+    gmondir="/tmp"
+    AC_SUBST(gmondir)
+    ;;
+  no)
+    AC_MSG_RESULT(no)
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_GPROF_SUPPORT)
+    CFLAGS="-pg $CFLAGS"
+    LDFLAGS="-pg $LDFLAGS"
+    gmondir="$withval"
+    AC_SUBST(gmondir)
+    ;;
+  esac 
+],
+  AC_MSG_RESULT(no)
+)
+
+
+#################################################
 # check for experimental netatalk resource fork support
 AC_MSG_CHECKING(whether to support netatalk)
 AC_ARG_WITH(netatalk,
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/lib/gprof_support.c source.rob/lib/gprof_support.c
--- source/lib/gprof_support.c	Wed Dec 31 16:00:00 1969
+++ source.rob/lib/gprof_support.c	Tue Jun 13 22:51:52 2000
@@ -0,0 +1,103 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 1.9.
+   store smbd profiling information in shared memory
+   Copyright (C) Andrew Tridgell 1999
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "includes.h"
+
+#ifdef WITH_GPROF_SUPPORT
+#include "errno.h"
+
+extern int DEBUGLEVEL;
+
+void gprof_exit_func(void);
+
+static char *progname = NULL;
+static char *dir = GMONDIR;
+
+/*******************************************************************
+  Set up to create distinct gmon.out files for different processes.
+  If GLIBC is being used, this can be done by simply setting the
+  GMON_OUT_PREFIX environment variable appropriately.  Otherwise, an
+  exit function is defined to do some trickery with symlinks to get 
+  a sane filename.
+  ******************************************************************/
+void init_gprof_support(const char *program_name)
+{
+    int len;
+    char *temp;
+
+    /* save the last portion of the program name */
+    progname = strrchr(program_name,'/');
+    if(progname == NULL) progname = program_name;
+    else progname++; /* increment past the '/' */
+
+    /* decide on the appropriate file name prefix */
+    len = strlen("GMON_OUT_PREFIX=/.gmon") + strlen(dir) + strlen(progname);
+    len += 3; /* a bit of extra space */
+    temp = malloc(len);
+    if(temp== NULL) {
+        DEBUG(2,("Out of memory in init_gprof_support()\n"));
+        return;
+    }
+    snprintf(temp,len,"GMON_OUT_PREFIX=%s/%s.gmon",dir,progname);
+    putenv(temp);
+    free(temp);
+
+    /* set up the exit function */
+    atexit(gprof_exit_func);
+}
+
+
+/*******************************************************************
+  An exit function, to munge names of symlinks.
+  ******************************************************************/
+void gprof_exit_func(void)
+{
+    char outfile[200];
+
+    /* change to the desired output directory */
+    if(chdir(dir) != 0) {
+        DEBUG(2,("chdir() failed in gprof_exit_func()!\n"));
+        return;
+    }
+
+    /* remove any old gmon.out files */
+    if(unlink("gmon.out") != 0 && errno!=ENOENT) {
+        DEBUG(2,("unlink() failed in gprof_exit_func()!\n"));
+        return;
+    }
+    
+    /* create a symlink from dir/gmon.out -> dir/progname.gmon.pid */
+    snprintf(outfile,sizeof(outfile),"%s.gmon.%d",progname,getpid());
+    if(symlink(outfile,"gmon.out") != 0) {
+        DEBUG(2,("symlink() failed in gprof_exit_func()!\n"));
+        return;
+    }
+}
+
+
+
+
+
+#else
+ /* to keep compilers happy about empty modules */
+ void gprof_support_dummy(void) {}
+#endif
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/nmbd/nmbd.c source.rob/nmbd/nmbd.c
--- source/nmbd/nmbd.c	Wed May 10 02:49:54 2000
+++ source.rob/nmbd/nmbd.c	Mon Jun  5 09:50:42 2000
@@ -644,6 +644,10 @@
   extern char *optarg;
   extern BOOL  append_log;
 
+#ifdef WITH_GPROF_SUPPORT
+  init_gprof_support(argv[0]);
+#endif
+
   append_log = True;  /* Default, override with '-o' option. */
 
   global_nmb_port = NMB_PORT;
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/nsswitch/winbindd.c source.rob/nsswitch/winbindd.c
--- source/nsswitch/winbindd.c	Tue May  9 04:42:56 2000
+++ source.rob/nsswitch/winbindd.c	Mon Jun  5 09:51:12 2000
@@ -582,6 +582,10 @@
     BOOL interactive = False;
     int opt;
 
+#ifdef WITH_GPROF_SUPPORT
+    init_gprof_support(argv[0]);
+#endif
+
     while ((opt = getopt(argc, argv, "i")) != EOF) {
 	    switch (opt) {
 		case 'i':
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/smbd/server.c source.rob/smbd/server.c
--- source/smbd/server.c	Mon Jun 12 08:53:31 2000
+++ source.rob/smbd/server.c	Fri Jun 16 12:48:02 2000
@@ -520,6 +520,10 @@
 	set_auth_parameters(argc,argv);
 #endif
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	/* this is for people who can't start the program correctly */
 	while (argc > 1 && (*argv[1] != '-')) {
 		argv++;
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/smbwrapper/smbsh.c source.rob/smbwrapper/smbsh.c
--- source/smbwrapper/smbsh.c	Mon Dec 13 05:27:52 1999
+++ source.rob/smbwrapper/smbsh.c	Mon Jun  5 09:51:41 2000
@@ -42,6 +42,10 @@
 	extern char *optarg;
 	extern int optind;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	smbw_setup_shared();
 
 	while ((opt = getopt(argc, argv, "W:U:R:d:P:l:h")) != EOF) {
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/tdb/tdbtest.c source.rob/tdb/tdbtest.c
--- source/tdb/tdbtest.c	Sun Apr 30 17:41:47 2000
+++ source.rob/tdb/tdbtest.c	Mon Jun  5 09:52:12 2000
@@ -182,6 +182,10 @@
 	int i, seed=0;
 	int loops = 10000;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	unlink("test.gdbm");
 
 	db = tdb_open("test.tdb", 0, TDB_CLEAR_IF_FIRST, 
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/tdb/tdbtool.c source.rob/tdb/tdbtool.c
--- source/tdb/tdbtool.c	Mon Apr 24 07:36:44 2000
+++ source.rob/tdb/tdbtool.c	Mon Jun  5 09:52:30 2000
@@ -223,6 +223,10 @@
     char *line;
     char *tok;
 	
+#ifdef WITH_GPROF_SUPPORT
+    init_gprof_support(argv[0]);
+#endif
+
     while ((line = getline("tdb> "))) {
 
         /* Shell command */
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/tdb/tdbtorture.c source.rob/tdb/tdbtorture.c
--- source/tdb/tdbtorture.c	Sun Feb 27 16:38:45 2000
+++ source.rob/tdb/tdbtorture.c	Mon Jun  5 09:52:41 2000
@@ -94,6 +94,10 @@
 	int i, seed=0;
 	int loops = NLOOPS;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	for (i=0;i<NPROC-1;i++) {
 		if (fork() == 0) break;
 	}
diff --exclude-from=/tmp/diff-excludes -ur --new-file source/web/swat.c source.rob/web/swat.c
--- source/web/swat.c	Tue Apr 11 00:14:12 2000
+++ source.rob/web/swat.c	Mon Jun  5 09:53:21 2000
@@ -964,6 +964,10 @@
 	int opt;
 	char *page;
 
+#ifdef WITH_GPROF_SUPPORT
+        init_gprof_support(argv[0]);
+#endif
+
 	fault_setup(NULL);
 
 #if defined(HAVE_SET_AUTH_PARAMETERS)
-------------- next part --------------
CVS
*.o
Makefile
configure
bin
config.cache
config.log
config.status
config.h
config.h.in
proto.h
stamp-h



More information about the samba-technical mailing list