# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
-# $FreeBSD: src/lib/libc/gmon/Makefile.inc,v 1.7.2.1 2001/04/25 10:04:05 ru Exp $
+# $FreeBSD: src/lib/libc/gmon/Makefile.inc,v 1.12 2006/10/28 13:34:35 bde Exp $
# $DragonFly: src/lib/libc/gmon/Makefile.inc,v 1.2 2003/06/17 04:26:42 dillon Exp $
# gmon sources
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libc/gmon/gmon.c,v 1.8 2000/01/27 23:06:25 jasone Exp $
- * $DragonFly: src/lib/libc/gmon/gmon.c,v 1.8 2005/11/13 01:18:20 swildner Exp $
- *
* @(#)gmon.c 8.1 (Berkeley) 6/4/93
+ * $FreeBSD: src/lib/libc/gmon/gmon.c,v 1.22 2007/01/09 00:27:58 imp Exp $
+ * $DragonFly: src/lib/libc/gmon/gmon.c,v 1.8 2005/11/13 01:18:20 swildner Exp $
*/
#include "namespace.h"
#include <sys/sysctl.h>
#include <err.h>
-#include <errno.h>
-#include <stdio.h>
#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "un-namespace.h"
-#if defined(__i386__) || defined(__amd64__)
-extern char *minbrk asm (".minbrk");
+#include "libc_private.h"
+
+#if defined(__i386__) || defined(__sparc64__) || defined(__amd64__) || defined(__powerpc__)
+extern char *minbrk __asm (".minbrk");
#else
-extern char *minbrk asm ("minbrk");
+extern char *minbrk __asm ("minbrk");
#endif
struct gmonparam _gmonparam = { GMON_PROF_OFF };
#define ERR(s) _write(2, s, sizeof(s))
-void moncontrol (int);
-static int hertz (void);
+void moncontrol(int);
+static int hertz(void);
void
monstartup(u_long lowpc, u_long highpc)
}
moncontrol(0);
- snprintf(outname, sizeof(outname), "%s.gmon", getprogname());
+ snprintf(outname, sizeof(outname), "%s.gmon", _getprogname());
fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
- warnx("_mcleanup: %s - %s",outname,strerror(errno));
+ _warn("_mcleanup: %s", outname);
return;
}
#ifdef DEBUG
log = _open("gmon.log", O_CREAT|O_TRUNC|O_WRONLY, 0664);
if (log < 0) {
- perror("_mcleanup: gmon.log");
+ _warn("_mcleanup: gmon.log");
return;
}
- len = sprintf(buf, "[mcleanup1] kcount 0x%x ssiz %d\n",
+ len = sprintf(buf, "[mcleanup1] kcount 0x%p ssiz %lu\n",
p->kcount, p->kcountsize);
_write(log, buf, len);
#endif
hdr = (struct gmonhdr *)&gmonhdr;
+ bzero(hdr, sizeof(*hdr));
hdr->lpc = p->lowpc;
hdr->hpc = p->highpc;
hdr->ncnt = p->kcountsize + sizeof(gmonhdr);
toindex = p->tos[toindex].link) {
#ifdef DEBUG
len = sprintf(buf,
- "[mcleanup2] frompc 0x%x selfpc 0x%x count %d\n" ,
+ "[mcleanup2] frompc 0x%lx selfpc 0x%lx count %lu\n" ,
frompc, p->tos[toindex].selfpc,
p->tos[toindex].count);
_write(log, buf, len);
* SUCH DAMAGE.
*
* @(#)mcount.c 8.1 (Berkeley) 6/4/93
- * $FreeBSD: src/lib/libc/gmon/mcount.c,v 1.17 1999/12/29 05:04:13 peter Exp $
+ * $FreeBSD: src/lib/libc/gmon/mcount.c,v 1.20 2004/10/16 06:32:43 obrien Exp $
* $DragonFly: src/lib/libc/gmon/mcount.c,v 1.5 2005/11/13 01:18:20 swildner Exp $
*/
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
-void bintr (void);
-void btrap (void);
-void eintr (void);
-void user (void);
+void bintr(void);
+void btrap(void);
+void eintr(void);
+void user(void);
#endif
/*
* Note: the original BSD code used the same variable (frompcindex) for
* both frompcindex and frompc. Any reasonable, modern compiler will
* perform this optimization.
- *
- * _mcount; may be static, inline, etc
*/
+/* _mcount; may be static, inline, etc */
_MCOUNT_DECL(uintfptr_t frompc, uintfptr_t selfpc)
{
#ifdef GUPROF
#ifdef _KERNEL
MCOUNT_ENTER(s);
#else
- p->state = GMON_PROF_BUSY;
+ p->state = GMON_PROF_BUSY; /* XXX */
#endif
frompci = frompc - p->lowpc;
#ifdef _KERNEL
MCOUNT_EXIT(s);
#else
- p->state = GMON_PROF_ON;
+ p->state = GMON_PROF_ON; /* XXX */
#endif
return;
overflow:
- p->state = GMON_PROF_ERROR;
+ p->state = GMON_PROF_ERROR; /* XXX */
#ifdef _KERNEL
MCOUNT_EXIT(s);
#endif
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" SUCH DAMAGE.
.\"
.\" @(#)moncontrol.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gmon/moncontrol.3,v 1.6.2.5 2001/12/14 18:33:54 ru Exp $
+.\" $FreeBSD: src/lib/libc/gmon/moncontrol.3,v 1.17 2007/01/09 00:27:58 imp Exp $
.\" $DragonFly: src/lib/libc/gmon/moncontrol.3,v 1.2 2003/06/17 04:26:42 dillon Exp $
.\"
-.Dd June 4, 1993
+.Dd June 14, 2004
.Dt MONCONTROL 3
.Os
.Sh NAME
.Lb libc
.Sh SYNOPSIS
.In sys/types.h
-.Ft int
+.In sys/gmon.h
+.Ft void
.Fn moncontrol "int mode"
-.Ft int
-.Fn monstartup "u_long *lowpc" "u_long *highpc"
+.Ft void
+.Fn monstartup "u_long lowpc" "u_long highpc"
.Sh DESCRIPTION
An executable program compiled using the
.Fl pg
In typical operation, profiling begins at program startup
and ends when the program calls exit.
When the program exits, the profiling data are written to the file
-.Em progname.gmon ,
+.Ar progname Ns Pa .gmon ,
where progname is the name of the program, then
.Xr gprof 1
can be used to examine the results.
.Pp
+The
.Fn moncontrol
+function
selectively controls profiling within a program.
When the program starts, profiling begins.
To stop the collection of histogram ticks and call counts use
may selectively collect profiling statistics by calling
.Fn monstartup
with the range of addresses to be profiled.
+The
.Fa lowpc
and
.Fa highpc
+arguments
specify the address range that is to be sampled;
the lowest address sampled is that of
.Fa lowpc