What I'm talking about is the Method Profiling in Eclipse or Android Device Monitor. When you choose a process from the list and press the button(I can't post image, the button is in the left of the 'stop' button), it will start recording the function stack of the process, and show you a detailed chart after you press stop.
What I want to know is how does it work? How does it get the function stack of a process by just knowing the pid? Does it use hook or something to do this?