Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the gprof.exe related content working well? #111

Open
thefatwhale opened this issue Aug 16, 2022 · 10 comments
Open

Is the gprof.exe related content working well? #111

thefatwhale opened this issue Aug 16, 2022 · 10 comments

Comments

@thefatwhale
Copy link

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

@brechtsanders
Copy link
Owner

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?

@thefatwhale
Copy link
Author

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
Copy link
Author

I actually tried the latest version before, but I forgot to write it in the markdown above, it's only in the file name. 😄

@brechtsanders
Copy link
Owner

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?

@thefatwhale
Copy link
Author

thefatwhale commented Aug 18, 2022

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
Copy link
Author

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

@brechtsanders
Copy link
Owner

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.

@thefatwhale
Copy link
Author

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.

@jpgpng
Copy link

jpgpng commented Sep 6, 2022

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

@brechtsanders
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants