Some people argue that gprof is not useful in multi-thread programming, is that true?
Do you think gprof is useful, and why?
This is a discussion on Does anybody use "gprof" ? Is it useful? within the C++ Programming forums, part of the General Programming Boards category; Some people argue that gprof is not useful in multi-thread programming, is that true? Do you think gprof is useful, ...
Some people argue that gprof is not useful in multi-thread programming, is that true?
Do you think gprof is useful, and why?
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.
Thank you, brewbuck, but I am still a little confused about:
(1) Why people use gprof. Would you name few examples you think gprof is useful in?
(2) In a multiple threading program, I don't understand why only single thread receives signal? How do other threads communicate (or synchronize) by signal?
Thanks!
You use it to find out which parts of your code consume the most CPU time.
They don't, really. Signals are a poor synchronization mechanism in multi-threaded programs. Instead you have mutexes and condition variables.(2) In a multiple threading program, I don't understand why only single thread receives signal? How do other threads communicate (or synchronize) by signal?