next up previous contents
Next: gprof --- Call Up: Profiling Mechanisms Previous: Profiling Mechanisms

prof --- PC Sampling

To prepare for using the prof program, the programmer gives the C compiler and linkers an option (usually -p) at compile- and link-time. The compiler generates additional code in each function's prologue, including a call to the function mcount(), and creates an unique storage slot for each functiongif; the linker links in a special startup function. During program execution, the startup function enables a periodic operating system timer interrupt, which typically operates at 100 Hertz. The handler for the interrupt samples the program counter (PC) value when the interrupt occurs and uses it to index to the appropriate bin, which stores a count that it increments. Data gathered is thus of a statistical nature. The prof program post-processes the raw bin counts into human-readable output by totalling the counts in the bins which correspond to each function symbol in the executable's symbol table.



Reinventing Computing, MIT AI Lab. Author: pshuang@ai.mit.edu (Ping Huang)