evilsong / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

cpuprofiler only profiler parent process (not fork child) #460

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile a multi-thread program against cpu profiler
2. run the program

What is the expected output? What do you see instead?
I call ProfileStart in with different filename after calling fork, and only the 
main thread get profile output, and the second thread get no result at all.

What version of the product are you using? On what operating system?
gperftools 2.0
archlinux 64
gcc (GCC) 4.7.1 20120721 (prerelease)

Please provide any additional information below.

Original issue reported on code.google.com by ranjiao on 8 Aug 2012 at 7:13

Attachments:

GoogleCodeExporter commented 9 years ago
I've been battling against this issue as well.  To be clear, I'm talking about 
sub-PROCESSES created using fork() here.

The problem seems to be that the interval timer is set only once at the start 
of the program.  Timers are not inherited by child processes (according "man 2 
fork").  The signal handler is set up when you call ProfileStart(), but the 
timer must be reset as well.  Try adding the following workaround either just 
after you call ProfileStart() or just after you fork().  This fixes the issue 
for me.

----->
struct itimerval t;
t.it_interval.tv_sec = 0;
t.it_interval.tv_usec = 1000;
t.it_value = t.it_interval;
setitimer(ITIMER_PROF, &t, NULL);
<-----

Original comment by t...@bitwiz.org.uk on 30 Nov 2012 at 1:29

GoogleCodeExporter commented 9 years ago
Alternatively, call ProfilerRegisterThread().  Perhaps an expert can comment on 
the correct way to make this work - the details don't seem to be in any of the 
documentation I could find.

Original comment by t...@bitwiz.org.uk on 30 Nov 2012 at 2:19

GoogleCodeExporter commented 9 years ago
Any chance one of you guys can provide a sample program that reproduces the 
issue so that we can try to put together a patch based on the above workaround?

Original comment by chapp...@gmail.com on 11 Mar 2013 at 1:08

GoogleCodeExporter commented 9 years ago
There's a simple one in the original post above, but here's another one which 
illustrates the workaround and the actual/expected results.

Original comment by t...@bitwiz.org.uk on 10 May 2013 at 1:16

Attachments:

GoogleCodeExporter commented 9 years ago
Issue 543 has been merged into this issue.

Original comment by alkondratenko on 15 Sep 2013 at 12:10

GoogleCodeExporter commented 9 years ago

Original comment by alkondratenko on 15 Sep 2013 at 12:37