When you use the gprof, you only know that the original gprof can only be counted on the main thread. There are no thread-related issues on the manual.
But there are ready-made solutions: http://sam.zoy.org/writings/programming/gprof.html
The scheme encapsulates the pthread_create (), allowing the thread to initialize the execution of a setitimer (Itimer_prof, ...).
An easy way to do this is to write a setitimer () directly in your code.
#include <sys/time.h>
#include <boost/thread.hpp>
struct itimerval g_itimer;
void foo ()
{
Setitimer (itimer_prof, &g_itimer, NULL);
for (int i = 0; i < 10000000 i++)
(void) i;
}
int main ()
{
Getitimer (itimer_prof, &g_itimer);
Boost::thread T (&foo);
T.join ();
return 0;
}
g++ Main.cpp-pg-lboost_thread
./a.out
Gprof
This will help you to count the time consuming foo (). There will be no time-consuming statistics for foo () without Setitimer ().