Does anybody use "gprof" ? Is it useful?

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, ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21