massive overhaul for new profiling structure from mccanne at LBL
[unix-history] / usr / src / lib / libc / gmon / moncontrol.3
.\" Copyright (c) 1980, 1991 Regents of the University of California.
.\" All rights reserved.
.\"
.\" %sccs.include.proprietary.roff%
.\"
.\" @(#)moncontrol.3 6.3 (Berkeley) %G%
.\"
.TH MONCONTROL 3 ""
.UC 4
.SH NAME
moncontrol, monstartup \- prepare execution profile
.SH SYNOPSIS
.nf
.B moncontrol(mode)
.B int mode;
.sp
.B monstartup(lowpc, highpc)
.B int (*lowpc)(), (*highpc)();
.fi
.SH DESCRIPTION
.PP
An executable program created by:
.IP " cc \-pg . . ."
.LP
automatically includes calls to collect statistics for the
.IR gprof (1)
call-graph execution profiler.
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
.IR gmon.out ,
then
.IR gprof (1)
can be used to examine the results.
.PP
.I Moncontrol
selectively controls profiling within a program.
When the program starts, profiling begins.
To stop the collection of histogram ticks and call counts use
.IR moncontrol (0);
to resume the collection of histogram ticks and call counts use
.IR moncontrol (1).
This allows the cost of particular operations to be measured.
Note that an output file will be produced on program exit
regardless of the state of
.I moncontrol.
.PP
Programs that are not loaded with
.IP " cc \-pg . . ."
.LP
may selectively collect profiling statistics by calling
.I monstartup
with the range of addresses to be profiled.
.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 .
Only functions in that range that have been compiled with the
.B \-p
option to
.IR cc (1)
will appear in the call graph part of the output;
however, all functions in that address range will
have their execution time measured.
Profiling begins on return from
.IR monstartup .
.PP
To stop execution monitoring and write the results on the file
.I gmon.out,
use
.PP
_mcleanup();
.LP
then
.IR gprof (1)
can be used to examine the results.
.SH FILES
gmon.out
.SH "SEE ALSO"
cc(1), gprof(1), profil(2)