This is a more comprehensive patch. It actually works properly under gdb. Key notes: 1) cyggmon.dll has the gmon code to allow multiple dlls and the actual .exe to all share the all-important _gmonparam symbol. 2) The 100-odd Mb gmon.out is a side-effect of some apparent assumptions on the symbol table layout in memory. Win32's sparse layout really drives the current code hard for storage, and I've tried to find a happy medium. if you have a low-memory machine, I suggest pushing the constants in gmon.h up to 30 or 40 to get a smaller gmon.out. 3) To link a new program with libgmon.a, be sure to add -limagehlp to the link line. The gcc specs file can also be altered, of course. 4) gprof seems unable to find the symbols that are referenced in the gmon.out call-graph. I think it needs work to make it search the .dll's used by the profiled file, or perhaps to allow specifying multiple images on the command line. I make this assumption because only symbols present in the image are identified by gprof, as the appended output shows - the etext and <hicore> are dll call AFAICT.
Anyway, I don't have time to look into gprof.exe myself. I think that the -hard- part
has been done, which was getting a clean-running gmon'd cygwin1.dll. There is one more
hard thing to do with the profilable .dll, and that is fork() support, as the
virtualAlloc'd ram isn't copied across AFAICT. That's alrigh, as atfork() should allow
that to be addressed with a little care.
Anway, I'm putting this on hold until gprof is reviewed, whether by me or someone else.
Rob
G:\Users\RobertC\src\pthreadtest>gprof --file-info -l -p -q -b deadlock.exe dead
lock.out
File `deadlock.out' (version 0) contains:
1 histogram record
153 call-graph records
0 basic-block count records
♀
Flat profile:
Each sample counts as 0.01 seconds.
no time accumulated
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 868 0.00 0.00 etext
0.00 0.00 0.00 1 0.00 0.00 __monstartup
0.00 0.00 0.00 1 0.00 0.00 _main
0.00 0.00 0.00 1 0.00 0.00 _t1
0.00 0.00 0.00 1 0.00 0.00 _t2
♀
Call graph
granularity: each sample hit covers 40 byte(s) no time propagated
index % time self children called name
0.00 0.00 1/868 t1 (deadlock.c:21 @ 4011b2) [91
]
0.00 0.00 1/868 t1 (deadlock.c:22 @ 4011d8) [92
]
0.00 0.00 1/868 t1 (deadlock.c:28 @ 40122d) [96
]
0.00 0.00 1/868 _t2 [117]
0.00 0.00 1/868 t2 (deadlock.c:38 @ 4012f6) [11
3]
0.00 0.00 1/868 t2 (deadlock.c:39 @ 401304) [11
2]
0.00 0.00 1/868 t2 (deadlock.c:44 @ 401345) [10
9]
0.00 0.00 1/868 t2 (deadlock.c:49 @ 401395) [10
5]
0.00 0.00 1/868 _main [115]
0.00 0.00 1/868 main (deadlock.c:60 @ 401500) [
30]
0.00 0.00 1/868 main (deadlock.c:62 @ 401528) [
26]
0.00 0.00 1/868 main (deadlock.c:65 @ 401548) [
33]
0.00 0.00 1/868 main (deadlock.c:72 @ 401590) [
38]
0.00 0.00 1/868 main (deadlock.c:77 @ 4015c0) [
41]
0.00 0.00 854/868 <hicore> (2)
[1] 0.0 0.00 0.00 868 etext [1]
-----------------------------------------------
0.00 0.00 1/1 <hicore> (2)
[114] 0.0 0.00 0.00 1 __monstartup [114]
-----------------------------------------------
0.00 0.00 1/1 <hicore> (2)
[115] 0.0 0.00 0.00 1 _main [115]
0.00 0.00 1/868 etext [1]
-----------------------------------------------
0.00 0.00 1/1 <hicore> (2)
[116] 0.0 0.00 0.00 1 _t1 [116]
-----------------------------------------------
0.00 0.00 1/1 <hicore> (2)
[117] 0.0 0.00 0.00 1 _t2 [117]
0.00 0.00 1/868 etext [1]
-----------------------------------------------
♀
Index by function name
[114] __monstartup [116] _t1 [1] etext
[115] _main [117] _t2
profiling.diff
Description: profiling.diff
(C) 2002 Robert Collins How to profile cygwin1.dll. The hard way: Build libc.a and libm.a with -pg. Build all the cygwin1.dll source - except mcount.c - with -pg and no -O2. -O2 interferes with -pg in some inlined code. Link libgmon.a into cygwin1.dll. build cyggmon.dll and copy to /usr/bin. I used a CCNOPROF target in Makefile.in to make this relatively easy. The gmon code must be in a dll, so that multiple .dll's all built with profiling will all access the same instance of _gmonparam. The result if this is not done is that only the code in .a and .o items gets recorded to the gmon.out file. Voila.
gmon.din
Description: gmon.din
