linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gprof, threads and forks
@ 2001-09-06  3:04 M. Edward Borasky
  2001-09-06  3:11 ` Mike Fedyk
  2001-09-06  3:42 ` Ian Lance Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: M. Edward Borasky @ 2001-09-06  3:04 UTC (permalink / raw)
  To: bug-binutils, linux-kernel, gcc-bugs; +Cc: jonathan.bright, aron

It's rare that I cross-post to this many lists, but

1. I blew a week trying to track this little monster down, and
2. It isn't at all clear to me where the appropriate fixes and documentation
changes need to be applied.

So here goes:

If you have an executable compiled with *gcc* using the "-pg" option, it is
supposed to generate a "gmon.out" file, which you can later process with the
*binutils* utility "gprof" to produce a profile. All this magic works just
dandy for a single threaded executable, but apparently child threads and
child processes created with "fork" don't get their execution time counted.
See the following links for the gory details:

http://sources.redhat.com/ml/bug-binutils/2001-q3/msg00090.html

http://uwsg.iu.edu/hypermail/linux/kernel/0101.3/1516.html

The second link implies that it's possible to fix this at the *kernel*
level. So my question to all of you is, "what's the best way to get this
fixed?" I need to profile a multi-threaded executable and personally don't
care about the "fork" case, but I'm sure there are others who would care
about forks and not threads.
--
M. Edward (Ed) Borasky, Chief Scientist, Borasky Research
http://www.borasky-research.net  http://www.aracnet.com/~znmeb
mailto:znmeb@borasky-research.com  mailto:znmeb@aracnet.com

Stand-Up Comedy: Because Man Does Not Live By Dread Alone


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gprof, threads and forks
  2001-09-06  3:04 gprof, threads and forks M. Edward Borasky
@ 2001-09-06  3:11 ` Mike Fedyk
  2001-09-06  3:42 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Fedyk @ 2001-09-06  3:11 UTC (permalink / raw)
  To: linux-kernel

On Wed, Sep 05, 2001 at 08:04:00PM -0700, M. Edward Borasky wrote:
> fixed?" I need to profile a multi-threaded executable and personally don't
> care about the "fork" case, but I'm sure there are others who would care
> about forks and not threads.

Did you try testing against an -ac kernel?  I believe there is a patch in
there that allows profiling of multi-threaded apps.  If it has made it into
the main kernel, then you can just ignore this message...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gprof, threads and forks
  2001-09-06  3:04 gprof, threads and forks M. Edward Borasky
  2001-09-06  3:11 ` Mike Fedyk
@ 2001-09-06  3:42 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2001-09-06  3:42 UTC (permalink / raw)
  To: M. Edward Borasky
  Cc: bug-binutils, linux-kernel, gcc-bugs, jonathan.bright, aron

"M. Edward Borasky" <znmeb@aracnet.com> writes:

> It's rare that I cross-post to this many lists, but
> 
> 1. I blew a week trying to track this little monster down, and
> 2. It isn't at all clear to me where the appropriate fixes and documentation
> changes need to be applied.
> 
> So here goes:
> 
> If you have an executable compiled with *gcc* using the "-pg" option, it is
> supposed to generate a "gmon.out" file, which you can later process with the
> *binutils* utility "gprof" to produce a profile. All this magic works just
> dandy for a single threaded executable, but apparently child threads and
> child processes created with "fork" don't get their execution time counted.
> See the following links for the gory details:
> 
> http://sources.redhat.com/ml/bug-binutils/2001-q3/msg00090.html
> 
> http://uwsg.iu.edu/hypermail/linux/kernel/0101.3/1516.html
> 
> The second link implies that it's possible to fix this at the *kernel*
> level. So my question to all of you is, "what's the best way to get this
> fixed?" I need to profile a multi-threaded executable and personally don't
> care about the "fork" case, but I'm sure there are others who would care
> about forks and not threads.

Fork is easy enough to handle, at least on GNU/Linux.  If you set the
environment variable GMON_OUT_PREFIX, glibc will automatically append
the process ID when writing the gmon.out file.  If you then also do
this in the child after calling fork:
		extern void _start (void), etext (void);
		monstartup ((u_long) &_start, (u_long) &etext);
you will a set of ${GMON_OUT_PREFIX}.pid files, one for the parent and
one for each child.

As far as I know, none of this is documented, though that might just
mean that I missed it.  I think glibc ought to document
GMON_OUT_PREFIX and the right way to call monstartup.

In principle threading could be handled the same way, but glibc would
need to cooperate when generating the profiling output file so that
each thread doesn't overwrite the same file.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-06  3:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-06  3:04 gprof, threads and forks M. Edward Borasky
2001-09-06  3:11 ` Mike Fedyk
2001-09-06  3:42 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).