Sample will allow you to profile a process during runtime without recompiling it.

Download at github

How it works

sample will retrieve the stack trace of all threads of a given process every 10 ms during a delay that was given by the user. This uses ptrace to get the stack trace information. These stack trace will be grouped by thread, then by callers to get a call tree. sample will count how many times a given call stack has been reported: this is the number on the left of the function name.



$ sample [pid] [delay-in-seconds] > sample-result.txt
When finished, the data will be shown as a call tree . The number on the left will show how much time was spent in each function. By using the following command, the results will be shown in a GUI.
$ gtk-sample sample-result.txt

Here how you read it