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