diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac index 17c7aa64..b6ded7bc 100644 --- a/jemalloc/configure.ac +++ b/jemalloc/configure.ac @@ -688,10 +688,13 @@ fi AC_SUBST([enable_prof]) if test "x$enable_prof" = "x0" ; then roff_prof=".\\\" " + roff_no_prof="" else roff_prof="" + roff_no_prof=".\\\" " fi AC_SUBST([roff_prof]) +AC_SUBST([roff_no_prof]) dnl If libunwind isn't enabled, try to use libgcc rather than gcc intrinsics dnl for backtracing. diff --git a/jemalloc/doc/jemalloc.3.in b/jemalloc/doc/jemalloc.3.in index e6611777..3865ac9b 100644 --- a/jemalloc/doc/jemalloc.3.in +++ b/jemalloc/doc/jemalloc.3.in @@ -38,7 +38,7 @@ .\" @(#)malloc.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD: head/lib/libc/stdlib/malloc.3 182225 2008-08-27 02:00:53Z jasone $ .\" -.Dd January 27, 2010 +.Dd February 11, 2010 .Dt JEMALLOC 3 .Os .Sh NAME @@ -345,7 +345,12 @@ will disable dirty page purging. @roff_prof@.Xr atexit 3 @roff_prof@function to dump final memory usage to a file named according to @roff_prof@the pattern -@roff_prof@.Pa jeprof...f.heap . +@roff_prof@.Pa ...f.heap , +@roff_prof@where +@roff_prof@.Pa +@roff_prof@is controlled by the +@roff_prof@JEMALLOC_PROF_PREFIX +@roff_prof@environment variable. @roff_prof@See the @roff_prof@.Dq B @roff_prof@option for backtrace depth control. @@ -390,7 +395,12 @@ will disable dirty page purging. @roff_prof@This is an artifact of the concurrent algorithm that is used to @roff_prof@track allocation activity. @roff_prof@Profiles are dumped to files named according to the pattern -@roff_prof@.Pa jeprof...i.heap . +@roff_prof@.Pa ...i.heap , +@roff_prof@where +@roff_prof@.Pa +@roff_prof@is controlled by the +@roff_prof@JEMALLOC_PROF_PREFIX +@roff_prof@environment variable. @roff_prof@The default maximum interval is 4 GiB. @roff_fill@.It J @roff_fill@Each byte of new memory allocated by @@ -474,7 +484,12 @@ The default value is 128 bytes. @roff_prof@Trigger a memory profile dump every time the total virtual memory @roff_prof@exceeds the previous maximum. @roff_prof@Profiles are dumped to files named according to the pattern -@roff_prof@.Pa jeprof...u.heap . +@roff_prof@.Pa ...u.heap , +@roff_prof@where +@roff_prof@.Pa +@roff_prof@is controlled by the +@roff_prof@JEMALLOC_PROF_PREFIX +@roff_prof@environment variable. @roff_prof@This option is disabled by default. @roff_sysv@.It V @roff_sysv@Attempting to allocate zero bytes will return a @@ -970,7 +985,12 @@ Maximum size supported by this large size class. @roff_prof@.It Sy "prof.dump (void) --" @roff_prof@.Bd -ragged -offset indent -compact @roff_prof@Dump a memory profile to a file according to the pattern -@roff_prof@.Pa jeprof...m.heap . +@roff_prof@.Pa ...m.heap , +@roff_prof@where +@roff_prof@.Pa +@roff_prof@is controlled by the +@roff_prof@JEMALLOC_PROF_PREFIX +@roff_prof@environment variable. @roff_prof@.Ed .\"----------------------------------------------------------------------------- @roff_stats@.It Sy "stats.allocated (size_t) r-" @@ -1356,12 +1376,19 @@ read/write processing. .Sh ENVIRONMENT The following environment variables affect the execution of the allocation functions: -.Bl -tag -width ".Ev JEMALLOC_OPTIONS" +@roff_prof@.Bl -tag -width ".Ev JEMALLOC_PROF_PREFIX" +@roff_no_prof@.Bl -tag -width ".Ev JEMALLOC_OPTIONS" .It Ev JEMALLOC_OPTIONS If the environment variable .Ev JEMALLOC_OPTIONS is set, the characters it contains will be interpreted as flags to the allocation functions. +@roff_prof@.It Ev JEMALLOC_PROF_PREFIX +@roff_prof@If the environment variable +@roff_prof@.Ev JEMALLOC_PROF_PREFIX +@roff_prof@is set, use itas the filename prefix for profile dumps; otherwise use +@roff_prof@.Pa jeprof +@roff_prof@as the prefix. .El .Sh EXAMPLES To dump core whenever a problem occurs: diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c index f471c6a1..8f69c01f 100644 --- a/jemalloc/src/prof.c +++ b/jemalloc/src/prof.c @@ -854,13 +854,12 @@ prof_dump(const char *filename, bool leakcheck) } } -/* jeprof...v.heap\0 */ -#define DUMP_FILENAME_BUFSIZE (7 + UMAX2S_BUFSIZE \ - + 1 \ - + UMAX2S_BUFSIZE \ - + 2 \ - + UMAX2S_BUFSIZE \ - + 5 + 1) +#define DUMP_FILENAME_BUFSIZE (PATH_MAX+ UMAX2S_BUFSIZE \ + + 1 \ + + UMAX2S_BUFSIZE \ + + 2 \ + + UMAX2S_BUFSIZE \ + + 5 + 1) static void prof_dump_filename(char *filename, char v, int64_t vseq) { @@ -868,9 +867,30 @@ prof_dump_filename(char *filename, char v, int64_t vseq) char *s; unsigned i, slen; + /* + * Construct a filename of the form: + * + * ...v.heap\0 + * or + * jeprof...v.heap\0 + */ + i = 0; - s = "jeprof."; + /* + * Use JEMALLOC_PROF_PREFIX if it's set, and if it is short enough to + * avoid overflowing DUMP_FILENAME_BUFSIZE. The result may exceed + * PATH_MAX, but creat(2) will catch that problem. + */ + if ((s = getenv("JEMALLOC_PROF_PREFIX")) != NULL + && strlen(s) + (DUMP_FILENAME_BUFSIZE - PATH_MAX) <= PATH_MAX) { + slen = strlen(s); + memcpy(&filename[i], s, slen); + i += slen; + + s = "."; + } else + s = "jeprof."; slen = strlen(s); memcpy(&filename[i], s, slen); i += slen;