From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Eric S. Raymond" Newsgroups: gmane.emacs.bugs Subject: Patch -- fixes some deficiencies in the gprof manual Date: Thu, 11 Sep 2003 18:22:01 -0400 Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: <200309112222.h8BMM1QY011530@snark.thyrsus.com> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1063319306 8018 80.91.224.253 (11 Sep 2003 22:28:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 11 Sep 2003 22:28:26 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 12 00:28:23 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19xZvL-0002Vj-00 for ; Fri, 12 Sep 2003 00:28:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19xZqI-0004he-6K for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Sep 2003 18:23:10 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19xZqG-0004fI-13 for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2003 18:23:08 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19xZqD-0004dT-BQ for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2003 18:23:06 -0400 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.22) id 19xZqD-0004ck-4B for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2003 18:23:05 -0400 Original-Received: from [66.92.53.140] (helo=grelber.thyrsus.com) by mx20.gnu.org with esmtp (Exim 4.22) id 19xZpE-0006rt-IM for bug-gnu-emacs@gnu.org; Thu, 11 Sep 2003 18:22:04 -0400 Original-Received: from snark.thyrsus.com (quintaped.thyrsus.com [192.168.1.1]) by grelber.thyrsus.com (8.12.8/8.12.8) with ESMTP id h8BMM1hN022698 for ; Thu, 11 Sep 2003 18:22:01 -0400 Original-Received: from snark.thyrsus.com (localhost [127.0.0.1]) by snark.thyrsus.com (8.12.8/8.12.8) with ESMTP id h8BMM1sa011534 for ; Thu, 11 Sep 2003 18:22:01 -0400 Original-Received: (from esr@localhost) by snark.thyrsus.com (8.12.8/8.12.8/Submit) id h8BMM1QY011530; Thu, 11 Sep 2003 18:22:01 -0400 Original-To: bug-gnu-emacs@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:5780 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:5780 Answers the biggest FAQ. Corrects some typos. Adds a useful tip. --- gprof.texi.orig 2003-09-11 17:42:44.000000000 -0400 +++ gprof.texi 2003-09-11 18:10:15.000000000 -0400 @@ -90,6 +90,7 @@ execute programs. @sc{gnu} @code{gprof} was written by Jay Fenlason. This manual was updated August 1997 by Brent Baccala. +Eric S. Raymond made some minor corrections and additions in 2003. @menu * Introduction:: What profiling means, and why it is useful. @@ -190,6 +191,14 @@ cc -o myprog myprog.c utils.c -g -pg @end example +Note: The @samp{-pg} option must be part of your compilation options +as well as your link options. If it is not, when you run @code{gprof} +you will get no profile report and an error message like this: + +@example +gprof: gmon.out file is missing call-graph data +@end example + If you run the linker @code{ld} directly instead of through a compiler such as @code{cc}, you may have to specify a profiling startup file @file{gcrt0.o} as the first input file instead of the usual startup @@ -219,10 +228,13 @@ that match program addresses to source code lines. @xref{Line-by-line}. -In addition to the @samp{-pg} and @samp{-g} options, -you may also wish to specify the @samp{-a} option when compiling. -This will instrument -the program to perform basic-block counting. As the program runs, +In addition to the @samp{-pg} and @samp{-g} options, older versions of +GCC required you to specify the @samp{-a} option when compiling in +order to instrument it to perform basic-block counting. Newer +versions do not require this option and will not accept it; +basic-block counting is always enabled when @samp{-pg} is on. + +When basic-block counting is enabled, as the program runs it will count how many times it executed each branch of each @samp{if} statement, each iteration of each @samp{do} loop, etc. This will enable @code{gprof} to construct an annotated source code @@ -303,7 +315,7 @@ * Output Options:: Controlling @code{gprof}'s output style * Analysis Options:: Controlling how @code{gprof} analyses its data * Miscellaneous Options:: -* Depricated Options:: Options you no longer need to use, but which +* Deprecated Options:: Options you no longer need to use, but which have been retained for compatibility * Symspecs:: Specifying functions to include or exclude @end menu @@ -565,7 +577,7 @@ @end table -@node Miscellaneous Options,Depricated Options,Analysis Options,Invoking +@node Miscellaneous Options,Deprecated Options,Analysis Options,Invoking @section Miscellaneous Options @table @code @@ -601,8 +613,8 @@ @end table -@node Depricated Options,Symspecs,Miscellaneous Options,Invoking -@section Depricated Options +@node Deprecated Options,Symspecs,Miscellaneous Options,Invoking +@section Deprecated Options @table @code @@ -653,7 +665,7 @@ lists in the call graph all functions that were reached from either @code{foo} or @code{bar} and were not reachable from @code{boring}. -@node Symspecs,,Depricated Options,Invoking +@node Symspecs,,Deprecated Options,Invoking @section Symspecs Many of the output options allow functions to be included or excluded @@ -1507,6 +1519,14 @@ @chapter Answers to Common Questions @table @asis +@item How can I get more exact information about hot spots in my program? + +Looking at the per-line call counts only tells part of the story. +Because @code{gprof} can only report call times and counts by function, +the best way to get finer-grained information on where the program +is spending its time is to refactor large functions into sequences +of calls to smaller ones. + @item How do I find which lines in my program were executed the most times? Compile your program with basic-block counting enabled, run it, then -- Eric S. Raymond "Taking my gun away because I might shoot someone is like cutting my tongue out because I might yell `Fire!' in a crowded theater." -- Peter Venetoklis