On Mon, 27 Jun 2005 19:17:38 +0800, Morgan Cheng <mo***@nospam.nospam>
wrote:
Hi,
I am curious that how sampling profiler works.
How can a program(profiler) know the running detailis of another program?
I googled this topic and not much info is got. Is there anybody get some
insight about it?
Basically, you use a second process to examine what's happening in the
first process.
The obvious way to do this is to get your OS kernel to examine process
1 during timer interrupts. The timer interrupts process 1 regularly
(say, 50 or 100 times a second). The kernel records where the PC was
in process 1, storing the result in an array, before returning control
to process 1. When process 1 completes, the profiler gets this array
from the kernel, and translates the PC addresses into locations in the
source program using process 1's symbol table. Look up Unix's
profile() (I think that's right - I forget what the exact name is)
system call.
Easy!
AL