2021年4月24日星期六

gprof producing no output for a program that takes reasonable time to execute

I know that similar questions have been asked before, but:

  1. In regards to gprof produces empty output I am using GCC 10.2.0 from MSYS2 on Windows 10, i.e. it's a MingW64 distribution. I have also added -no-pie to the linker arguments with no results still. The version of GNU Prof is 2.36.1
  2. In regards to gprof gives no output I am executing this on a program that explicitly takes time to execute.

The program is the code from this tutorial which is replicated below:

//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;  }  

I'm building with Code::Blocks. I've tried with both the 32bit and 64bit versions of MingW from MSYS2. I've upgraded everything to the latest versions of the packages available.

Output from the Code::Blocks build log:

g++.exe -pg -c C:\Users\david\Documents\GameDev\CPPTESTS\main.cpp -o obj\Debug\CPPTESTS\main.o  g++.exe -o CPPTESTS-d.exe obj\Debug\CPPTESTS\main.o -pg -lgmon -no-pie  

The program compiles and executes successfully. After execution, a gmon.out file is generated. Executing gprof to interpret this file:

 gprof CPPTests-d.exe gmon.out > gprofoutput.txt  

produces the following in gprofoutput.txt:

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.     self      the number of seconds accounted for by this  seconds    function alone.  This is the major sort for this             listing.    calls      the number of times this function was invoked, if             this function is profiled, else blank.     self      the average number of milliseconds spent in this  ms/call    function per call, if this function is profiled,         else blank.     total     the average number of milliseconds spent in this  ms/call    function and its descendents per call, if this         function is profiled, else blank.    name       the name of the function.  This is the minor sort             for this listing. The index shows the location of         the function in the gprof listing. If the index is         in parenthesis it shows where it would appear in         the gprof listing if it were to be printed.    Copyright (C) 2012-2021 Free Software Foundation, Inc.    Copying and distribution of this file, with or without modification,  are permitted in any medium without royalty provided the copyright  notice and this notice are preserved.                 Call graph (explanation follows)      granularity: each sample hit covers 4 byte(s) no time propagated    index % time    self  children    called     name     This table describes the call tree of the program, and was sorted by   the total amount of time spent in each function and its children.     Each entry in this table consists of several lines.  The line with the   index number at the left hand margin lists the current function.   The lines above it list the functions that called this function,   and the lines below it list the functions this one called.   This line lists:       index  A unique number given to each element of the table.          Index numbers are sorted numerically.          The index number is printed next to every function name so          it is easier to look up where the function is in the table.         % time This is the percentage of the `total' time that was spent          in this function and its children.  Note that due to          different viewpoints, functions excluded by options, etc,          these numbers will NOT add up to 100%.         self   This is the total amount of time spent in this function.         children   This is the total amount of time propagated into this          function by its children.         called This is the number of times the function was called.          If the function called itself recursively, the number          only includes non-recursive calls, and is followed by          a `+' and the number of recursive calls.         name   The name of the current function.  The index number is          printed after it.  If the function is a member of a          cycle, the cycle number is printed between the          function's name and the index number.       For the function's parents, the fields have the following meanings:         self   This is the amount of time that was propagated directly          from the function into this parent.         children   This is the amount of time that was propagated from          the function's children into this parent.         called This is the number of times this parent called the          function `/' the total number of times the function          was called.  Recursive calls to the function are not          included in the number after the `/'.         name   This is the name of the parent.  The parent's index          number is printed after it.  If the parent is a          member of a cycle, the cycle number is printed between          the name and the index number.     If the parents of the function cannot be determined, the word   `<spontaneous>' is printed in the `name' field, and all the other   fields are blank.     For the function's children, the fields have the following meanings:         self   This is the amount of time that was propagated directly          from the child into the function.         children   This is the amount of time that was propagated from the          child's children to the function.         called This is the number of times the function called          this child `/' the total number of times the child          was called.  Recursive calls by the child are not          listed in the number after the `/'.         name   This is the name of the child.  The child's index          number is printed after it.  If the child is a          member of a cycle, the cycle number is printed          between the name and the index number.     If there are any cycles (circles) in the call graph, there is an   entry for the cycle-as-a-whole.  This entry shows who called the   cycle (as parents) and the members of the cycle (as children.)   The `+' recursive calls entry shows the number of function calls that   were internal to the cycle, and the calls entry for each member shows,   for that member, how many times it was called from other members of   the cycle.    Copyright (C) 2012-2021 Free Software Foundation, Inc.    Copying and distribution of this file, with or without modification,  are permitted in any medium without royalty provided the copyright  notice and this notice are preserved.    Index by function name  

which you can see it's completely empty. Further, if I open gmon.out in a hex editor, it's mostly blank inside, here's the first bit:

F0 14 C5 00 18 8A C5 00 B4 3A 00 00 79 18 05 00 64 00 00 00 96 1A C5 00 A7 16 C5 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 FE 00 5D 00 E2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 C6 01 A5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 00 E5 00 77 00 F5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  

and then the end is the following:

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E4 15 C5 00 6C 89 C5 00 01 00 00 00 14 16 C5 00 6C 89 C5 00 01 00 00 00 2C 16 C5 00 DB 15 C5 00 01 00 00 00 48 16 C5 00 6C 89 C5 00 01 00 00 00 84 16 C5 00 6C 89 C5 00 01 00 00 00 A0 16 C5 00 0A 16 C5 00 01 00 00 00 A4 16 C5 00 3C 16 C5 00 01 00 00 00  

The rest is a few kilobytes of 00.

I have tried everything I can find in google about getting this to work. Originally I was having trouble executing it on actual code for a project, but have resorted to using the code above as there seems to be something I'm doing wrong which I just can't figure out.

Any help would be appreciated.

EDIT

I managed to produce results in gmon.out that were parsed correctly with gprof and gave me timing for all the functions in my test program. Making no changes, not even closing the MSYS2 terminal, I then recompiled the program with the same command, executed it again, and back to having an empty results.

It's unclear to me if it's something during compilation (hard to believe, it was compiled using the last command in the terminal history), or something on my machine when I execute it. Or if it's a problem with gprof translating the gmon.out file.

EDIT 2

I've executed the program on a different machine (it's a similar Windows 10 Surface Pro) that has never been used for development. It's produced gmon.out also seems to have no results when parsed through gprof.

https://stackoverflow.com/questions/67240792/gprof-producing-no-output-for-a-program-that-takes-reasonable-time-to-execute April 24, 2021 at 04:32PM

没有评论:

发表评论