Thread: Does anybody use "gprof" ? Is it useful?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    Does anybody use "gprof" ? Is it useful?

    Some people argue that gprof is not useful in multi-thread programming, is that true?
    Do you think gprof is useful, and why?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by meili100 View Post
    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.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    284
    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!

    Quote Originally Posted by brewbuck View Post
    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.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by meili100 View Post
    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?
    You use it to find out which parts of your code consume the most CPU time.

    (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?
    They don't, really. Signals are a poor synchronization mechanism in multi-threaded programs. Instead you have mutexes and condition variables.

Popular pages Recent additions subscribe to a feed