I have an outstanding question on StackOverflow here, and I also have a ticket open on MSYS2 about the same topic (but I believe it should be here instead). I'm linking to these so that people in the future can see that these are connected.
Compiling with Mingw64 10.2 (from MSYS2) with -pg
does not appear to correctly instrument the code. When executed, a gmon.out file is produced, but gprof reports that all functions had 0 time, and marks the functions as unused. This is with code specifically designed to take time to execute and produce gprof results.
Compiling with Mingw64-Builds 8.1.0 with -pg
works correctly. A gmon.out file produced by a program from 8.1.0 is able to be parsed by gprof from MSYS2 correctly.
//test_gprof.c #include<stdio.h> void new_func1(void) { printf("\n Inside new_func1()\n"); int i = 0; for(;i<0xffffffee;i++); return; } void func1(void) { printf("\n Inside func1 \n"); int i = 0; for(;i<0xffffffff;i++); new_func1(); return; } static void func2(void) { printf("\n Inside func2 \n"); int i = 0; for(;i<0xffffffaa;i++); return; } int main(void) { printf("\n Inside main()\n"); int i = 0; for(;i<0xffffff;i++); func1(); func2(); return 0; }
Compiled with
g++ -g -pg main.cpp -o CPPTESTS-d.exe
Then gprof on the gmon.out file
gprof CPPTests-d.exe gmon.out > gprofoutput.txt
results in empty results.
I have used both GCC and G++, both 32 and 64 bit versions, none work. I've tried compiling and linking in different stages, doesn't work. I've tried compiling with -no-pie
as well, doesn't work. I have received feedback in the Mingw64 mailing list that someone else experienced the same issue.
I've tested with a fresh install of Windows 7 on a Virtual Box with the same wrongly instrumented code. For what it's worth, I'm using a Windows 10 machine.