* curious gprof behaviour on trivial testcase
@ 2006-04-29 16:56 James E Wilson
2006-04-29 18:49 ` Daniel Jacobowitz
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: James E Wilson @ 2006-04-29 16:56 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]
This came up on the mips linux kernel mailing list.
http://www.linux-mips.org/archives/linux-mips/2006-04/msg00231.html
Suppose I am building a toolchain for the first time, and want to verify
that gprof works. So you compile a trivial testcase with -pg, run it,
run gprof on it, and you get an error. This is very confusing for a
naive user.
The problem here is that a trivial testcase has only one function, and
hence no call graph info. However, gprof by default assumes you want to
emit call graph info, and if there is none, it gives an error.
I suspect this used to work OK, because in the past we used static
libraries by default, and usually had static profiled libraries
available to link with, so there was generally always a call graph.
Even if it only included start and main. However, nowadays, we use
shared libraries by default, and we don't link with profiled libraries
unless you add extra options because this only works right for static
libraries, so it is much more likely that there may be no call graph.
I think it would be better if we emit a flat profile if no call graph is
present. Of course, the flaw here is that people may now ask why they
got a result but no call graph. However, I think this is easier to deal
with. If you see a flat profile with only one function, then it is
clear what is wrong. If you see an error with gprof, it isn't clear
what is wrong, since the problem could be in gcc, glibc, or gprof or
even somewhere else entirely.
I tested this patch on x86_64-linux. There were no regressions. Not
very meaningful since there is no gprof testsuite, but I tested it by
hand on a trivial and non-trivial testcase. Without the patch I get an
error on a trivial testcase. With the patch, I get a flat profile for a
trivial testcase.
Not checked in yet in case someone wanted to comment.
--
Jim Wilson, GNU Tools Support, http://www.specifix.com
[-- Attachment #2: curious.result --]
[-- Type: text/plain, Size: 1538 bytes --]
aretha$ cat tmp.c
int main (void) { int i; for (i = 0; i < 10000000; i++); return 0; }
aretha$ gcc -pg tmp.c
aretha$ ./a.out
aretha$ ./gprof a.out
./gprof: gmon.out file is missing call-graph data
aretha$ ./gprof -p a.out
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
100.00 0.50 0.50 main
% 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.
aretha$
[-- Attachment #3: patch.default.style --]
[-- Type: text/plain, Size: 986 bytes --]
2006-04-28 James E Wilson <wilson@specifix.com>
* gprof.c (main): When setting default output_style,
Index: gprof.c
===================================================================
RCS file: /cvs/src/src/gprof/gprof.c,v
retrieving revision 1.25
diff -p -p -r1.25 gprof.c
*** gprof.c 30 Oct 2005 18:08:52 -0000 1.25
--- gprof.c 29 Apr 2006 01:13:36 -0000
*************** This program is free software. This pro
*** 545,551 ****
if (output_style == 0)
{
if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH))
! output_style = STYLE_FLAT_PROFILE | STYLE_CALL_GRAPH;
else
output_style = STYLE_EXEC_COUNTS;
--- 545,556 ----
if (output_style == 0)
{
if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH))
! {
! if (gmon_input & INPUT_HISTOGRAM)
! output_style |= STYLE_FLAT_PROFILE;
! if (gmon_input & INPUT_CALL_GRAPH)
! output_style |= STYLE_CALL_GRAPH;
! }
else
output_style = STYLE_EXEC_COUNTS;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: curious gprof behaviour on trivial testcase
2006-04-29 16:56 curious gprof behaviour on trivial testcase James E Wilson
@ 2006-04-29 18:49 ` Daniel Jacobowitz
2006-05-02 0:33 ` Ben Elliston
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2006-04-29 18:49 UTC (permalink / raw)
To: binutils
On Fri, Apr 28, 2006 at 07:08:04PM -0700, James E Wilson wrote:
> I tested this patch on x86_64-linux. There were no regressions. Not
> very meaningful since there is no gprof testsuite, but I tested it by
> hand on a trivial and non-trivial testcase. Without the patch I get an
> error on a trivial testcase. With the patch, I get a flat profile for a
> trivial testcase.
For what my opinion is worth, I think this is a great change. Every
time I try to use gprof on an application built without -pg I have to
go look up the argument to print the flat callgraph.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: curious gprof behaviour on trivial testcase
2006-04-29 16:56 curious gprof behaviour on trivial testcase James E Wilson
2006-04-29 18:49 ` Daniel Jacobowitz
@ 2006-05-02 0:33 ` Ben Elliston
2006-05-02 10:55 ` Nick Clifton
2006-05-02 18:03 ` James E Wilson
3 siblings, 0 replies; 5+ messages in thread
From: Ben Elliston @ 2006-05-02 0:33 UTC (permalink / raw)
To: James E Wilson; +Cc: binutils
Hi Jim
> The problem here is that a trivial testcase has only one function,
> and hence no call graph info. However, gprof by default assumes you
> want to emit call graph info, and if there is none, it gives an
> error.
Thanks for fixing this -- it caught me recently and I didn't get a
chance to go back and try to fix it myself.
More to the point, the error message you get from gprof is utterly
unhelpful. When I encountered it, I immediately suspected corruption
in the gmon.out file or operator error. It had me scratching my head
for a bit!
Cheers, Ben
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: curious gprof behaviour on trivial testcase
2006-04-29 16:56 curious gprof behaviour on trivial testcase James E Wilson
2006-04-29 18:49 ` Daniel Jacobowitz
2006-05-02 0:33 ` Ben Elliston
@ 2006-05-02 10:55 ` Nick Clifton
2006-05-02 18:03 ` James E Wilson
3 siblings, 0 replies; 5+ messages in thread
From: Nick Clifton @ 2006-05-02 10:55 UTC (permalink / raw)
To: James E Wilson; +Cc: binutils
Hi Jim,
> Not checked in yet in case someone wanted to comment.
Please do check this in, it is a very helpful change.
> 2006-04-28 James E Wilson <wilson@specifix.com>
>
> * gprof.c (main): When setting default output_style,
Approved.
Cheers
Nick
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: curious gprof behaviour on trivial testcase
2006-04-29 16:56 curious gprof behaviour on trivial testcase James E Wilson
` (2 preceding siblings ...)
2006-05-02 10:55 ` Nick Clifton
@ 2006-05-02 18:03 ` James E Wilson
3 siblings, 0 replies; 5+ messages in thread
From: James E Wilson @ 2006-05-02 18:03 UTC (permalink / raw)
To: binutils
I checked in this patch, and fixed the incomplete ChangeLog entry.
--
Jim Wilson, GNU Tools Support, http://www.specifix.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-02 18:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-29 16:56 curious gprof behaviour on trivial testcase James E Wilson
2006-04-29 18:49 ` Daniel Jacobowitz
2006-05-02 0:33 ` Ben Elliston
2006-05-02 10:55 ` Nick Clifton
2006-05-02 18:03 ` James E Wilson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).