monitor(3)
NAME
monitor − prepare execution profile
SYNTAX
void monitor(lowpcf, highpc, buffer, bufsize, nfunc)
int (*lowpc)(), (*highpc)();
short buffer[];
int bufsize, nfunc;
DESCRIPTION
An executable program created by “cc −p” automatically includes calls for monitor with default parameters. The monitor subroutine needn’t be called explicitly except to gain fine control over profiling.
The monitor subroutine is an interface to profil(2). The lowpc and highpc are the addresses of two functions. The buffer is the address of a (user supplied) array of bufsize short integers. The monitor subroutine arranges to record a histogram of periodically sampled values of the program counter, and of counts of calls of certain functions, in the buffer. The lowest address sampled is that of lowpc and the highest is just below highpc. At most, nfunc call counts can be kept. Only calls of functions compiled with the profiling option −p of cc(1) are recorded. 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.
To profile the entire program, it is sufficient to use
extern etext();
monitor((int)2, etext, buf, bufsize, nfunc);
The etext lies just above all the program text. For further information, see end(3).
To stop execution monitoring and write the results on the file mon.out, use
monitor(0);
Then prof(1) can be used to examine the results.
FILES
mon.out