4.1cBSD/usr/man/man3/monitor.3

Compare this file to the similar file:
Show the results in this format:

.TH MONITOR 3  "19 January 1983"
.SH NAME
monitor, monstartup \- prepare execution profile
.SH SYNOPSIS
.nf
.B monitor(lowpc, highpc, buffer, bufsize, nfunc)
.B int (*lowpc)(), (*highpc)();
.B short buffer[];

.B monstartup(lowpc, highpc)
.B int (*lowpc)(), (*highpc)();
.fi
.SH DESCRIPTION
There are two different forms of monitoring available:
An executable program created by:
.IP  "cc \-p . . ."
.LP
automatically includes calls for
.I monstartup
with default parameters;
.I monitor
need not be called explicitly except to gain fine control over profiling.
An executable program created by:
.IP  "cc \-pg . . ."
.LP
obtains a different monitor.
.PP
.I Monstartup
is a high level interface to
.IR profil (2).
.I Lowpc
and
.I highpc
specify the address range that is to be sampled; the lowest address sampled
is that of
.I lowpc
and the highest is just below
.IR highpc .
.I Monstartup
allocates space using 
.IR sbrk (2)
and passes it to
.I monitor
(see below) to record a histogram of periodically sampled values of
the program counter, and of counts of calls of certain functions, in the buffer.
Only calls of functions compiled with the profiling option
.B \-p
of
.IR cc (1)
are recorded.
.PP
To profile the entire program, it is sufficient to use
.PP
.nf
	extern etext();
	. . .
	monstartup((int) 2, etext);
.fi
.PP
.I Etext
lies just above all the program text, see
.IR end (3).
.PP
To stop execution monitoring and write the results on the file
.I mon.out,
use
.PP
	monitor(0);
.LP
then
.IR prof (1)
can be used to examine the results.
.PP
.I Monitor
is a low level interface to
.IR profil (2).
.I Lowpc
and
.I highpc
are the addresses of two functions;
.I buffer
is the address of a (user supplied) array of
.I bufsize
short integers.  At most
.I nfunc
call counts can be kept.
For the results to be significant, especially where there are small, heavily
used routines, it is suggested that the buffer be no more
than a few times smaller than the range of locations sampled.
.I Monitor
divides the buffer into space to record the histogram
of program counter samples over the range
.I lowpc
to
.IR highpc ,
and space to record call counts of functions compiled with the 
.B \-p
option to
.IR cc (1).
.PP
To profile the entire program, it is sufficient to use
.PP
.nf
	extern etext();
	. . .
	monitor((int) 2, etext, buf, bufsize, nfunc);
.fi
.SH FILES
mon.out
.SH "SEE ALSO"
cc(1), prof(1), gprof(1), profil(2), sbrk(2)