Add JEMALLOC_PROF_PREFIX support.

If JEMALLOC_PROF_PREFIX is set in the environment, use it as the
filename prefix when dumping heap profiles, rather than "jeprof".
This commit is contained in:
Jason Evans 2010-02-11 10:25:36 -08:00
parent c717718115
commit b01a6c2057
3 changed files with 64 additions and 14 deletions

View File

@ -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.

View File

@ -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.<pid>.<seq>.f.heap .
@roff_prof@.Pa <prefix>.<pid>.<seq>.f.heap ,
@roff_prof@where
@roff_prof@.Pa <prefix>
@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.<pid>.<seq>.i<iseq>.heap .
@roff_prof@.Pa <prefix>.<pid>.<seq>.i<iseq>.heap ,
@roff_prof@where
@roff_prof@.Pa <prefix>
@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.<pid>.<seq>.u<useq>.heap .
@roff_prof@.Pa <prefix>.<pid>.<seq>.u<useq>.heap ,
@roff_prof@where
@roff_prof@.Pa <prefix>
@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.<pid>.<seq>.m<mseq>.heap .
@roff_prof@.Pa <prefix>.<pid>.<seq>.m<mseq>.heap ,
@roff_prof@where
@roff_prof@.Pa <prefix>
@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:

View File

@ -854,8 +854,7 @@ prof_dump(const char *filename, bool leakcheck)
}
}
/* jeprof.<pid>.<seq>.v<vseq>.heap\0 */
#define DUMP_FILENAME_BUFSIZE (7 + UMAX2S_BUFSIZE \
#define DUMP_FILENAME_BUFSIZE (PATH_MAX+ UMAX2S_BUFSIZE \
+ 1 \
+ UMAX2S_BUFSIZE \
+ 2 \
@ -868,8 +867,29 @@ prof_dump_filename(char *filename, char v, int64_t vseq)
char *s;
unsigned i, slen;
/*
* Construct a filename of the form:
*
* <prefix>.<pid>.<seq>.v<vseq>.heap\0
* or
* jeprof.<pid>.<seq>.v<vseq>.heap\0
*/
i = 0;
/*
* 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);