| <html lang="en"> |
| <head> |
| <title>How do I? - GNU gprof</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="GNU gprof"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="prev" href="Inaccuracy.html#Inaccuracy" title="Inaccuracy"> |
| <link rel="next" href="Incompatibilities.html#Incompatibilities" title="Incompatibilities"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| This file documents the gprof profiler of the GNU system. |
| |
| Copyright (C) 1988, 1992, 1997, 1998, 1999, 2000, 2001, 2003, |
| 2007, 2008, 2009 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 |
| or any later version published by the Free Software Foundation; |
| with no Invariant Sections, with no Front-Cover Texts, and with no |
| Back-Cover Texts. A copy of the license is included in the |
| section entitled ``GNU Free Documentation License''. |
| |
| --> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="How-do-I%3f"></a> |
| <a name="How-do-I_003f"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Incompatibilities.html#Incompatibilities">Incompatibilities</a>, |
| Previous: <a rel="previous" accesskey="p" href="Inaccuracy.html#Inaccuracy">Inaccuracy</a>, |
| Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> |
| <hr> |
| </div> |
| |
| <h2 class="chapter">7 Answers to Common Questions</h2> |
| |
| <dl> |
| <dt>How can I get more exact information about hot spots in my program?<dd> |
| Looking at the per-line call counts only tells part of the story. |
| Because <code>gprof</code> 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 re-factor large functions into sequences |
| of calls to smaller ones. Beware however that this can introduce |
| artificial hot spots since compiling with ‘<samp><span class="samp">-pg</span></samp>’ adds a significant |
| overhead to function calls. An alternative solution is to use a |
| non-intrusive profiler, e.g. oprofile. |
| |
| <br><dt>How do I find which lines in my program were executed the most times?<dd> |
| Use the <code>gcov</code> program. |
| |
| <br><dt>How do I find which lines in my program called a particular function?<dd> |
| Use ‘<samp><span class="samp">gprof -l</span></samp>’ and lookup the function in the call graph. |
| The callers will be broken down by function and line number. |
| |
| <br><dt>How do I analyze a program that runs for less than a second?<dd> |
| Try using a shell script like this one: |
| |
| <pre class="example"> for i in `seq 1 100`; do |
| fastprog |
| mv gmon.out gmon.out.$i |
| done |
| |
| gprof -s fastprog gmon.out.* |
| |
| gprof fastprog gmon.sum |
| </pre> |
| <p>If your program is completely deterministic, all the call counts |
| will be simple multiples of 100 (i.e., a function called once in |
| each run will appear with a call count of 100). |
| |
| </dl> |
| |
| </body></html> |
| |