I'm using the MinGW GCC compiler on Windows. If I add -pg switch to the compiler I can generate both the EXE and the DLL with profile data.
The gmon.out is generated. But the problem is that when I use
gprof myprogram.exe gmon.out
I get no profile output (other than the table headings and other text).
gprof mydll.dll gmon.out
I get the output for that particular DLL only but not for the main exe.
Maybe both the exe and the dll wanted to generate the same file and the dll won.
The goal is getting stats for functions in both the EXE and DLL in one output.
Can gprof do that? If not, is there any tool that can do this on Windows?
It seems gprof cannot do that. sprof is not available in MinGw. So rolled my own profiler.
I used
-finstrument-functions
So two functions__cyg_profile_func_enter
and__cyg_profile_func_exit
will be called before and after each functions respectively.The actual profiling functions are exported into a DLL and called in these functions, and the DLL is linked to all EXE and DLL in question. So it can profile both of them
The code in the library is like this (removed clutter: asserts, error checking, simplified function calls for clarity).
And it produces logs like this:
The function names can be found out from the MAP file. And the function at 0x691C83B9 in the DLL is indeed a suboptimal function with O(n³) complexity and is called lot of times, I must refactor that... I totally forgot that function even exist... The 0x004390F9 is the WinMain.