Originally Posted by
brewbuck
gprof is extremely useful. And the comment about multithreading is true.
Profiling works in two simultaneous ways: First, a SIGPROF is delivered periodically to the process, which causes a hit counter to be incremented for the current instruction. Second, all entry/exit points from all functions are monitored and counted accurately. Both of these are problematic in a multithreaded context.
Under POSIX threading, only a single thread can receive a signal. This includes SIGPROF. Therefore, only one thread will be profile-counted. But even if we could fix this problem, it still isn't enough, because the gmon layer only maintains a single count table for the entire process. So it would be impossible to distinguish the time used by various threads.
This is not to say that using gprof is impossible in a multithreaded application, but it will only be able to profile one of the threads.