This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gprof profiling of multi-threaded Cygwin programs


I've attached a patch set modifying Cygwin's profiling support to sample PC values of all an application's threads, not just the main thread. There is no change to how profiling is requested: just compile and link the app with "-pg" as usual. The profiling info is dumped into file gmon.out as usual.

There is a behavioral change that ought to be documented somewhere: If a gmon.out file exists when a profiled application exits, the app will now dump its profiling info into another file gmon.outXXXXXX where mkstemp() replaces the Xs with random alphanumerics. I added this functionality to allow a profiled program to fork() yet retain profiling info for both parent and child. The old behavior was to simply overwrite any existing gmon.out file.

There is no change to the normal Cygwin execution paths if profiling is not enabled. And when it is enabled, only the one profiling thread per profiled app is doing more work than it used to.

Here's a change log of the modifications; all files are in winsup/cygwin:

        * common.din (cygheap_profthr_all): Export.
        * cygheap.cc (cygheap_profthr_all): Implement a C-callable function
        that runs cygheap's threadlist handing each pthread's thread handle
        in turn to profthr_byhandle().
        * gmon.c (_mcleanup): Added support for multiple simultaneous
        gmon.out* files created when necessary using mkstemp(). Added
        #include <errno.h>, added extern decl for _setmode().
        * gmon.h (struct gmonparam): Made state decl volatile.
        * mcount.c (_MCOUNT_DECL): Changed stores into gmonparam.state to use
        Interlocked operations. Added #include "winsup.h", updated commentary.
        * profil.c (profthr_byhandle): New function abstracting out the
        updating of profile counters based on a thread handle.
        (profthr_func): Updated to call profthr_byhandle() to sample the main
        thread then call cygheap_profthr_all() to sample all other pthreads.

Thanks for reading,

..mark

Attachment: mt-profiling.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]