From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5144 invoked by alias); 29 Apr 2006 02:08:12 -0000 Received: (qmail 5130 invoked by uid 22791); 29 Apr 2006 02:08:09 -0000 X-Spam-Check-By: sourceware.org Received: from w099.z064220152.sjc-ca.dsl.cnc.net (HELO duck.specifix.com) (64.220.152.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 29 Apr 2006 02:08:06 +0000 Received: from [127.0.0.1] (duck.corp.specifix.com [192.168.1.1]) by duck.specifix.com (Postfix) with ESMTP id 62928FCDB for ; Fri, 28 Apr 2006 19:08:04 -0700 (PDT) Subject: curious gprof behaviour on trivial testcase From: James E Wilson To: binutils@sourceware.org Content-Type: multipart/mixed; boundary="=-gVxrGIe+IPfv1W6T+VLT" Message-Id: <1146276484.15759.326.camel@aretha.corp.specifix.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Sat, 29 Apr 2006 16:56:00 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00426.txt.bz2 --=-gVxrGIe+IPfv1W6T+VLT Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1906 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 --=-gVxrGIe+IPfv1W6T+VLT Content-Disposition: attachment; filename=curious.result Content-Type: text/plain; name=curious.result; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 1538 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$ --=-gVxrGIe+IPfv1W6T+VLT Content-Disposition: attachment; filename=patch.default.style Content-Type: text/plain; name=patch.default.style; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 986 2006-04-28 James E Wilson * 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; --=-gVxrGIe+IPfv1W6T+VLT--