added LIBC_SCCS condition for sccs ids
[unix-history] / usr / src / lib / libc / gmon / moncontrol.3
CommitLineData
8e556f67
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5c0bd1c3 5.\" @(#)moncontrol.3 6.1 (Berkeley) %G%
8e556f67 6.\"
5c0bd1c3 7.TH MONITOR 3 ""
8e556f67
KM
8.UC 4
9.SH NAME
4656920c 10monitor, monstartup, moncontrol \- prepare execution profile
8e556f67
KM
11.SH SYNOPSIS
12.nf
13.B monitor(lowpc, highpc, buffer, bufsize, nfunc)
14.B int (*lowpc)(), (*highpc)();
15.B short buffer[];
4656920c
KM
16.sp
17.B monstartup(lowpc, highpc)
18.B int (*lowpc)(), (*highpc)();
19.sp
20.B moncontrol(mode)
8e556f67
KM
21.fi
22.SH DESCRIPTION
4656920c
KM
23There are two different forms of monitoring available:
24An executable program created by:
25.IP " cc \-p . . ."
26.LP
27automatically includes calls for the
28.IR prof (1)
29monitor and includes an initial call to its start-up routine
30.I monstartup
8e556f67
KM
31with default parameters;
32.I monitor
4656920c
KM
33need not be called explicitly except to gain fine control over profil
34buffer allocation.
35An executable program created by:
36.IP " cc \-pg . . ."
37.LP
38automatically includes calls for the
39.IR gprof (1)
40monitor.
8e556f67 41.PP
4656920c
KM
42.I Monstartup
43is a high level interface to
8e556f67
KM
44.IR profil (2).
45.I Lowpc
46and
47.I highpc
4656920c 48specify the address range that is to be sampled; the lowest address sampled
8e556f67
KM
49is that of
50.I lowpc
4656920c 51and the highest is just below
8e556f67 52.IR highpc .
4656920c
KM
53.I Monstartup
54allocates space using
55.IR sbrk (2)
56and passes it to
57.I monitor
58(see below) to record a histogram of periodically sampled values of
59the program counter, and of counts of calls of certain functions, in the buffer.
60Only calls of functions compiled with the profiling option
8e556f67
KM
61.B \-p
62of
63.IR cc (1)
64are recorded.
8e556f67 65.PP
4656920c 66To profile the entire program, it is sufficient to use
8e556f67
KM
67.PP
68.nf
69 extern etext();
70 . . .
4656920c 71 monstartup((int) 2, etext);
8e556f67
KM
72.fi
73.PP
74.I Etext
4656920c 75lies just above all the program text, see
8e556f67
KM
76.IR end (3).
77.PP
4656920c 78To stop execution monitoring and write the results on the file
8e556f67
KM
79.I mon.out,
80use
81.PP
82 monitor(0);
83.LP
84then
85.IR prof (1)
4656920c
KM
86can be used to examine the results.
87.PP
88.I Moncontrol
89is used to selectively control profiling within a program.
90This works with either
91.IR prof (1)
92or
93.IR gprof (1)
94type profiling.
95When the program starts, profiling begins.
96To stop the collection of histogram ticks and call counts use
97.IR moncontrol (0);
98to resume the collection of histogram ticks and call counts use
99.IR moncontrol (1).
100This allows the cost of particular operations to be measured.
101Note that an output file will be produced upon program exit
102irregardless of the state of
103.I moncontrol.
104.PP
105.I Monitor
106is a low level interface to
107.IR profil (2).
108.I Lowpc
109and
110.I highpc
111are the addresses of two functions;
112.I buffer
113is the address of a (user supplied) array of
114.I bufsize
115short integers. At most
116.I nfunc
117call counts can be kept.
118For the results to be significant, especially where there are small, heavily
119used routines, it is suggested that the buffer be no more
120than a few times smaller than the range of locations sampled.
121.I Monitor
122divides the buffer into space to record the histogram
123of program counter samples over the range
124.I lowpc
125to
126.IR highpc ,
127and space to record call counts of functions compiled with the
128.B \-p
129option to
130.IR cc (1).
131.PP
132To profile the entire program, it is sufficient to use
133.PP
134.nf
135 extern etext();
136 . . .
137 monitor((int) 2, etext, buf, bufsize, nfunc);
138.fi
8e556f67
KM
139.SH FILES
140mon.out
141.SH "SEE ALSO"
4656920c 142cc(1), prof(1), gprof(1), profil(2), sbrk(2)