William A. Barath <wi534@victoria.tc.ca> wrote:>The most efficient way I can imagine to do it is this: compile into>each function a small code fragment at the entry and exit points which>read a global variable containing the seed of a high-resolution timer>and add the difference between the two reads to a table entry for that>function.
[...]>[That's what Unix C compilers do with the -p flag. -John]

However, this method won't work correctly for recursive functions.

Unix C compilers that use -p or -pg for profiling usually rely on
sampling techniques: the value of program counter is sampled periodically,
and use the distribution of samples to infer an execution profile. See: