xref: /freebsd/lib/libc/gmon/moncontrol.3 (revision 6b3455a7665208c366849f0b2b3bc916fb97516e)
1.\" Copyright (c) 1980, 1991, 1992, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)moncontrol.3	8.1 (Berkeley) 6/4/93
33.\" $FreeBSD$
34.\"
35.Dd June 14, 2004
36.Dt MONCONTROL 3
37.Os
38.Sh NAME
39.Nm moncontrol ,
40.Nm monstartup
41.Nd control execution profile
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In sys/types.h
46.In sys/gmon.h
47.Ft int
48.Fn moncontrol "int mode"
49.Ft int
50.Fn monstartup "u_long *lowpc" "u_long *highpc"
51.Sh DESCRIPTION
52An executable program compiled using the
53.Fl pg
54option to
55.Xr cc 1
56automatically includes calls to collect statistics for the
57.Xr gprof 1
58call-graph execution profiler.
59In typical operation, profiling begins at program startup
60and ends when the program calls exit.
61When the program exits, the profiling data are written to the file
62.Ar progname Ns Pa .gmon ,
63where progname is the name of the program, then
64.Xr gprof 1
65can be used to examine the results.
66.Pp
67The
68.Fn moncontrol
69function
70selectively controls profiling within a program.
71When the program starts, profiling begins.
72To stop the collection of histogram ticks and call counts use
73.Fn moncontrol 0 ;
74to resume the collection of histogram ticks and call counts use
75.Fn moncontrol 1 .
76This feature allows the cost of particular operations to be measured.
77Note that an output file will be produced on program exit
78regardless of the state of
79.Fn moncontrol .
80.Pp
81Programs that are not loaded with
82.Fl pg
83may selectively collect profiling statistics by calling
84.Fn monstartup
85with the range of addresses to be profiled.
86The
87.Fa lowpc
88and
89.Fa highpc
90arguments
91specify the address range that is to be sampled;
92the lowest address sampled is that of
93.Fa lowpc
94and the highest is just below
95.Fa highpc .
96Only functions in that range that have been compiled with the
97.Fl pg
98option to
99.Xr cc 1
100will appear in the call graph part of the output;
101however, all functions in that address range will
102have their execution time measured.
103Profiling begins on return from
104.Fn monstartup .
105.Sh FILES
106.Bl -tag -width progname.gmon -compact
107.It Pa progname.gmon
108execution data file
109.El
110.Sh SEE ALSO
111.Xr cc 1 ,
112.Xr gprof 1 ,
113.Xr profil 2 ,
114.Xr clocks 7
115