How to profile a multithreaded program using gprof?

Marcel Loose loose@astron.nl
Fri Nov 30 13:55:00 GMT 2007


Hi all,

I've been trying to profile a multithreaded program, but have not been
successful so far. Profiling a single-threaded program, however, does not
pose any problems.

Basically, I already fail to get a working executable at all; not to mention
the fact the gprof does not support profiling of multiple threads by default.

When linking a multithreaded program against the profiling C library
(libc_p.a) I either get a `Segmentation fault' or a `Floating exception' upon
thread creation.
SuSE 10.0 (64-bit)  : SIGSEGV in _dl_allocate_tls_init ()
SuSE 10.1 (64-bit)  : SIGFPE in profil ()
Ubuntu 7.10 (32-bit): SIGSEGV in _dl_get_tls_static_info ()

When I try to use libpthread_p.a instead I get a bunch of link errors, that
basically tell me that the size of symbols like __flock_file are different
between libc_p.a and libpthread_p.a. What the ...? 

Ok, suppose I could solve this problem (I don't know how, but suppose), then I
could enable support for profiling multiple threads, using Sam Hocevar's
`gprof-helper.c' (http://sam.zoy.org/writings/programming/gprof.html). But
then, the dynamic loader sends me to misery land when I've linked my program
against libc_p; it fails to dynamically load the pthread_create symbol at
run-time. Sigh!

Does anyone have a suggestion on how to profile a multithreaded application?
Any help would be very much appreciated.


Kind regards,

Marcel Loose.



More information about the Binutils mailing list