bin/99800: [PATCH] Add support for profiling multiple executions

Peter Jeremy peterjeremy at
Wed Jul 5 09:30:24 UTC 2006

>Number:         99800
>Category:       bin
>Synopsis:       [PATCH] Add support for profiling multiple executions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 05 09:30:21 GMT 2006
>Originator:     Peter Jeremy
>Release:        FreeBSD 6.1-STABLE amd64
System: FreeBSD 6.1-STABLE FreeBSD 6.1-STABLE #19: Tue Jul 4 17:56:20 EST 2006 root at amd64

	gprof(1) has support for merging multiple gmon.out files but
	the name 'NAME.gmon' is hard-wired in the profiling code and
	any existing NAME.gmon file is over-written.

	The patch below allows a process to create 'NAME.PID.gmon' by
	creating an enviroment variable "PROFIL_USE_PID".

	Code inspection shows that NAME.gmon is hard-coded and truncated.
Index: lib/libc/gmon/gmon.c
RCS file: /usr/ncvs/src/lib/libc/gmon/gmon.c,v
retrieving revision 1.20
diff -u -r1.20 gmon.c
--- lib/libc/gmon/gmon.c	16 Oct 2004 06:32:43 -0000	1.20
+++ lib/libc/gmon/gmon.c	21 May 2006 19:11:14 -0000
@@ -174,7 +174,11 @@
-	snprintf(outname, sizeof(outname), "%s.gmon", _getprogname());
+	if (getenv("PROFIL_USE_PID"))
+		snprintf(outname, sizeof(outname), "%s.%d.gmon",
+			_getprogname(), getpid());
+	else
+		snprintf(outname, sizeof(outname), "%s.gmon", _getprogname());
 	fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666);
 	if (fd < 0) {
 		_warn("_mcleanup: %s", outname);

More information about the freebsd-bugs mailing list