Is the `gprof.exe` related content working well?
I use my gcc-8.1.0 on sourceforge works well.
gcc -pg -g -o .\a.exe .\a.c
.\a
gprof .\a.exe .\gmon.out > output.txt
(.\gmon.out file generated by running the program a.exe because of the option -pg)
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 1 0.00 0.00 fbnq
...
But the software I downloaded from the releases of this repository can't output this text file normally like this
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
It's output only a table header. no content.
After my test. it may not gprof.exe mistake.
- I use gcc-8.1.0 to compile with -pg arg.
- run output executeable file
- switch to gcc-11.3.0 use gprof command.
- he works well
So I guess it is gcc problem.
output file here.
gprof is part of binutils, of which version 2.39 was recently released.
You can check if you're still using an older version with: gprof --version
Also GCC 11.3.0 is not the most recent.
Can you try with the latest winlibs release from https://github.com/brechtsanders/winlibs_mingw/releases/tag/12.1.0-14.0.6-10.0.0-msvcrt-r3 ?
Do you have example a.c code I can try to reproduce with?
In the latest winlibs release still have this problem.
a.c is the Minimized Test Samples
fbnq is Fibonacci series in English.
#include <stdio.h>
int fbnq(int);
int fbnq(int n)
{
if (n <= 2)
{
return 1;
}
return fbnq(n - 1) + fbnq(n - 2);
}
int main(void)
{
printf("fbnq(8) is %d\n", fbnq(8));
return 0;
}
gcc --version
gcc (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gprof --version
GNU gprof (Binutils for MinGW-W64 x86_64, built by Brecht Sanders) 2.39
Based on BSD gprof, copyright 1983 Regents of the University of California.
This program is free software. This program has absolutely no warranty.
I actually tried the latest version before, but I forgot to write it in the markdown above, it's only in the file name. :smile:
I actually get the same output as you with the latest release:
gcc -pg -g -O0 -c -o a.o a.c && gcc -pg -g a.o -o a.exe && ./a.exe && gprof a.exe gmon.out
My output starts with:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
% the percentage of the total running time of the
time program used by this function.
cumulative a running sum of the number of seconds accounted
seconds for by this function and those listed above it.
So it looks like I can reproduce it, but I'm no expert in gprof on Windows.
The question is: is this an issue in GCC generating the gmon.out file or in gprof reading it?
I guess is gcc's issue. You can read my first message on this issue, which is written in an ordered list. Or you can download one and try it out. I use gcc-8.1.0 to compile and gprof-2.39 to reading it. It works well.
By the way, I see that the releases of this repository are posix. Is there a big difference between this and win32?
The win32 builds use the Windows threads API as much as possible but don't provide POSIX threads compatibility (pthreads.h).
In the winlibs project it was decided there is no benefit in this as it makes it usable for portability.
I do see a lot of forums saying gprof just won't get timed results if the application finishes faster than 0.01 seconds.
Thanks for your answer, I got it.
But it seems that I use some functions that take up a lot of time, and still have the same problem. I am on gcc-8.1.0, even 0.01s can output normally.
This build of mingw64 offers win32 threads: https://github.com/niXman/mingw-builds-binaries/releases
I don't see how this relates to Win32 threads.
For the winlibs build it was decided to only make POSIX thread releases as these also provide Win32 threads support and it makes it possible to port a lot more libraries originally written for POSIX threads.