> And the patch is where?

You caught me; guess I'd better make something up fast, huh?

Here it is, thanks.

            -- Korry


> 
> ---------------------------------------------------------------------------
> 
> [EMAIL PROTECTED] wrote:
> > It's difficult to profile a backend server process  (using gprof)
> > because each process overwrites any earlier profile as it exits.
> > 
> > It is especially tricky to nab a useful profile if you happen to have
> > autovacuum enabled.
> > 
> > This patch reduces the problem by forcing the backend to 'cd' to a new
> > directory ($PGDATA/gprof/pid) just before calling exit(), but only if
> > the backend was compiled with -DLINUX_PROFILE.
> > 
> > I've tested this with Linux, but not with other host architectures. 
> > 
> >         -- Korry
> > 
> > 
> > 
> > --
> >   Korry Douglas    [EMAIL PROTECTED]
> >   EnterpriseDB      http://www.enterprisedb.com
> 



--
  Korry Douglas    [EMAIL PROTECTED]
  EnterpriseDB      http://www.enterprisedb.com
Index: src/backend/storage/ipc/ipc.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v
retrieving revision 1.95
diff -c -r1.95 ipc.c
*** src/backend/storage/ipc/ipc.c	5 Jan 2007 22:19:37 -0000	1.95
--- src/backend/storage/ipc/ipc.c	31 Jan 2007 15:48:55 -0000
***************
*** 110,115 ****
--- 110,145 ----
  								  on_proc_exit_list[on_proc_exit_index].arg);
  
  	elog(DEBUG3, "exit(%d)", code);
+ 
+ #ifdef LINUX_PROFILE
+     {
+         /*
+          * If we are profiling ourself then gprof's mcleanup() is about
+          * to write out a profile to ./gmon.out.  Since mcleanup() always 
+          * uses a fixed file name, each backend will overwrite earlier
+          * profiles. To fix that, we create a separate subdirectory for
+          * each backend (./gprof/pid) and 'cd' to that subdirectory before
+          * we exit() - that forces mcleanup() to write each profile into
+          * its own directory.  We end up with something like:
+          *  $PGDATA/gprof/8829/gmon.out
+          *  $PGDATA/gprof/8845/gmon.out
+          *      ...
+          *
+          * Note that we do this here instead of in an on_proc_exit() 
+          * callback because we want to ensure that this code executes
+          * last - we don't want to interfere with any other on_proc_exit()
+          * callback.
+          */
+         char gprofDirName[MAXPGPATH];
+ 
+         snprintf(gprofDirName, MAXPGPATH, "./gprof/%d", getpid());
+         
+         mkdir("./gprof", 0777);
+         mkdir(gprofDirName, 0777);
+         chdir(gprofDirName);
+     }
+ #endif
+ 
  	exit(code);
  }
  
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to