winlibs_mingw icon indicating copy to clipboard operation
winlibs_mingw copied to clipboard

Is the `gprof.exe` related content working well?

Open thefatwhale opened this issue 3 years ago • 10 comments

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.

  1. I use gcc-8.1.0 to compile with -pg arg.
  2. run output executeable file
  3. switch to gcc-11.3.0 use gprof command.
  4. he works well

So I guess it is gcc problem.

output file here.

gcc-8.1.0-from-sourceforge.txt gcc-11.3.0-or-12.1.0.txt

thefatwhale avatar Aug 16 '22 07:08 thefatwhale

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?

brechtsanders avatar Aug 18 '22 11:08 brechtsanders

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.

thefatwhale avatar Aug 18 '22 12:08 thefatwhale

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:

thefatwhale avatar Aug 18 '22 12:08 thefatwhale

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?

brechtsanders avatar Aug 18 '22 13:08 brechtsanders

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.

link: sourceforge-gcc-8.1.0-posix-seh

thefatwhale avatar Aug 18 '22 14:08 thefatwhale

By the way, I see that the releases of this repository are posix. Is there a big difference between this and win32?

thefatwhale avatar Aug 18 '22 15:08 thefatwhale

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.

brechtsanders avatar Aug 18 '22 16:08 brechtsanders

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.

thefatwhale avatar Aug 19 '22 06:08 thefatwhale

This build of mingw64 offers win32 threads: https://github.com/niXman/mingw-builds-binaries/releases

jpgpng avatar Sep 06 '22 06:09 jpgpng

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.

brechtsanders avatar Sep 06 '22 07:09 brechtsanders