gprof.html 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the gprof profiler of the GNU system.
  4. Copyright (C) 1988-2024 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>GNU gprof</title>
  16. <meta name="description" content="GNU gprof">
  17. <meta name="keywords" content="GNU gprof">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="#Top" rel="start" title="Top">
  22. <link href="#SEC_Contents" rel="contents" title="Table of Contents">
  23. <style type="text/css">
  24. <!--
  25. a.summary-letter {text-decoration: none}
  26. blockquote.indentedblock {margin-right: 0em}
  27. div.display {margin-left: 3.2em}
  28. div.example {margin-left: 3.2em}
  29. div.lisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. span.nolinebreak {white-space: nowrap}
  36. span.roman {font-family: initial; font-weight: normal}
  37. span.sansserif {font-family: sans-serif; font-weight: normal}
  38. ul.no-bullet {list-style: none}
  39. -->
  40. </style>
  41. </head>
  42. <body lang="en">
  43. <h1 class="settitle" align="center">GNU gprof</h1>
  44. <span id="SEC_Contents"></span>
  45. <h2 class="contents-heading">Table of Contents</h2>
  46. <div class="contents">
  47. <ul class="no-bullet">
  48. <li><a id="toc-Introduction-to-Profiling" href="#Introduction">1 Introduction to Profiling</a></li>
  49. <li><a id="toc-Compiling-a-Program-for-Profiling" href="#Compiling">2 Compiling a Program for Profiling</a></li>
  50. <li><a id="toc-Executing-the-Program" href="#Executing">3 Executing the Program</a></li>
  51. <li><a id="toc-gprof-Command-Summary" href="#Invoking">4 <code>gprof</code> Command Summary</a>
  52. <ul class="no-bullet">
  53. <li><a id="toc-Output-Options-1" href="#Output-Options">4.1 Output Options</a></li>
  54. <li><a id="toc-Analysis-Options-1" href="#Analysis-Options">4.2 Analysis Options</a></li>
  55. <li><a id="toc-Miscellaneous-Options-1" href="#Miscellaneous-Options">4.3 Miscellaneous Options</a></li>
  56. <li><a id="toc-Deprecated-Options-1" href="#Deprecated-Options">4.4 Deprecated Options</a></li>
  57. <li><a id="toc-Symspecs-1" href="#Symspecs">4.5 Symspecs</a></li>
  58. </ul></li>
  59. <li><a id="toc-Interpreting-gprof_0027s-Output" href="#Output">5 Interpreting <code>gprof</code>&rsquo;s Output</a>
  60. <ul class="no-bullet">
  61. <li><a id="toc-The-Flat-Profile" href="#Flat-Profile">5.1 The Flat Profile</a></li>
  62. <li><a id="toc-The-Call-Graph" href="#Call-Graph">5.2 The Call Graph</a>
  63. <ul class="no-bullet">
  64. <li><a id="toc-The-Primary-Line" href="#Primary">5.2.1 The Primary Line</a></li>
  65. <li><a id="toc-Lines-for-a-Function_0027s-Callers" href="#Callers">5.2.2 Lines for a Function&rsquo;s Callers</a></li>
  66. <li><a id="toc-Lines-for-a-Function_0027s-Subroutines" href="#Subroutines">5.2.3 Lines for a Function&rsquo;s Subroutines</a></li>
  67. <li><a id="toc-How-Mutually-Recursive-Functions-Are-Described" href="#Cycles">5.2.4 How Mutually Recursive Functions Are Described</a></li>
  68. </ul></li>
  69. <li><a id="toc-Line_002dby_002dline-Profiling" href="#Line_002dby_002dline">5.3 Line-by-line Profiling</a></li>
  70. <li><a id="toc-The-Annotated-Source-Listing" href="#Annotated-Source">5.4 The Annotated Source Listing</a></li>
  71. </ul></li>
  72. <li><a id="toc-Inaccuracy-of-gprof-Output" href="#Inaccuracy">6 Inaccuracy of <code>gprof</code> Output</a>
  73. <ul class="no-bullet">
  74. <li><a id="toc-Statistical-Sampling-Error" href="#Sampling-Error">6.1 Statistical Sampling Error</a></li>
  75. <li><a id="toc-Estimating-children-Times" href="#Assumptions">6.2 Estimating <code>children</code> Times</a></li>
  76. </ul></li>
  77. <li><a id="toc-Answers-to-Common-Questions" href="#How-do-I_003f">7 Answers to Common Questions</a></li>
  78. <li><a id="toc-Incompatibilities-with-Unix-gprof" href="#Incompatibilities">8 Incompatibilities with Unix <code>gprof</code></a></li>
  79. <li><a id="toc-Details-of-Profiling" href="#Details">9 Details of Profiling</a>
  80. <ul class="no-bullet">
  81. <li><a id="toc-Implementation-of-Profiling" href="#Implementation">9.1 Implementation of Profiling</a></li>
  82. <li><a id="toc-Profiling-Data-File-Format" href="#File-Format">9.2 Profiling Data File Format</a>
  83. <ul class="no-bullet">
  84. <li><a id="toc-Histogram-Records" href="#Histogram-Records">9.2.1 Histogram Records</a></li>
  85. <li><a id="toc-Call_002dGraph-Records" href="#Call_002dGraph-Records">9.2.2 Call-Graph Records</a></li>
  86. <li><a id="toc-Basic_002dBlock-Execution-Count-Records" href="#Basic_002dBlock-Execution-Count-Records">9.2.3 Basic-Block Execution Count Records</a></li>
  87. </ul></li>
  88. <li><a id="toc-gprof_0027s-Internal-Operation" href="#Internals">9.3 <code>gprof</code>&rsquo;s Internal Operation</a></li>
  89. <li><a id="toc-Debugging-gprof" href="#Debugging">9.4 Debugging <code>gprof</code></a></li>
  90. </ul></li>
  91. <li><a id="toc-GNU-Free-Documentation-License-1" href="#GNU-Free-Documentation-License">Appendix A GNU Free Documentation License</a></li>
  92. </ul>
  93. </div>
  94. <span id="Top"></span><div class="header">
  95. <p>
  96. Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  97. </div>
  98. <span id="Profiling-a-Program_003a-Where-Does-It-Spend-Its-Time_003f"></span><h1 class="top">Profiling a Program: Where Does It Spend Its Time?</h1>
  99. <p>This manual describes the <small>GNU</small> profiler, <code>gprof</code>, and how you
  100. can use it to determine which parts of a program are taking most of the
  101. execution time. We assume that you know how to write, compile, and
  102. execute programs. <small>GNU</small> <code>gprof</code> was written by Jay Fenlason.
  103. </p>
  104. <p>This manual is for <code>gprof</code>
  105. (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24))
  106. version 2.42.0.
  107. </p>
  108. <p>This document is distributed under the terms of the GNU Free
  109. Documentation License version 1.3. A copy of the license is included
  110. in the section entitled &ldquo;GNU Free Documentation License&rdquo;.
  111. </p>
  112. <table class="menu" border="0" cellspacing="0">
  113. <tr><td align="left" valign="top">&bull; <a href="#Introduction" accesskey="1">Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">What profiling means, and why it is useful.
  114. </td></tr>
  115. <tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
  116. </pre></th></tr><tr><td align="left" valign="top">&bull; <a href="#Compiling" accesskey="2">Compiling</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How to compile your program for profiling.
  117. </td></tr>
  118. <tr><td align="left" valign="top">&bull; <a href="#Executing" accesskey="3">Executing</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Executing your program to generate profile data
  119. </td></tr>
  120. <tr><td align="left" valign="top">&bull; <a href="#Invoking" accesskey="4">Invoking</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How to run <code>gprof</code>, and its options
  121. </td></tr>
  122. <tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
  123. </pre></th></tr><tr><td align="left" valign="top">&bull; <a href="#Output" accesskey="5">Output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Interpreting <code>gprof</code>&rsquo;s output
  124. </td></tr>
  125. <tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
  126. </pre></th></tr><tr><td align="left" valign="top">&bull; <a href="#Inaccuracy" accesskey="6">Inaccuracy</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Potential problems you should be aware of
  127. </td></tr>
  128. <tr><td align="left" valign="top">&bull; <a href="#How-do-I_003f" accesskey="7">How do I?</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Answers to common questions
  129. </td></tr>
  130. <tr><td align="left" valign="top">&bull; <a href="#Incompatibilities" accesskey="8">Incompatibilities</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">(between <small>GNU</small> <code>gprof</code> and Unix <code>gprof</code>.)
  131. </td></tr>
  132. <tr><td align="left" valign="top">&bull; <a href="#Details" accesskey="9">Details</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Details of how profiling is done
  133. </td></tr>
  134. <tr><td align="left" valign="top">&bull; <a href="#GNU-Free-Documentation-License">GNU Free Documentation License</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">GNU Free Documentation License
  135. </td></tr>
  136. </table>
  137. <hr>
  138. <span id="Introduction"></span><div class="header">
  139. <p>
  140. Next: <a href="#Compiling" accesskey="n" rel="next">Compiling</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  141. </div>
  142. <span id="Introduction-to-Profiling"></span><h2 class="chapter">1 Introduction to Profiling</h2>
  143. <p>Profiling allows you to learn where your program spent its time and which
  144. functions called which other functions while it was executing. This
  145. information can show you which pieces of your program are slower than you
  146. expected, and might be candidates for rewriting to make your program
  147. execute faster. It can also tell you which functions are being called more
  148. or less often than you expected. This may help you spot bugs that had
  149. otherwise been unnoticed.
  150. </p>
  151. <p>Since the profiler uses information collected during the actual execution
  152. of your program, it can be used on programs that are too large or too
  153. complex to analyze by reading the source. However, how your program is run
  154. will affect the information that shows up in the profile data. If you
  155. don&rsquo;t use some feature of your program while it is being profiled, no
  156. profile information will be generated for that feature.
  157. </p>
  158. <p>Profiling has several steps:
  159. </p>
  160. <ul>
  161. <li> You must compile and link your program with profiling enabled.
  162. See <a href="#Compiling">Compiling a Program for Profiling</a>.
  163. </li><li> You must execute your program to generate a profile data file.
  164. See <a href="#Executing">Executing the Program</a>.
  165. </li><li> You must run <code>gprof</code> to analyze the profile data.
  166. See <a href="#Invoking"><code>gprof</code> Command Summary</a>.
  167. </li></ul>
  168. <p>The next three chapters explain these steps in greater detail.
  169. </p>
  170. <p>Several forms of output are available from the analysis.
  171. </p>
  172. <p>The <em>flat profile</em> shows how much time your program spent in each function,
  173. and how many times that function was called. If you simply want to know
  174. which functions burn most of the cycles, it is stated concisely here.
  175. See <a href="#Flat-Profile">The Flat Profile</a>.
  176. </p>
  177. <p>The <em>call graph</em> shows, for each function, which functions called it, which
  178. other functions it called, and how many times. There is also an estimate
  179. of how much time was spent in the subroutines of each function. This can
  180. suggest places where you might try to eliminate function calls that use a
  181. lot of time. See <a href="#Call-Graph">The Call Graph</a>.
  182. </p>
  183. <p>The <em>annotated source</em> listing is a copy of the program&rsquo;s
  184. source code, labeled with the number of times each line of the
  185. program was executed. See <a href="#Annotated-Source">The Annotated Source
  186. Listing</a>.
  187. </p>
  188. <p>To better understand how profiling works, you may wish to read
  189. a description of its implementation.
  190. See <a href="#Implementation">Implementation of Profiling</a>.
  191. </p>
  192. <hr>
  193. <span id="Compiling"></span><div class="header">
  194. <p>
  195. Next: <a href="#Executing" accesskey="n" rel="next">Executing</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  196. </div>
  197. <span id="Compiling-a-Program-for-Profiling"></span><h2 class="chapter">2 Compiling a Program for Profiling</h2>
  198. <p>The first step in generating profile information for your program is
  199. to compile and link it with profiling enabled.
  200. </p>
  201. <p>To compile a source file for profiling, specify the &lsquo;<samp>-pg</samp>&rsquo; option when
  202. you run the compiler. (This is in addition to the options you normally
  203. use.)
  204. </p>
  205. <p>To link the program for profiling, if you use a compiler such as <code>cc</code>
  206. to do the linking, simply specify &lsquo;<samp>-pg</samp>&rsquo; in addition to your usual
  207. options. The same option, &lsquo;<samp>-pg</samp>&rsquo;, alters either compilation or linking
  208. to do what is necessary for profiling. Here are examples:
  209. </p>
  210. <div class="example">
  211. <pre class="example">cc -g -c myprog.c utils.c -pg
  212. cc -o myprog myprog.o utils.o -pg
  213. </pre></div>
  214. <p>The &lsquo;<samp>-pg</samp>&rsquo; option also works with a command that both compiles and links:
  215. </p>
  216. <div class="example">
  217. <pre class="example">cc -o myprog myprog.c utils.c -g -pg
  218. </pre></div>
  219. <p>Note: The &lsquo;<samp>-pg</samp>&rsquo; option must be part of your compilation options
  220. as well as your link options. If it is not then no call-graph data
  221. will be gathered and when you run <code>gprof</code> you will get an error
  222. message like this:
  223. </p>
  224. <div class="example">
  225. <pre class="example">gprof: gmon.out file is missing call-graph data
  226. </pre></div>
  227. <p>If you add the &lsquo;<samp>-Q</samp>&rsquo; switch to suppress the printing of the call
  228. graph data you will still be able to see the time samples:
  229. </p>
  230. <div class="example">
  231. <pre class="example">Flat profile:
  232. Each sample counts as 0.01 seconds.
  233. % cumulative self self total
  234. time seconds seconds calls Ts/call Ts/call name
  235. 44.12 0.07 0.07 zazLoop
  236. 35.29 0.14 0.06 main
  237. 20.59 0.17 0.04 bazMillion
  238. </pre></div>
  239. <p>If you run the linker <code>ld</code> directly instead of through a compiler
  240. such as <code>cc</code>, you may have to specify a profiling startup file
  241. <samp>gcrt0.o</samp> as the first input file instead of the usual startup
  242. file <samp>crt0.o</samp>. In addition, you would probably want to
  243. specify the profiling C library, <samp>libc_p.a</samp>, by writing
  244. &lsquo;<samp>-lc_p</samp>&rsquo; instead of the usual &lsquo;<samp>-lc</samp>&rsquo;. This is not absolutely
  245. necessary, but doing this gives you number-of-calls information for
  246. standard library functions such as <code>read</code> and <code>open</code>. For
  247. example:
  248. </p>
  249. <div class="example">
  250. <pre class="example">ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p
  251. </pre></div>
  252. <p>If you are running the program on a system which supports shared
  253. libraries you may run into problems with the profiling support code in
  254. a shared library being called before that library has been fully
  255. initialised. This is usually detected by the program encountering a
  256. segmentation fault as soon as it is run. The solution is to link
  257. against a static version of the library containing the profiling
  258. support code, which for <code>gcc</code> users can be done via the
  259. &lsquo;<samp>-static</samp>&rsquo; or &lsquo;<samp>-static-libgcc</samp>&rsquo; command-line option. For
  260. example:
  261. </p>
  262. <div class="example">
  263. <pre class="example">gcc -g -pg -static-libgcc myprog.c utils.c -o myprog
  264. </pre></div>
  265. <p>If you compile only some of the modules of the program with &lsquo;<samp>-pg</samp>&rsquo;, you
  266. can still profile the program, but you won&rsquo;t get complete information about
  267. the modules that were compiled without &lsquo;<samp>-pg</samp>&rsquo;. The only information
  268. you get for the functions in those modules is the total time spent in them;
  269. there is no record of how many times they were called, or from where. This
  270. will not affect the flat profile (except that the <code>calls</code> field for
  271. the functions will be blank), but will greatly reduce the usefulness of the
  272. call graph.
  273. </p>
  274. <p>If you wish to perform line-by-line profiling you should use the
  275. <code>gcov</code> tool instead of <code>gprof</code>. See that tool&rsquo;s manual or
  276. info pages for more details of how to do this.
  277. </p>
  278. <p>Note, older versions of <code>gcc</code> produce line-by-line profiling
  279. information that works with <code>gprof</code> rather than <code>gcov</code> so
  280. there is still support for displaying this kind of information in
  281. <code>gprof</code>. See <a href="#Line_002dby_002dline">Line-by-line Profiling</a>.
  282. </p>
  283. <p>It also worth noting that <code>gcc</code> implements a
  284. &lsquo;<samp>-finstrument-functions</samp>&rsquo; command-line option which will insert
  285. calls to special user supplied instrumentation routines at the entry
  286. and exit of every function in their program. This can be used to
  287. implement an alternative profiling scheme.
  288. </p>
  289. <hr>
  290. <span id="Executing"></span><div class="header">
  291. <p>
  292. Next: <a href="#Invoking" accesskey="n" rel="next">Invoking</a>, Previous: <a href="#Compiling" accesskey="p" rel="prev">Compiling</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  293. </div>
  294. <span id="Executing-the-Program"></span><h2 class="chapter">3 Executing the Program</h2>
  295. <p>Once the program is compiled for profiling, you must run it in order to
  296. generate the information that <code>gprof</code> needs. Simply run the program
  297. as usual, using the normal arguments, file names, etc. The program should
  298. run normally, producing the same output as usual. It will, however, run
  299. somewhat slower than normal because of the time spent collecting and
  300. writing the profile data.
  301. </p>
  302. <p>The way you run the program&mdash;the arguments and input that you give
  303. it&mdash;may have a dramatic effect on what the profile information shows. The
  304. profile data will describe the parts of the program that were activated for
  305. the particular input you use. For example, if the first command you give
  306. to your program is to quit, the profile data will show the time used in
  307. initialization and in cleanup, but not much else.
  308. </p>
  309. <p>Your program will write the profile data into a file called <samp>gmon.out</samp>
  310. just before exiting. If there is already a file called <samp>gmon.out</samp>,
  311. its contents are overwritten. You can rename the file afterwards if you
  312. are concerned that it may be overwritten. If your system libc allows you
  313. may be able to write the profile data under a different name. Set the
  314. GMON_OUT_PREFIX environment variable; this name will be appended with
  315. the PID of the running program.
  316. </p>
  317. <p>In order to write the <samp>gmon.out</samp> file properly, your program must exit
  318. normally: by returning from <code>main</code> or by calling <code>exit</code>. Calling
  319. the low-level function <code>_exit</code> does not write the profile data, and
  320. neither does abnormal termination due to an unhandled signal.
  321. </p>
  322. <p>The <samp>gmon.out</samp> file is written in the program&rsquo;s <em>current working
  323. directory</em> at the time it exits. This means that if your program calls
  324. <code>chdir</code>, the <samp>gmon.out</samp> file will be left in the last directory
  325. your program <code>chdir</code>&rsquo;d to. If you don&rsquo;t have permission to write in
  326. this directory, the file is not written, and you will get an error message.
  327. </p>
  328. <p>Older versions of the <small>GNU</small> profiling library may also write a file
  329. called <samp>bb.out</samp>. This file, if present, contains an human-readable
  330. listing of the basic-block execution counts. Unfortunately, the
  331. appearance of a human-readable <samp>bb.out</samp> means the basic-block
  332. counts didn&rsquo;t get written into <samp>gmon.out</samp>.
  333. The Perl script <code>bbconv.pl</code>, included with the <code>gprof</code>
  334. source distribution, will convert a <samp>bb.out</samp> file into
  335. a format readable by <code>gprof</code>. Invoke it like this:
  336. </p>
  337. <div class="example">
  338. <pre class="example">bbconv.pl &lt; bb.out &gt; <var>bh-data</var>
  339. </pre></div>
  340. <p>This translates the information in <samp>bb.out</samp> into a form that
  341. <code>gprof</code> can understand. But you still need to tell <code>gprof</code>
  342. about the existence of this translated information. To do that, include
  343. <var>bb-data</var> on the <code>gprof</code> command line, <em>along with
  344. <samp>gmon.out</samp></em>, like this:
  345. </p>
  346. <div class="example">
  347. <pre class="example">gprof <var>options</var> <var>executable-file</var> gmon.out <var>bb-data</var> [<var>yet-more-profile-data-files</var>&hellip;] [&gt; <var>outfile</var>]
  348. </pre></div>
  349. <hr>
  350. <span id="Invoking"></span><div class="header">
  351. <p>
  352. Next: <a href="#Output" accesskey="n" rel="next">Output</a>, Previous: <a href="#Executing" accesskey="p" rel="prev">Executing</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  353. </div>
  354. <span id="gprof-Command-Summary"></span><h2 class="chapter">4 <code>gprof</code> Command Summary</h2>
  355. <p>After you have a profile data file <samp>gmon.out</samp>, you can run <code>gprof</code>
  356. to interpret the information in it. The <code>gprof</code> program prints a
  357. flat profile and a call graph on standard output. Typically you would
  358. redirect the output of <code>gprof</code> into a file with &lsquo;<samp>&gt;</samp>&rsquo;.
  359. </p>
  360. <p>You run <code>gprof</code> like this:
  361. </p>
  362. <div class="example">
  363. <pre class="example">gprof <var>options</var> [<var>executable-file</var> [<var>profile-data-files</var>&hellip;]] [&gt; <var>outfile</var>]
  364. </pre></div>
  365. <p>Here square-brackets indicate optional arguments.
  366. </p>
  367. <p>If you omit the executable file name, the file <samp>a.out</samp> is used. If
  368. you give no profile data file name, the file <samp>gmon.out</samp> is used. If
  369. any file is not in the proper format, or if the profile data file does not
  370. appear to belong to the executable file, an error message is printed.
  371. </p>
  372. <p>You can give more than one profile data file by entering all their names
  373. after the executable file name; then the statistics in all the data files
  374. are summed together.
  375. </p>
  376. <p>The order of these options does not matter.
  377. </p>
  378. <table class="menu" border="0" cellspacing="0">
  379. <tr><td align="left" valign="top">&bull; <a href="#Output-Options" accesskey="1">Output Options</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling <code>gprof</code>&rsquo;s output style
  380. </td></tr>
  381. <tr><td align="left" valign="top">&bull; <a href="#Analysis-Options" accesskey="2">Analysis Options</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling how <code>gprof</code> analyzes its data
  382. </td></tr>
  383. <tr><td align="left" valign="top">&bull; <a href="#Miscellaneous-Options" accesskey="3">Miscellaneous Options</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  384. </td></tr>
  385. <tr><td align="left" valign="top">&bull; <a href="#Deprecated-Options" accesskey="4">Deprecated Options</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Options you no longer need to use, but which
  386. have been retained for compatibility
  387. </td></tr>
  388. <tr><td align="left" valign="top">&bull; <a href="#Symspecs" accesskey="5">Symspecs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Specifying functions to include or exclude
  389. </td></tr>
  390. </table>
  391. <hr>
  392. <span id="Output-Options"></span><div class="header">
  393. <p>
  394. Next: <a href="#Analysis-Options" accesskey="n" rel="next">Analysis Options</a>, Up: <a href="#Invoking" accesskey="u" rel="up">Invoking</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  395. </div>
  396. <span id="Output-Options-1"></span><h3 class="section">4.1 Output Options</h3>
  397. <p>These options specify which of several output formats
  398. <code>gprof</code> should produce.
  399. </p>
  400. <p>Many of these options take an optional <em>symspec</em> to specify
  401. functions to be included or excluded. These options can be
  402. specified multiple times, with different symspecs, to include
  403. or exclude sets of symbols. See <a href="#Symspecs">Symspecs</a>.
  404. </p>
  405. <p>Specifying any of these options overrides the default (&lsquo;<samp>-p -q</samp>&rsquo;),
  406. which prints a flat profile and call graph analysis
  407. for all functions.
  408. </p>
  409. <dl compact="compact">
  410. <dt><code>-A[<var>symspec</var>]</code></dt>
  411. <dt><code>--annotated-source[=<var>symspec</var>]</code></dt>
  412. <dd><p>The &lsquo;<samp>-A</samp>&rsquo; option causes <code>gprof</code> to print annotated source code.
  413. If <var>symspec</var> is specified, print output only for matching symbols.
  414. See <a href="#Annotated-Source">The Annotated Source Listing</a>.
  415. </p>
  416. </dd>
  417. <dt><code>-b</code></dt>
  418. <dt><code>--brief</code></dt>
  419. <dd><p>If the &lsquo;<samp>-b</samp>&rsquo; option is given, <code>gprof</code> doesn&rsquo;t print the
  420. verbose blurbs that try to explain the meaning of all of the fields in
  421. the tables. This is useful if you intend to print out the output, or
  422. are tired of seeing the blurbs.
  423. </p>
  424. </dd>
  425. <dt><code>-B</code></dt>
  426. <dd><p>The &lsquo;<samp>-B</samp>&rsquo; option causes <code>gprof</code> to print the call graph analysis.
  427. </p>
  428. </dd>
  429. <dt><code>-C[<var>symspec</var>]</code></dt>
  430. <dt><code>--exec-counts[=<var>symspec</var>]</code></dt>
  431. <dd><p>The &lsquo;<samp>-C</samp>&rsquo; option causes <code>gprof</code> to
  432. print a tally of functions and the number of times each was called.
  433. If <var>symspec</var> is specified, print tally only for matching symbols.
  434. </p>
  435. <p>If the profile data file contains basic-block count records, specifying
  436. the &lsquo;<samp>-l</samp>&rsquo; option, along with &lsquo;<samp>-C</samp>&rsquo;, will cause basic-block
  437. execution counts to be tallied and displayed.
  438. </p>
  439. </dd>
  440. <dt><code>-i</code></dt>
  441. <dt><code>--file-info</code></dt>
  442. <dd><p>The &lsquo;<samp>-i</samp>&rsquo; option causes <code>gprof</code> to display summary information
  443. about the profile data file(s) and then exit. The number of histogram,
  444. call graph, and basic-block count records is displayed.
  445. </p>
  446. </dd>
  447. <dt><code>-I <var>dirs</var></code></dt>
  448. <dt><code>--directory-path=<var>dirs</var></code></dt>
  449. <dd><p>The &lsquo;<samp>-I</samp>&rsquo; option specifies a list of search directories in
  450. which to find source files. Environment variable <var>GPROF_PATH</var>
  451. can also be used to convey this information.
  452. Used mostly for annotated source output.
  453. </p>
  454. </dd>
  455. <dt><code>-J[<var>symspec</var>]</code></dt>
  456. <dt><code>--no-annotated-source[=<var>symspec</var>]</code></dt>
  457. <dd><p>The &lsquo;<samp>-J</samp>&rsquo; option causes <code>gprof</code> not to
  458. print annotated source code.
  459. If <var>symspec</var> is specified, <code>gprof</code> prints annotated source,
  460. but excludes matching symbols.
  461. </p>
  462. </dd>
  463. <dt><code>-L</code></dt>
  464. <dt><code>--print-path</code></dt>
  465. <dd><p>Normally, source filenames are printed with the path
  466. component suppressed. The &lsquo;<samp>-L</samp>&rsquo; option causes <code>gprof</code>
  467. to print the full pathname of
  468. source filenames, which is determined
  469. from symbolic debugging information in the image file
  470. and is relative to the directory in which the compiler
  471. was invoked.
  472. </p>
  473. </dd>
  474. <dt><code>-p[<var>symspec</var>]</code></dt>
  475. <dt><code>--flat-profile[=<var>symspec</var>]</code></dt>
  476. <dd><p>The &lsquo;<samp>-p</samp>&rsquo; option causes <code>gprof</code> to print a flat profile.
  477. If <var>symspec</var> is specified, print flat profile only for matching symbols.
  478. See <a href="#Flat-Profile">The Flat Profile</a>.
  479. </p>
  480. </dd>
  481. <dt><code>-P[<var>symspec</var>]</code></dt>
  482. <dt><code>--no-flat-profile[=<var>symspec</var>]</code></dt>
  483. <dd><p>The &lsquo;<samp>-P</samp>&rsquo; option causes <code>gprof</code> to suppress printing a flat profile.
  484. If <var>symspec</var> is specified, <code>gprof</code> prints a flat profile,
  485. but excludes matching symbols.
  486. </p>
  487. </dd>
  488. <dt><code>-q[<var>symspec</var>]</code></dt>
  489. <dt><code>--graph[=<var>symspec</var>]</code></dt>
  490. <dd><p>The &lsquo;<samp>-q</samp>&rsquo; option causes <code>gprof</code> to print the call graph analysis.
  491. If <var>symspec</var> is specified, print call graph only for matching symbols
  492. and their children.
  493. See <a href="#Call-Graph">The Call Graph</a>.
  494. </p>
  495. </dd>
  496. <dt><code>-Q[<var>symspec</var>]</code></dt>
  497. <dt><code>--no-graph[=<var>symspec</var>]</code></dt>
  498. <dd><p>The &lsquo;<samp>-Q</samp>&rsquo; option causes <code>gprof</code> to suppress printing the
  499. call graph.
  500. If <var>symspec</var> is specified, <code>gprof</code> prints a call graph,
  501. but excludes matching symbols.
  502. </p>
  503. </dd>
  504. <dt><code>-t</code></dt>
  505. <dt><code>--table-length=<var>num</var></code></dt>
  506. <dd><p>The &lsquo;<samp>-t</samp>&rsquo; option causes the <var>num</var> most active source lines in
  507. each source file to be listed when source annotation is enabled. The
  508. default is 10.
  509. </p>
  510. </dd>
  511. <dt><code>-y</code></dt>
  512. <dt><code>--separate-files</code></dt>
  513. <dd><p>This option affects annotated source output only.
  514. Normally, <code>gprof</code> prints annotated source files
  515. to standard-output. If this option is specified,
  516. annotated source for a file named <samp>path/<var>filename</var></samp>
  517. is generated in the file <samp><var>filename</var>-ann</samp>. If the underlying
  518. file system would truncate <samp><var>filename</var>-ann</samp> so that it
  519. overwrites the original <samp><var>filename</var></samp>, <code>gprof</code> generates
  520. annotated source in the file <samp><var>filename</var>.ann</samp> instead (if the
  521. original file name has an extension, that extension is <em>replaced</em>
  522. with <samp>.ann</samp>).
  523. </p>
  524. </dd>
  525. <dt><code>-Z[<var>symspec</var>]</code></dt>
  526. <dt><code>--no-exec-counts[=<var>symspec</var>]</code></dt>
  527. <dd><p>The &lsquo;<samp>-Z</samp>&rsquo; option causes <code>gprof</code> not to
  528. print a tally of functions and the number of times each was called.
  529. If <var>symspec</var> is specified, print tally, but exclude matching symbols.
  530. </p>
  531. </dd>
  532. <dt><code>-r</code></dt>
  533. <dt><code>--function-ordering</code></dt>
  534. <dd><p>The &lsquo;<samp>--function-ordering</samp>&rsquo; option causes <code>gprof</code> to print a
  535. suggested function ordering for the program based on profiling data.
  536. This option suggests an ordering which may improve paging, tlb and
  537. cache behavior for the program on systems which support arbitrary
  538. ordering of functions in an executable.
  539. </p>
  540. <p>The exact details of how to force the linker to place functions
  541. in a particular order is system dependent and out of the scope of this
  542. manual.
  543. </p>
  544. </dd>
  545. <dt><code>-R <var>map_file</var></code></dt>
  546. <dt><code>--file-ordering <var>map_file</var></code></dt>
  547. <dd><p>The &lsquo;<samp>--file-ordering</samp>&rsquo; option causes <code>gprof</code> to print a
  548. suggested .o link line ordering for the program based on profiling data.
  549. This option suggests an ordering which may improve paging, tlb and
  550. cache behavior for the program on systems which do not support arbitrary
  551. ordering of functions in an executable.
  552. </p>
  553. <p>Use of the &lsquo;<samp>-a</samp>&rsquo; argument is highly recommended with this option.
  554. </p>
  555. <p>The <var>map_file</var> argument is a pathname to a file which provides
  556. function name to object file mappings. The format of the file is similar to
  557. the output of the program <code>nm</code>.
  558. </p>
  559. <div class="example">
  560. <pre class="example">c-parse.o:00000000 T yyparse
  561. c-parse.o:00000004 C yyerrflag
  562. c-lang.o:00000000 T maybe_objc_method_name
  563. c-lang.o:00000000 T print_lang_statistics
  564. c-lang.o:00000000 T recognize_objc_keyword
  565. c-decl.o:00000000 T print_lang_identifier
  566. c-decl.o:00000000 T print_lang_type
  567. &hellip;
  568. </pre></div>
  569. <p>To create a <var>map_file</var> with <small>GNU</small> <code>nm</code>, type a command like
  570. <kbd>nm --extern-only --defined-only -v --print-file-name program-name</kbd>.
  571. </p>
  572. </dd>
  573. <dt><code>-T</code></dt>
  574. <dt><code>--traditional</code></dt>
  575. <dd><p>The &lsquo;<samp>-T</samp>&rsquo; option causes <code>gprof</code> to print its output in
  576. &ldquo;traditional&rdquo; BSD style.
  577. </p>
  578. </dd>
  579. <dt><code>-w <var>width</var></code></dt>
  580. <dt><code>--width=<var>width</var></code></dt>
  581. <dd><p>Sets width of output lines to <var>width</var>.
  582. Currently only used when printing the function index at the bottom
  583. of the call graph.
  584. </p>
  585. </dd>
  586. <dt><code>-x</code></dt>
  587. <dt><code>--all-lines</code></dt>
  588. <dd><p>This option affects annotated source output only.
  589. By default, only the lines at the beginning of a basic-block
  590. are annotated. If this option is specified, every line in
  591. a basic-block is annotated by repeating the annotation for the
  592. first line. This behavior is similar to <code>tcov</code>&rsquo;s &lsquo;<samp>-a</samp>&rsquo;.
  593. </p>
  594. </dd>
  595. <dt><code>--demangle[=<var>style</var>]</code></dt>
  596. <dt><code>--no-demangle</code></dt>
  597. <dd><p>These options control whether C++ symbol names should be demangled when
  598. printing output. The default is to demangle symbols. The
  599. <code>--no-demangle</code> option may be used to turn off demangling. Different
  600. compilers have different mangling styles. The optional demangling style
  601. argument can be used to choose an appropriate demangling style for your
  602. compiler.
  603. </p></dd>
  604. </dl>
  605. <hr>
  606. <span id="Analysis-Options"></span><div class="header">
  607. <p>
  608. Next: <a href="#Miscellaneous-Options" accesskey="n" rel="next">Miscellaneous Options</a>, Previous: <a href="#Output-Options" accesskey="p" rel="prev">Output Options</a>, Up: <a href="#Invoking" accesskey="u" rel="up">Invoking</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  609. </div>
  610. <span id="Analysis-Options-1"></span><h3 class="section">4.2 Analysis Options</h3>
  611. <dl compact="compact">
  612. <dt><code>-a</code></dt>
  613. <dt><code>--no-static</code></dt>
  614. <dd><p>The &lsquo;<samp>-a</samp>&rsquo; option causes <code>gprof</code> to suppress the printing of
  615. statically declared (private) functions. (These are functions whose
  616. names are not listed as global, and which are not visible outside the
  617. file/function/block where they were defined.) Time spent in these
  618. functions, calls to/from them, etc., will all be attributed to the
  619. function that was loaded directly before it in the executable file.
  620. This option affects both the flat profile and the call graph.
  621. </p>
  622. </dd>
  623. <dt><code>-c</code></dt>
  624. <dt><code>--static-call-graph</code></dt>
  625. <dd><p>The &lsquo;<samp>-c</samp>&rsquo; option causes the call graph of the program to be
  626. augmented by a heuristic which examines the text space of the object
  627. file and identifies function calls in the binary machine code.
  628. Since normal call graph records are only generated when functions are
  629. entered, this option identifies children that could have been called,
  630. but never were. Calls to functions that were not compiled with
  631. profiling enabled are also identified, but only if symbol table
  632. entries are present for them.
  633. Calls to dynamic library routines are typically <em>not</em> found
  634. by this option.
  635. Parents or children identified via this heuristic
  636. are indicated in the call graph with call counts of &lsquo;<samp>0</samp>&rsquo;.
  637. </p>
  638. </dd>
  639. <dt><code>-D</code></dt>
  640. <dt><code>--ignore-non-functions</code></dt>
  641. <dd><p>The &lsquo;<samp>-D</samp>&rsquo; option causes <code>gprof</code> to ignore symbols which
  642. are not known to be functions. This option will give more accurate
  643. profile data on systems where it is supported (Solaris and HPUX for
  644. example).
  645. </p>
  646. </dd>
  647. <dt><code>-k <var>from</var>/<var>to</var></code></dt>
  648. <dd><p>The &lsquo;<samp>-k</samp>&rsquo; option allows you to delete from the call graph any arcs from
  649. symbols matching symspec <var>from</var> to those matching symspec <var>to</var>.
  650. </p>
  651. </dd>
  652. <dt><code>-l</code></dt>
  653. <dt><code>--line</code></dt>
  654. <dd><p>The &lsquo;<samp>-l</samp>&rsquo; option enables line-by-line profiling, which causes
  655. histogram hits to be charged to individual source code lines,
  656. instead of functions. This feature only works with programs compiled
  657. by older versions of the <code>gcc</code> compiler. Newer versions of
  658. <code>gcc</code> are designed to work with the <code>gcov</code> tool instead.
  659. </p>
  660. <p>If the program was compiled with basic-block counting enabled,
  661. this option will also identify how many times each line of
  662. code was executed.
  663. While line-by-line profiling can help isolate where in a large function
  664. a program is spending its time, it also significantly increases
  665. the running time of <code>gprof</code>, and magnifies statistical
  666. inaccuracies.
  667. See <a href="#Sampling-Error">Statistical Sampling Error</a>.
  668. </p>
  669. </dd>
  670. <dt><code>--inline-file-names</code></dt>
  671. <dd><p>This option causes <code>gprof</code> to print the source file after each
  672. symbol in both the flat profile and the call graph. The full path to the
  673. file is printed if used with the &lsquo;<samp>-L</samp>&rsquo; option.
  674. </p>
  675. </dd>
  676. <dt><code>-m <var>num</var></code></dt>
  677. <dt><code>--min-count=<var>num</var></code></dt>
  678. <dd><p>This option affects execution count output only.
  679. Symbols that are executed less than <var>num</var> times are suppressed.
  680. </p>
  681. </dd>
  682. <dt><code>-n<var>symspec</var></code></dt>
  683. <dt><code>--time=<var>symspec</var></code></dt>
  684. <dd><p>The &lsquo;<samp>-n</samp>&rsquo; option causes <code>gprof</code>, in its call graph analysis,
  685. to only propagate times for symbols matching <var>symspec</var>.
  686. </p>
  687. </dd>
  688. <dt><code>-N<var>symspec</var></code></dt>
  689. <dt><code>--no-time=<var>symspec</var></code></dt>
  690. <dd><p>The &lsquo;<samp>-n</samp>&rsquo; option causes <code>gprof</code>, in its call graph analysis,
  691. not to propagate times for symbols matching <var>symspec</var>.
  692. </p>
  693. </dd>
  694. <dt><code>-S<var>filename</var></code></dt>
  695. <dt><code>--external-symbol-table=<var>filename</var></code></dt>
  696. <dd><p>The &lsquo;<samp>-S</samp>&rsquo; option causes <code>gprof</code> to read an external symbol table
  697. file, such as <samp>/proc/kallsyms</samp>, rather than read the symbol table
  698. from the given object file (the default is <code>a.out</code>). This is useful
  699. for profiling kernel modules.
  700. </p>
  701. </dd>
  702. <dt><code>-z</code></dt>
  703. <dt><code>--display-unused-functions</code></dt>
  704. <dd><p>If you give the &lsquo;<samp>-z</samp>&rsquo; option, <code>gprof</code> will mention all
  705. functions in the flat profile, even those that were never called, and
  706. that had no time spent in them. This is useful in conjunction with the
  707. &lsquo;<samp>-c</samp>&rsquo; option for discovering which routines were never called.
  708. </p>
  709. </dd>
  710. </dl>
  711. <hr>
  712. <span id="Miscellaneous-Options"></span><div class="header">
  713. <p>
  714. Next: <a href="#Deprecated-Options" accesskey="n" rel="next">Deprecated Options</a>, Previous: <a href="#Analysis-Options" accesskey="p" rel="prev">Analysis Options</a>, Up: <a href="#Invoking" accesskey="u" rel="up">Invoking</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  715. </div>
  716. <span id="Miscellaneous-Options-1"></span><h3 class="section">4.3 Miscellaneous Options</h3>
  717. <dl compact="compact">
  718. <dt><code>-d[<var>num</var>]</code></dt>
  719. <dt><code>--debug[=<var>num</var>]</code></dt>
  720. <dd><p>The &lsquo;<samp>-d <var>num</var></samp>&rsquo; option specifies debugging options.
  721. If <var>num</var> is not specified, enable all debugging.
  722. See <a href="#Debugging">Debugging <code>gprof</code></a>.
  723. </p>
  724. </dd>
  725. <dt><code>-h</code></dt>
  726. <dt><code>--help</code></dt>
  727. <dd><p>The &lsquo;<samp>-h</samp>&rsquo; option prints command line usage.
  728. </p>
  729. </dd>
  730. <dt><code>-O<var>name</var></code></dt>
  731. <dt><code>--file-format=<var>name</var></code></dt>
  732. <dd><p>Selects the format of the profile data files. Recognized formats are
  733. &lsquo;<samp>auto</samp>&rsquo; (the default), &lsquo;<samp>bsd</samp>&rsquo;, &lsquo;<samp>4.4bsd</samp>&rsquo;, &lsquo;<samp>magic</samp>&rsquo;, and
  734. &lsquo;<samp>prof</samp>&rsquo; (not yet supported).
  735. </p>
  736. </dd>
  737. <dt><code>-s</code></dt>
  738. <dt><code>--sum</code></dt>
  739. <dd><p>The &lsquo;<samp>-s</samp>&rsquo; option causes <code>gprof</code> to summarize the information
  740. in the profile data files it read in, and write out a profile data
  741. file called <samp>gmon.sum</samp>, which contains all the information from
  742. the profile data files that <code>gprof</code> read in. The file <samp>gmon.sum</samp>
  743. may be one of the specified input files; the effect of this is to
  744. merge the data in the other input files into <samp>gmon.sum</samp>.
  745. </p>
  746. <p>Eventually you can run <code>gprof</code> again without &lsquo;<samp>-s</samp>&rsquo; to analyze the
  747. cumulative data in the file <samp>gmon.sum</samp>.
  748. </p>
  749. </dd>
  750. <dt><code>-v</code></dt>
  751. <dt><code>--version</code></dt>
  752. <dd><p>The &lsquo;<samp>-v</samp>&rsquo; flag causes <code>gprof</code> to print the current version
  753. number, and then exit.
  754. </p>
  755. </dd>
  756. </dl>
  757. <hr>
  758. <span id="Deprecated-Options"></span><div class="header">
  759. <p>
  760. Next: <a href="#Symspecs" accesskey="n" rel="next">Symspecs</a>, Previous: <a href="#Miscellaneous-Options" accesskey="p" rel="prev">Miscellaneous Options</a>, Up: <a href="#Invoking" accesskey="u" rel="up">Invoking</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  761. </div>
  762. <span id="Deprecated-Options-1"></span><h3 class="section">4.4 Deprecated Options</h3>
  763. <p>These options have been replaced with newer versions that use symspecs.
  764. </p>
  765. <dl compact="compact">
  766. <dt><code>-e <var>function_name</var></code></dt>
  767. <dd><p>The &lsquo;<samp>-e <var>function</var></samp>&rsquo; option tells <code>gprof</code> to not print
  768. information about the function <var>function_name</var> (and its
  769. children&hellip;) in the call graph. The function will still be listed
  770. as a child of any functions that call it, but its index number will be
  771. shown as &lsquo;<samp>[not printed]</samp>&rsquo;. More than one &lsquo;<samp>-e</samp>&rsquo; option may be
  772. given; only one <var>function_name</var> may be indicated with each &lsquo;<samp>-e</samp>&rsquo;
  773. option.
  774. </p>
  775. </dd>
  776. <dt><code>-E <var>function_name</var></code></dt>
  777. <dd><p>The <code>-E <var>function</var></code> option works like the <code>-e</code> option, but
  778. time spent in the function (and children who were not called from
  779. anywhere else), will not be used to compute the percentages-of-time for
  780. the call graph. More than one &lsquo;<samp>-E</samp>&rsquo; option may be given; only one
  781. <var>function_name</var> may be indicated with each &lsquo;<samp>-E</samp>&rsquo; option.
  782. </p>
  783. </dd>
  784. <dt><code>-f <var>function_name</var></code></dt>
  785. <dd><p>The &lsquo;<samp>-f <var>function</var></samp>&rsquo; option causes <code>gprof</code> to limit the
  786. call graph to the function <var>function_name</var> and its children (and
  787. their children&hellip;). More than one &lsquo;<samp>-f</samp>&rsquo; option may be given;
  788. only one <var>function_name</var> may be indicated with each &lsquo;<samp>-f</samp>&rsquo;
  789. option.
  790. </p>
  791. </dd>
  792. <dt><code>-F <var>function_name</var></code></dt>
  793. <dd><p>The &lsquo;<samp>-F <var>function</var></samp>&rsquo; option works like the <code>-f</code> option, but
  794. only time spent in the function and its children (and their
  795. children&hellip;) will be used to determine total-time and
  796. percentages-of-time for the call graph. More than one &lsquo;<samp>-F</samp>&rsquo; option
  797. may be given; only one <var>function_name</var> may be indicated with each
  798. &lsquo;<samp>-F</samp>&rsquo; option. The &lsquo;<samp>-F</samp>&rsquo; option overrides the &lsquo;<samp>-E</samp>&rsquo; option.
  799. </p>
  800. </dd>
  801. </dl>
  802. <p>Note that only one function can be specified with each <code>-e</code>,
  803. <code>-E</code>, <code>-f</code> or <code>-F</code> option. To specify more than one
  804. function, use multiple options. For example, this command:
  805. </p>
  806. <div class="example">
  807. <pre class="example">gprof -e boring -f foo -f bar myprogram &gt; gprof.output
  808. </pre></div>
  809. <p>lists in the call graph all functions that were reached from either
  810. <code>foo</code> or <code>bar</code> and were not reachable from <code>boring</code>.
  811. </p>
  812. <hr>
  813. <span id="Symspecs"></span><div class="header">
  814. <p>
  815. Previous: <a href="#Deprecated-Options" accesskey="p" rel="prev">Deprecated Options</a>, Up: <a href="#Invoking" accesskey="u" rel="up">Invoking</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  816. </div>
  817. <span id="Symspecs-1"></span><h3 class="section">4.5 Symspecs</h3>
  818. <p>Many of the output options allow functions to be included or excluded
  819. using <em>symspecs</em> (symbol specifications), which observe the
  820. following syntax:
  821. </p>
  822. <div class="example">
  823. <pre class="example"> filename_containing_a_dot
  824. | funcname_not_containing_a_dot
  825. | linenumber
  826. | ( [ any_filename ] `:' ( any_funcname | linenumber ) )
  827. </pre></div>
  828. <p>Here are some sample symspecs:
  829. </p>
  830. <dl compact="compact">
  831. <dt>&lsquo;<samp>main.c</samp>&rsquo;</dt>
  832. <dd><p>Selects everything in file <samp>main.c</samp>&mdash;the
  833. dot in the string tells <code>gprof</code> to interpret
  834. the string as a filename, rather than as
  835. a function name. To select a file whose
  836. name does not contain a dot, a trailing colon
  837. should be specified. For example, &lsquo;<samp>odd:</samp>&rsquo; is
  838. interpreted as the file named <samp>odd</samp>.
  839. </p>
  840. </dd>
  841. <dt>&lsquo;<samp>main</samp>&rsquo;</dt>
  842. <dd><p>Selects all functions named &lsquo;<samp>main</samp>&rsquo;.
  843. </p>
  844. <p>Note that there may be multiple instances of the same function name
  845. because some of the definitions may be local (i.e., static). Unless a
  846. function name is unique in a program, you must use the colon notation
  847. explained below to specify a function from a specific source file.
  848. </p>
  849. <p>Sometimes, function names contain dots. In such cases, it is necessary
  850. to add a leading colon to the name. For example, &lsquo;<samp>:.mul</samp>&rsquo; selects
  851. function &lsquo;<samp>.mul</samp>&rsquo;.
  852. </p>
  853. <p>In some object file formats, symbols have a leading underscore.
  854. <code>gprof</code> will normally not print these underscores. When you name a
  855. symbol in a symspec, you should type it exactly as <code>gprof</code> prints
  856. it in its output. For example, if the compiler produces a symbol
  857. &lsquo;<samp>_main</samp>&rsquo; from your <code>main</code> function, <code>gprof</code> still prints
  858. it as &lsquo;<samp>main</samp>&rsquo; in its output, so you should use &lsquo;<samp>main</samp>&rsquo; in
  859. symspecs.
  860. </p>
  861. </dd>
  862. <dt>&lsquo;<samp>main.c:main</samp>&rsquo;</dt>
  863. <dd><p>Selects function &lsquo;<samp>main</samp>&rsquo; in file <samp>main.c</samp>.
  864. </p>
  865. </dd>
  866. <dt>&lsquo;<samp>main.c:134</samp>&rsquo;</dt>
  867. <dd><p>Selects line 134 in file <samp>main.c</samp>.
  868. </p></dd>
  869. </dl>
  870. <hr>
  871. <span id="Output"></span><div class="header">
  872. <p>
  873. Next: <a href="#Inaccuracy" accesskey="n" rel="next">Inaccuracy</a>, Previous: <a href="#Invoking" accesskey="p" rel="prev">Invoking</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  874. </div>
  875. <span id="Interpreting-gprof_0027s-Output"></span><h2 class="chapter">5 Interpreting <code>gprof</code>&rsquo;s Output</h2>
  876. <p><code>gprof</code> can produce several different output styles, the
  877. most important of which are described below. The simplest output
  878. styles (file information, execution count, and function and file ordering)
  879. are not described here, but are documented with the respective options
  880. that trigger them.
  881. See <a href="#Output-Options">Output Options</a>.
  882. </p>
  883. <table class="menu" border="0" cellspacing="0">
  884. <tr><td align="left" valign="top">&bull; <a href="#Flat-Profile" accesskey="1">Flat Profile</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The flat profile shows how much time was spent
  885. executing directly in each function.
  886. </td></tr>
  887. <tr><td align="left" valign="top">&bull; <a href="#Call-Graph" accesskey="2">Call Graph</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The call graph shows which functions called which
  888. others, and how much time each function used
  889. when its subroutine calls are included.
  890. </td></tr>
  891. <tr><td align="left" valign="top">&bull; <a href="#Line_002dby_002dline" accesskey="3">Line-by-line</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"><code>gprof</code> can analyze individual source code lines
  892. </td></tr>
  893. <tr><td align="left" valign="top">&bull; <a href="#Annotated-Source" accesskey="4">Annotated Source</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The annotated source listing displays source code
  894. labeled with execution counts
  895. </td></tr>
  896. </table>
  897. <hr>
  898. <span id="Flat-Profile"></span><div class="header">
  899. <p>
  900. Next: <a href="#Call-Graph" accesskey="n" rel="next">Call Graph</a>, Up: <a href="#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  901. </div>
  902. <span id="The-Flat-Profile"></span><h3 class="section">5.1 The Flat Profile</h3>
  903. <span id="index-flat-profile"></span>
  904. <p>The <em>flat profile</em> shows the total amount of time your program
  905. spent executing each function. Unless the &lsquo;<samp>-z</samp>&rsquo; option is given,
  906. functions with no apparent time spent in them, and no apparent calls
  907. to them, are not mentioned. Note that if a function was not compiled
  908. for profiling, and didn&rsquo;t run long enough to show up on the program
  909. counter histogram, it will be indistinguishable from a function that
  910. was never called.
  911. </p>
  912. <p>This is part of a flat profile for a small program:
  913. </p>
  914. <div class="example">
  915. <pre class="example">Flat profile:
  916. Each sample counts as 0.01 seconds.
  917. % cumulative self self total
  918. time seconds seconds calls ms/call ms/call name
  919. 33.34 0.02 0.02 7208 0.00 0.00 open
  920. 16.67 0.03 0.01 244 0.04 0.12 offtime
  921. 16.67 0.04 0.01 8 1.25 1.25 memccpy
  922. 16.67 0.05 0.01 7 1.43 1.43 write
  923. 16.67 0.06 0.01 mcount
  924. 0.00 0.06 0.00 236 0.00 0.00 tzset
  925. 0.00 0.06 0.00 192 0.00 0.00 tolower
  926. 0.00 0.06 0.00 47 0.00 0.00 strlen
  927. 0.00 0.06 0.00 45 0.00 0.00 strchr
  928. 0.00 0.06 0.00 1 0.00 50.00 main
  929. 0.00 0.06 0.00 1 0.00 0.00 memcpy
  930. 0.00 0.06 0.00 1 0.00 10.11 print
  931. 0.00 0.06 0.00 1 0.00 0.00 profil
  932. 0.00 0.06 0.00 1 0.00 50.00 report
  933. &hellip;
  934. </pre></div>
  935. <p>The functions are sorted first by decreasing run-time spent in them,
  936. then by decreasing number of calls, then alphabetically by name. The
  937. functions &lsquo;<samp>mcount</samp>&rsquo; and &lsquo;<samp>profil</samp>&rsquo; are part of the profiling
  938. apparatus and appear in every flat profile; their time gives a measure of
  939. the amount of overhead due to profiling.
  940. </p>
  941. <p>Just before the column headers, a statement appears indicating
  942. how much time each sample counted as.
  943. This <em>sampling period</em> estimates the margin of error in each of the time
  944. figures. A time figure that is not much larger than this is not
  945. reliable. In this example, each sample counted as 0.01 seconds,
  946. suggesting a 100 Hz sampling rate.
  947. The program&rsquo;s total execution time was 0.06
  948. seconds, as indicated by the &lsquo;<samp>cumulative seconds</samp>&rsquo; field. Since
  949. each sample counted for 0.01 seconds, this means only six samples
  950. were taken during the run. Two of the samples occurred while the
  951. program was in the &lsquo;<samp>open</samp>&rsquo; function, as indicated by the
  952. &lsquo;<samp>self seconds</samp>&rsquo; field. Each of the other four samples
  953. occurred one each in &lsquo;<samp>offtime</samp>&rsquo;, &lsquo;<samp>memccpy</samp>&rsquo;, &lsquo;<samp>write</samp>&rsquo;,
  954. and &lsquo;<samp>mcount</samp>&rsquo;.
  955. Since only six samples were taken, none of these values can
  956. be regarded as particularly reliable.
  957. In another run,
  958. the &lsquo;<samp>self seconds</samp>&rsquo; field for
  959. &lsquo;<samp>mcount</samp>&rsquo; might well be &lsquo;<samp>0.00</samp>&rsquo; or &lsquo;<samp>0.02</samp>&rsquo;.
  960. See <a href="#Sampling-Error">Statistical Sampling Error</a>,
  961. for a complete discussion.
  962. </p>
  963. <p>The remaining functions in the listing (those whose
  964. &lsquo;<samp>self seconds</samp>&rsquo; field is &lsquo;<samp>0.00</samp>&rsquo;) didn&rsquo;t appear
  965. in the histogram samples at all. However, the call graph
  966. indicated that they were called, so therefore they are listed,
  967. sorted in decreasing order by the &lsquo;<samp>calls</samp>&rsquo; field.
  968. Clearly some time was spent executing these functions,
  969. but the paucity of histogram samples prevents any
  970. determination of how much time each took.
  971. </p>
  972. <p>Here is what the fields in each line mean:
  973. </p>
  974. <dl compact="compact">
  975. <dt><code>% time</code></dt>
  976. <dd><p>This is the percentage of the total execution time your program spent
  977. in this function. These should all add up to 100%.
  978. </p>
  979. </dd>
  980. <dt><code>cumulative seconds</code></dt>
  981. <dd><p>This is the cumulative total number of seconds the computer spent
  982. executing this functions, plus the time spent in all the functions
  983. above this one in this table.
  984. </p>
  985. </dd>
  986. <dt><code>self seconds</code></dt>
  987. <dd><p>This is the number of seconds accounted for by this function alone.
  988. The flat profile listing is sorted first by this number.
  989. </p>
  990. </dd>
  991. <dt><code>calls</code></dt>
  992. <dd><p>This is the total number of times the function was called. If the
  993. function was never called, or the number of times it was called cannot
  994. be determined (probably because the function was not compiled with
  995. profiling enabled), the <em>calls</em> field is blank.
  996. </p>
  997. </dd>
  998. <dt><code>self ms/call</code></dt>
  999. <dd><p>This represents the average number of milliseconds spent in this
  1000. function per call, if this function is profiled. Otherwise, this field
  1001. is blank for this function.
  1002. </p>
  1003. </dd>
  1004. <dt><code>total ms/call</code></dt>
  1005. <dd><p>This represents the average number of milliseconds spent in this
  1006. function and its descendants per call, if this function is profiled.
  1007. Otherwise, this field is blank for this function.
  1008. This is the only field in the flat profile that uses call graph analysis.
  1009. </p>
  1010. </dd>
  1011. <dt><code>name</code></dt>
  1012. <dd><p>This is the name of the function. The flat profile is sorted by this
  1013. field alphabetically after the <em>self seconds</em> and <em>calls</em>
  1014. fields are sorted.
  1015. </p></dd>
  1016. </dl>
  1017. <hr>
  1018. <span id="Call-Graph"></span><div class="header">
  1019. <p>
  1020. Next: <a href="#Line_002dby_002dline" accesskey="n" rel="next">Line-by-line</a>, Previous: <a href="#Flat-Profile" accesskey="p" rel="prev">Flat Profile</a>, Up: <a href="#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1021. </div>
  1022. <span id="The-Call-Graph"></span><h3 class="section">5.2 The Call Graph</h3>
  1023. <span id="index-call-graph"></span>
  1024. <p>The <em>call graph</em> shows how much time was spent in each function
  1025. and its children. From this information, you can find functions that,
  1026. while they themselves may not have used much time, called other
  1027. functions that did use unusual amounts of time.
  1028. </p>
  1029. <p>Here is a sample call from a small program. This call came from the
  1030. same <code>gprof</code> run as the flat profile example in the previous
  1031. section.
  1032. </p>
  1033. <div class="example">
  1034. <pre class="example">granularity: each sample hit covers 2 byte(s) for 20.00% of 0.05 seconds
  1035. index % time self children called name
  1036. &lt;spontaneous&gt;
  1037. [1] 100.0 0.00 0.05 start [1]
  1038. 0.00 0.05 1/1 main [2]
  1039. 0.00 0.00 1/2 on_exit [28]
  1040. 0.00 0.00 1/1 exit [59]
  1041. -----------------------------------------------
  1042. 0.00 0.05 1/1 start [1]
  1043. [2] 100.0 0.00 0.05 1 main [2]
  1044. 0.00 0.05 1/1 report [3]
  1045. -----------------------------------------------
  1046. 0.00 0.05 1/1 main [2]
  1047. [3] 100.0 0.00 0.05 1 report [3]
  1048. 0.00 0.03 8/8 timelocal [6]
  1049. 0.00 0.01 1/1 print [9]
  1050. 0.00 0.01 9/9 fgets [12]
  1051. 0.00 0.00 12/34 strncmp &lt;cycle 1&gt; [40]
  1052. 0.00 0.00 8/8 lookup [20]
  1053. 0.00 0.00 1/1 fopen [21]
  1054. 0.00 0.00 8/8 chewtime [24]
  1055. 0.00 0.00 8/16 skipspace [44]
  1056. -----------------------------------------------
  1057. [4] 59.8 0.01 0.02 8+472 &lt;cycle 2 as a whole&gt; [4]
  1058. 0.01 0.02 244+260 offtime &lt;cycle 2&gt; [7]
  1059. 0.00 0.00 236+1 tzset &lt;cycle 2&gt; [26]
  1060. -----------------------------------------------
  1061. </pre></div>
  1062. <p>The lines full of dashes divide this table into <em>entries</em>, one for each
  1063. function. Each entry has one or more lines.
  1064. </p>
  1065. <p>In each entry, the primary line is the one that starts with an index number
  1066. in square brackets. The end of this line says which function the entry is
  1067. for. The preceding lines in the entry describe the callers of this
  1068. function and the following lines describe its subroutines (also called
  1069. <em>children</em> when we speak of the call graph).
  1070. </p>
  1071. <p>The entries are sorted by time spent in the function and its subroutines.
  1072. </p>
  1073. <p>The internal profiling function <code>mcount</code> (see <a href="#Flat-Profile">The
  1074. Flat Profile</a>) is never mentioned in the call graph.
  1075. </p>
  1076. <table class="menu" border="0" cellspacing="0">
  1077. <tr><td align="left" valign="top">&bull; <a href="#Primary" accesskey="1">Primary</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Details of the primary line&rsquo;s contents.
  1078. </td></tr>
  1079. <tr><td align="left" valign="top">&bull; <a href="#Callers" accesskey="2">Callers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Details of caller-lines&rsquo; contents.
  1080. </td></tr>
  1081. <tr><td align="left" valign="top">&bull; <a href="#Subroutines" accesskey="3">Subroutines</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Details of subroutine-lines&rsquo; contents.
  1082. </td></tr>
  1083. <tr><td align="left" valign="top">&bull; <a href="#Cycles" accesskey="4">Cycles</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">When there are cycles of recursion,
  1084. such as <code>a</code> calls <code>b</code> calls <code>a</code>&hellip;
  1085. </td></tr>
  1086. </table>
  1087. <hr>
  1088. <span id="Primary"></span><div class="header">
  1089. <p>
  1090. Next: <a href="#Callers" accesskey="n" rel="next">Callers</a>, Up: <a href="#Call-Graph" accesskey="u" rel="up">Call Graph</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1091. </div>
  1092. <span id="The-Primary-Line"></span><h4 class="subsection">5.2.1 The Primary Line</h4>
  1093. <p>The <em>primary line</em> in a call graph entry is the line that
  1094. describes the function which the entry is about and gives the overall
  1095. statistics for this function.
  1096. </p>
  1097. <p>For reference, we repeat the primary line from the entry for function
  1098. <code>report</code> in our main example, together with the heading line that
  1099. shows the names of the fields:
  1100. </p>
  1101. <div class="example">
  1102. <pre class="example">index % time self children called name
  1103. &hellip;
  1104. [3] 100.0 0.00 0.05 1 report [3]
  1105. </pre></div>
  1106. <p>Here is what the fields in the primary line mean:
  1107. </p>
  1108. <dl compact="compact">
  1109. <dt><code>index</code></dt>
  1110. <dd><p>Entries are numbered with consecutive integers. Each function
  1111. therefore has an index number, which appears at the beginning of its
  1112. primary line.
  1113. </p>
  1114. <p>Each cross-reference to a function, as a caller or subroutine of
  1115. another, gives its index number as well as its name. The index number
  1116. guides you if you wish to look for the entry for that function.
  1117. </p>
  1118. </dd>
  1119. <dt><code>% time</code></dt>
  1120. <dd><p>This is the percentage of the total time that was spent in this
  1121. function, including time spent in subroutines called from this
  1122. function.
  1123. </p>
  1124. <p>The time spent in this function is counted again for the callers of
  1125. this function. Therefore, adding up these percentages is meaningless.
  1126. </p>
  1127. </dd>
  1128. <dt><code>self</code></dt>
  1129. <dd><p>This is the total amount of time spent in this function. This
  1130. should be identical to the number printed in the <code>seconds</code> field
  1131. for this function in the flat profile.
  1132. </p>
  1133. </dd>
  1134. <dt><code>children</code></dt>
  1135. <dd><p>This is the total amount of time spent in the subroutine calls made by
  1136. this function. This should be equal to the sum of all the <code>self</code>
  1137. and <code>children</code> entries of the children listed directly below this
  1138. function.
  1139. </p>
  1140. </dd>
  1141. <dt><code>called</code></dt>
  1142. <dd><p>This is the number of times the function was called.
  1143. </p>
  1144. <p>If the function called itself recursively, there are two numbers,
  1145. separated by a &lsquo;<samp>+</samp>&rsquo;. The first number counts non-recursive calls,
  1146. and the second counts recursive calls.
  1147. </p>
  1148. <p>In the example above, the function <code>report</code> was called once from
  1149. <code>main</code>.
  1150. </p>
  1151. </dd>
  1152. <dt><code>name</code></dt>
  1153. <dd><p>This is the name of the current function. The index number is
  1154. repeated after it.
  1155. </p>
  1156. <p>If the function is part of a cycle of recursion, the cycle number is
  1157. printed between the function&rsquo;s name and the index number
  1158. (see <a href="#Cycles">How Mutually Recursive Functions Are Described</a>).
  1159. For example, if function <code>gnurr</code> is part of
  1160. cycle number one, and has index number twelve, its primary line would
  1161. be end like this:
  1162. </p>
  1163. <div class="example">
  1164. <pre class="example">gnurr &lt;cycle 1&gt; [12]
  1165. </pre></div>
  1166. </dd>
  1167. </dl>
  1168. <hr>
  1169. <span id="Callers"></span><div class="header">
  1170. <p>
  1171. Next: <a href="#Subroutines" accesskey="n" rel="next">Subroutines</a>, Previous: <a href="#Primary" accesskey="p" rel="prev">Primary</a>, Up: <a href="#Call-Graph" accesskey="u" rel="up">Call Graph</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1172. </div>
  1173. <span id="Lines-for-a-Function_0027s-Callers"></span><h4 class="subsection">5.2.2 Lines for a Function&rsquo;s Callers</h4>
  1174. <p>A function&rsquo;s entry has a line for each function it was called by.
  1175. These lines&rsquo; fields correspond to the fields of the primary line, but
  1176. their meanings are different because of the difference in context.
  1177. </p>
  1178. <p>For reference, we repeat two lines from the entry for the function
  1179. <code>report</code>, the primary line and one caller-line preceding it, together
  1180. with the heading line that shows the names of the fields:
  1181. </p>
  1182. <div class="example">
  1183. <pre class="example">index % time self children called name
  1184. &hellip;
  1185. 0.00 0.05 1/1 main [2]
  1186. [3] 100.0 0.00 0.05 1 report [3]
  1187. </pre></div>
  1188. <p>Here are the meanings of the fields in the caller-line for <code>report</code>
  1189. called from <code>main</code>:
  1190. </p>
  1191. <dl compact="compact">
  1192. <dt><code>self</code></dt>
  1193. <dd><p>An estimate of the amount of time spent in <code>report</code> itself when it was
  1194. called from <code>main</code>.
  1195. </p>
  1196. </dd>
  1197. <dt><code>children</code></dt>
  1198. <dd><p>An estimate of the amount of time spent in subroutines of <code>report</code>
  1199. when <code>report</code> was called from <code>main</code>.
  1200. </p>
  1201. <p>The sum of the <code>self</code> and <code>children</code> fields is an estimate
  1202. of the amount of time spent within calls to <code>report</code> from <code>main</code>.
  1203. </p>
  1204. </dd>
  1205. <dt><code>called</code></dt>
  1206. <dd><p>Two numbers: the number of times <code>report</code> was called from <code>main</code>,
  1207. followed by the total number of non-recursive calls to <code>report</code> from
  1208. all its callers.
  1209. </p>
  1210. </dd>
  1211. <dt><code>name and index number</code></dt>
  1212. <dd><p>The name of the caller of <code>report</code> to which this line applies,
  1213. followed by the caller&rsquo;s index number.
  1214. </p>
  1215. <p>Not all functions have entries in the call graph; some
  1216. options to <code>gprof</code> request the omission of certain functions.
  1217. When a caller has no entry of its own, it still has caller-lines
  1218. in the entries of the functions it calls.
  1219. </p>
  1220. <p>If the caller is part of a recursion cycle, the cycle number is
  1221. printed between the name and the index number.
  1222. </p></dd>
  1223. </dl>
  1224. <p>If the identity of the callers of a function cannot be determined, a
  1225. dummy caller-line is printed which has &lsquo;<samp>&lt;spontaneous&gt;</samp>&rsquo; as the
  1226. &ldquo;caller&rsquo;s name&rdquo; and all other fields blank. This can happen for
  1227. signal handlers.
  1228. </p>
  1229. <hr>
  1230. <span id="Subroutines"></span><div class="header">
  1231. <p>
  1232. Next: <a href="#Cycles" accesskey="n" rel="next">Cycles</a>, Previous: <a href="#Callers" accesskey="p" rel="prev">Callers</a>, Up: <a href="#Call-Graph" accesskey="u" rel="up">Call Graph</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1233. </div>
  1234. <span id="Lines-for-a-Function_0027s-Subroutines"></span><h4 class="subsection">5.2.3 Lines for a Function&rsquo;s Subroutines</h4>
  1235. <p>A function&rsquo;s entry has a line for each of its subroutines&mdash;in other
  1236. words, a line for each other function that it called. These lines&rsquo;
  1237. fields correspond to the fields of the primary line, but their meanings
  1238. are different because of the difference in context.
  1239. </p>
  1240. <p>For reference, we repeat two lines from the entry for the function
  1241. <code>main</code>, the primary line and a line for a subroutine, together
  1242. with the heading line that shows the names of the fields:
  1243. </p>
  1244. <div class="example">
  1245. <pre class="example">index % time self children called name
  1246. &hellip;
  1247. [2] 100.0 0.00 0.05 1 main [2]
  1248. 0.00 0.05 1/1 report [3]
  1249. </pre></div>
  1250. <p>Here are the meanings of the fields in the subroutine-line for <code>main</code>
  1251. calling <code>report</code>:
  1252. </p>
  1253. <dl compact="compact">
  1254. <dt><code>self</code></dt>
  1255. <dd><p>An estimate of the amount of time spent directly within <code>report</code>
  1256. when <code>report</code> was called from <code>main</code>.
  1257. </p>
  1258. </dd>
  1259. <dt><code>children</code></dt>
  1260. <dd><p>An estimate of the amount of time spent in subroutines of <code>report</code>
  1261. when <code>report</code> was called from <code>main</code>.
  1262. </p>
  1263. <p>The sum of the <code>self</code> and <code>children</code> fields is an estimate
  1264. of the total time spent in calls to <code>report</code> from <code>main</code>.
  1265. </p>
  1266. </dd>
  1267. <dt><code>called</code></dt>
  1268. <dd><p>Two numbers, the number of calls to <code>report</code> from <code>main</code>
  1269. followed by the total number of non-recursive calls to <code>report</code>.
  1270. This ratio is used to determine how much of <code>report</code>&rsquo;s <code>self</code>
  1271. and <code>children</code> time gets credited to <code>main</code>.
  1272. See <a href="#Assumptions">Estimating <code>children</code> Times</a>.
  1273. </p>
  1274. </dd>
  1275. <dt><code>name</code></dt>
  1276. <dd><p>The name of the subroutine of <code>main</code> to which this line applies,
  1277. followed by the subroutine&rsquo;s index number.
  1278. </p>
  1279. <p>If the caller is part of a recursion cycle, the cycle number is
  1280. printed between the name and the index number.
  1281. </p></dd>
  1282. </dl>
  1283. <hr>
  1284. <span id="Cycles"></span><div class="header">
  1285. <p>
  1286. Previous: <a href="#Subroutines" accesskey="p" rel="prev">Subroutines</a>, Up: <a href="#Call-Graph" accesskey="u" rel="up">Call Graph</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1287. </div>
  1288. <span id="How-Mutually-Recursive-Functions-Are-Described"></span><h4 class="subsection">5.2.4 How Mutually Recursive Functions Are Described</h4>
  1289. <span id="index-cycle"></span>
  1290. <span id="index-recursion-cycle"></span>
  1291. <p>The graph may be complicated by the presence of <em>cycles of
  1292. recursion</em> in the call graph. A cycle exists if a function calls
  1293. another function that (directly or indirectly) calls (or appears to
  1294. call) the original function. For example: if <code>a</code> calls <code>b</code>,
  1295. and <code>b</code> calls <code>a</code>, then <code>a</code> and <code>b</code> form a cycle.
  1296. </p>
  1297. <p>Whenever there are call paths both ways between a pair of functions, they
  1298. belong to the same cycle. If <code>a</code> and <code>b</code> call each other and
  1299. <code>b</code> and <code>c</code> call each other, all three make one cycle. Note that
  1300. even if <code>b</code> only calls <code>a</code> if it was not called from <code>a</code>,
  1301. <code>gprof</code> cannot determine this, so <code>a</code> and <code>b</code> are still
  1302. considered a cycle.
  1303. </p>
  1304. <p>The cycles are numbered with consecutive integers. When a function
  1305. belongs to a cycle, each time the function name appears in the call graph
  1306. it is followed by &lsquo;<samp>&lt;cycle <var>number</var>&gt;</samp>&rsquo;.
  1307. </p>
  1308. <p>The reason cycles matter is that they make the time values in the call
  1309. graph paradoxical. The &ldquo;time spent in children&rdquo; of <code>a</code> should
  1310. include the time spent in its subroutine <code>b</code> and in <code>b</code>&rsquo;s
  1311. subroutines&mdash;but one of <code>b</code>&rsquo;s subroutines is <code>a</code>! How much of
  1312. <code>a</code>&rsquo;s time should be included in the children of <code>a</code>, when
  1313. <code>a</code> is indirectly recursive?
  1314. </p>
  1315. <p>The way <code>gprof</code> resolves this paradox is by creating a single entry
  1316. for the cycle as a whole. The primary line of this entry describes the
  1317. total time spent directly in the functions of the cycle. The
  1318. &ldquo;subroutines&rdquo; of the cycle are the individual functions of the cycle, and
  1319. all other functions that were called directly by them. The &ldquo;callers&rdquo; of
  1320. the cycle are the functions, outside the cycle, that called functions in
  1321. the cycle.
  1322. </p>
  1323. <p>Here is an example portion of a call graph which shows a cycle containing
  1324. functions <code>a</code> and <code>b</code>. The cycle was entered by a call to
  1325. <code>a</code> from <code>main</code>; both <code>a</code> and <code>b</code> called <code>c</code>.
  1326. </p>
  1327. <div class="example">
  1328. <pre class="example">index % time self children called name
  1329. ----------------------------------------
  1330. 1.77 0 1/1 main [2]
  1331. [3] 91.71 1.77 0 1+5 &lt;cycle 1 as a whole&gt; [3]
  1332. 1.02 0 3 b &lt;cycle 1&gt; [4]
  1333. 0.75 0 2 a &lt;cycle 1&gt; [5]
  1334. ----------------------------------------
  1335. 3 a &lt;cycle 1&gt; [5]
  1336. [4] 52.85 1.02 0 0 b &lt;cycle 1&gt; [4]
  1337. 2 a &lt;cycle 1&gt; [5]
  1338. 0 0 3/6 c [6]
  1339. ----------------------------------------
  1340. 1.77 0 1/1 main [2]
  1341. 2 b &lt;cycle 1&gt; [4]
  1342. [5] 38.86 0.75 0 1 a &lt;cycle 1&gt; [5]
  1343. 3 b &lt;cycle 1&gt; [4]
  1344. 0 0 3/6 c [6]
  1345. ----------------------------------------
  1346. </pre></div>
  1347. <p>(The entire call graph for this program contains in addition an entry for
  1348. <code>main</code>, which calls <code>a</code>, and an entry for <code>c</code>, with callers
  1349. <code>a</code> and <code>b</code>.)
  1350. </p>
  1351. <div class="example">
  1352. <pre class="example">index % time self children called name
  1353. &lt;spontaneous&gt;
  1354. [1] 100.00 0 1.93 0 start [1]
  1355. 0.16 1.77 1/1 main [2]
  1356. ----------------------------------------
  1357. 0.16 1.77 1/1 start [1]
  1358. [2] 100.00 0.16 1.77 1 main [2]
  1359. 1.77 0 1/1 a &lt;cycle 1&gt; [5]
  1360. ----------------------------------------
  1361. 1.77 0 1/1 main [2]
  1362. [3] 91.71 1.77 0 1+5 &lt;cycle 1 as a whole&gt; [3]
  1363. 1.02 0 3 b &lt;cycle 1&gt; [4]
  1364. 0.75 0 2 a &lt;cycle 1&gt; [5]
  1365. 0 0 6/6 c [6]
  1366. ----------------------------------------
  1367. 3 a &lt;cycle 1&gt; [5]
  1368. [4] 52.85 1.02 0 0 b &lt;cycle 1&gt; [4]
  1369. 2 a &lt;cycle 1&gt; [5]
  1370. 0 0 3/6 c [6]
  1371. ----------------------------------------
  1372. 1.77 0 1/1 main [2]
  1373. 2 b &lt;cycle 1&gt; [4]
  1374. [5] 38.86 0.75 0 1 a &lt;cycle 1&gt; [5]
  1375. 3 b &lt;cycle 1&gt; [4]
  1376. 0 0 3/6 c [6]
  1377. ----------------------------------------
  1378. 0 0 3/6 b &lt;cycle 1&gt; [4]
  1379. 0 0 3/6 a &lt;cycle 1&gt; [5]
  1380. [6] 0.00 0 0 6 c [6]
  1381. ----------------------------------------
  1382. </pre></div>
  1383. <p>The <code>self</code> field of the cycle&rsquo;s primary line is the total time
  1384. spent in all the functions of the cycle. It equals the sum of the
  1385. <code>self</code> fields for the individual functions in the cycle, found
  1386. in the entry in the subroutine lines for these functions.
  1387. </p>
  1388. <p>The <code>children</code> fields of the cycle&rsquo;s primary line and subroutine lines
  1389. count only subroutines outside the cycle. Even though <code>a</code> calls
  1390. <code>b</code>, the time spent in those calls to <code>b</code> is not counted in
  1391. <code>a</code>&rsquo;s <code>children</code> time. Thus, we do not encounter the problem of
  1392. what to do when the time in those calls to <code>b</code> includes indirect
  1393. recursive calls back to <code>a</code>.
  1394. </p>
  1395. <p>The <code>children</code> field of a caller-line in the cycle&rsquo;s entry estimates
  1396. the amount of time spent <em>in the whole cycle</em>, and its other
  1397. subroutines, on the times when that caller called a function in the cycle.
  1398. </p>
  1399. <p>The <code>called</code> field in the primary line for the cycle has two numbers:
  1400. first, the number of times functions in the cycle were called by functions
  1401. outside the cycle; second, the number of times they were called by
  1402. functions in the cycle (including times when a function in the cycle calls
  1403. itself). This is a generalization of the usual split into non-recursive and
  1404. recursive calls.
  1405. </p>
  1406. <p>The <code>called</code> field of a subroutine-line for a cycle member in the
  1407. cycle&rsquo;s entry says how many time that function was called from functions in
  1408. the cycle. The total of all these is the second number in the primary line&rsquo;s
  1409. <code>called</code> field.
  1410. </p>
  1411. <p>In the individual entry for a function in a cycle, the other functions in
  1412. the same cycle can appear as subroutines and as callers. These lines show
  1413. how many times each function in the cycle called or was called from each other
  1414. function in the cycle. The <code>self</code> and <code>children</code> fields in these
  1415. lines are blank because of the difficulty of defining meanings for them
  1416. when recursion is going on.
  1417. </p>
  1418. <hr>
  1419. <span id="Line_002dby_002dline"></span><div class="header">
  1420. <p>
  1421. Next: <a href="#Annotated-Source" accesskey="n" rel="next">Annotated Source</a>, Previous: <a href="#Call-Graph" accesskey="p" rel="prev">Call Graph</a>, Up: <a href="#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1422. </div>
  1423. <span id="Line_002dby_002dline-Profiling"></span><h3 class="section">5.3 Line-by-line Profiling</h3>
  1424. <p><code>gprof</code>&rsquo;s &lsquo;<samp>-l</samp>&rsquo; option causes the program to perform
  1425. <em>line-by-line</em> profiling. In this mode, histogram
  1426. samples are assigned not to functions, but to individual
  1427. lines of source code. This only works with programs compiled with
  1428. older versions of the <code>gcc</code> compiler. Newer versions of <code>gcc</code>
  1429. use a different program - <code>gcov</code> - to display line-by-line
  1430. profiling information.
  1431. </p>
  1432. <p>With the older versions of <code>gcc</code> the program usually has to be
  1433. compiled with a &lsquo;<samp>-g</samp>&rsquo; option, in addition to &lsquo;<samp>-pg</samp>&rsquo;, in order
  1434. to generate debugging symbols for tracking source code lines.
  1435. Note, in much older versions of <code>gcc</code> the program had to be
  1436. compiled with the &lsquo;<samp>-a</samp>&rsquo; command-line option as well.
  1437. </p>
  1438. <p>The flat profile is the most useful output table
  1439. in line-by-line mode.
  1440. The call graph isn&rsquo;t as useful as normal, since
  1441. the current version of <code>gprof</code> does not propagate
  1442. call graph arcs from source code lines to the enclosing function.
  1443. The call graph does, however, show each line of code
  1444. that called each function, along with a count.
  1445. </p>
  1446. <p>Here is a section of <code>gprof</code>&rsquo;s output, without line-by-line profiling.
  1447. Note that <code>ct_init</code> accounted for four histogram hits, and
  1448. 13327 calls to <code>init_block</code>.
  1449. </p>
  1450. <div class="example">
  1451. <pre class="example">Flat profile:
  1452. Each sample counts as 0.01 seconds.
  1453. % cumulative self self total
  1454. time seconds seconds calls us/call us/call name
  1455. 30.77 0.13 0.04 6335 6.31 6.31 ct_init
  1456. Call graph (explanation follows)
  1457. granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
  1458. index % time self children called name
  1459. 0.00 0.00 1/13496 name_too_long
  1460. 0.00 0.00 40/13496 deflate
  1461. 0.00 0.00 128/13496 deflate_fast
  1462. 0.00 0.00 13327/13496 ct_init
  1463. [7] 0.0 0.00 0.00 13496 init_block
  1464. </pre></div>
  1465. <p>Now let&rsquo;s look at some of <code>gprof</code>&rsquo;s output from the same program run,
  1466. this time with line-by-line profiling enabled. Note that <code>ct_init</code>&rsquo;s
  1467. four histogram hits are broken down into four lines of source code&mdash;one hit
  1468. occurred on each of lines 349, 351, 382 and 385. In the call graph,
  1469. note how
  1470. <code>ct_init</code>&rsquo;s 13327 calls to <code>init_block</code> are broken down
  1471. into one call from line 396, 3071 calls from line 384, 3730 calls
  1472. from line 385, and 6525 calls from 387.
  1473. </p>
  1474. <div class="example">
  1475. <pre class="example">Flat profile:
  1476. Each sample counts as 0.01 seconds.
  1477. % cumulative self
  1478. time seconds seconds calls name
  1479. 7.69 0.10 0.01 ct_init (trees.c:349)
  1480. 7.69 0.11 0.01 ct_init (trees.c:351)
  1481. 7.69 0.12 0.01 ct_init (trees.c:382)
  1482. 7.69 0.13 0.01 ct_init (trees.c:385)
  1483. Call graph (explanation follows)
  1484. granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
  1485. % time self children called name
  1486. 0.00 0.00 1/13496 name_too_long (gzip.c:1440)
  1487. 0.00 0.00 1/13496 deflate (deflate.c:763)
  1488. 0.00 0.00 1/13496 ct_init (trees.c:396)
  1489. 0.00 0.00 2/13496 deflate (deflate.c:727)
  1490. 0.00 0.00 4/13496 deflate (deflate.c:686)
  1491. 0.00 0.00 5/13496 deflate (deflate.c:675)
  1492. 0.00 0.00 12/13496 deflate (deflate.c:679)
  1493. 0.00 0.00 16/13496 deflate (deflate.c:730)
  1494. 0.00 0.00 128/13496 deflate_fast (deflate.c:654)
  1495. 0.00 0.00 3071/13496 ct_init (trees.c:384)
  1496. 0.00 0.00 3730/13496 ct_init (trees.c:385)
  1497. 0.00 0.00 6525/13496 ct_init (trees.c:387)
  1498. [6] 0.0 0.00 0.00 13496 init_block (trees.c:408)
  1499. </pre></div>
  1500. <hr>
  1501. <span id="Annotated-Source"></span><div class="header">
  1502. <p>
  1503. Previous: <a href="#Line_002dby_002dline" accesskey="p" rel="prev">Line-by-line</a>, Up: <a href="#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1504. </div>
  1505. <span id="The-Annotated-Source-Listing"></span><h3 class="section">5.4 The Annotated Source Listing</h3>
  1506. <p><code>gprof</code>&rsquo;s &lsquo;<samp>-A</samp>&rsquo; option triggers an annotated source listing,
  1507. which lists the program&rsquo;s source code, each function labeled with the
  1508. number of times it was called. You may also need to specify the
  1509. &lsquo;<samp>-I</samp>&rsquo; option, if <code>gprof</code> can&rsquo;t find the source code files.
  1510. </p>
  1511. <p>With older versions of <code>gcc</code> compiling with &lsquo;<samp>gcc &hellip; -g
  1512. -pg -a</samp>&rsquo; augments your program with basic-block counting code, in
  1513. addition to function counting code. This enables <code>gprof</code> to
  1514. determine how many times each line of code was executed. With newer
  1515. versions of <code>gcc</code> support for displaying basic-block counts is
  1516. provided by the <code>gcov</code> program.
  1517. </p>
  1518. <p>For example, consider the following function, taken from gzip,
  1519. with line numbers added:
  1520. </p>
  1521. <div class="example">
  1522. <pre class="example"> 1 ulg updcrc(s, n)
  1523. 2 uch *s;
  1524. 3 unsigned n;
  1525. 4 {
  1526. 5 register ulg c;
  1527. 6
  1528. 7 static ulg crc = (ulg)0xffffffffL;
  1529. 8
  1530. 9 if (s == NULL) {
  1531. 10 c = 0xffffffffL;
  1532. 11 } else {
  1533. 12 c = crc;
  1534. 13 if (n) do {
  1535. 14 c = crc_32_tab[...];
  1536. 15 } while (--n);
  1537. 16 }
  1538. 17 crc = c;
  1539. 18 return c ^ 0xffffffffL;
  1540. 19 }
  1541. </pre></div>
  1542. <p><code>updcrc</code> has at least five basic-blocks.
  1543. One is the function itself. The
  1544. <code>if</code> statement on line 9 generates two more basic-blocks, one
  1545. for each branch of the <code>if</code>. A fourth basic-block results from
  1546. the <code>if</code> on line 13, and the contents of the <code>do</code> loop form
  1547. the fifth basic-block. The compiler may also generate additional
  1548. basic-blocks to handle various special cases.
  1549. </p>
  1550. <p>A program augmented for basic-block counting can be analyzed with
  1551. &lsquo;<samp>gprof -l -A</samp>&rsquo;.
  1552. The &lsquo;<samp>-x</samp>&rsquo; option is also helpful,
  1553. to ensure that each line of code is labeled at least once.
  1554. Here is <code>updcrc</code>&rsquo;s
  1555. annotated source listing for a sample <code>gzip</code> run:
  1556. </p>
  1557. <div class="example">
  1558. <pre class="example"> ulg updcrc(s, n)
  1559. uch *s;
  1560. unsigned n;
  1561. 2 -&gt;{
  1562. register ulg c;
  1563. static ulg crc = (ulg)0xffffffffL;
  1564. 2 -&gt; if (s == NULL) {
  1565. 1 -&gt; c = 0xffffffffL;
  1566. 1 -&gt; } else {
  1567. 1 -&gt; c = crc;
  1568. 1 -&gt; if (n) do {
  1569. 26312 -&gt; c = crc_32_tab[...];
  1570. 26312,1,26311 -&gt; } while (--n);
  1571. }
  1572. 2 -&gt; crc = c;
  1573. 2 -&gt; return c ^ 0xffffffffL;
  1574. 2 -&gt;}
  1575. </pre></div>
  1576. <p>In this example, the function was called twice, passing once through
  1577. each branch of the <code>if</code> statement. The body of the <code>do</code>
  1578. loop was executed a total of 26312 times. Note how the <code>while</code>
  1579. statement is annotated. It began execution 26312 times, once for
  1580. each iteration through the loop. One of those times (the last time)
  1581. it exited, while it branched back to the beginning of the loop 26311 times.
  1582. </p>
  1583. <hr>
  1584. <span id="Inaccuracy"></span><div class="header">
  1585. <p>
  1586. Next: <a href="#How-do-I_003f" accesskey="n" rel="next">How do I?</a>, Previous: <a href="#Output" accesskey="p" rel="prev">Output</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1587. </div>
  1588. <span id="Inaccuracy-of-gprof-Output"></span><h2 class="chapter">6 Inaccuracy of <code>gprof</code> Output</h2>
  1589. <table class="menu" border="0" cellspacing="0">
  1590. <tr><td align="left" valign="top">&bull; <a href="#Sampling-Error" accesskey="1">Sampling Error</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Statistical margins of error
  1591. </td></tr>
  1592. <tr><td align="left" valign="top">&bull; <a href="#Assumptions" accesskey="2">Assumptions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Estimating children times
  1593. </td></tr>
  1594. </table>
  1595. <hr>
  1596. <span id="Sampling-Error"></span><div class="header">
  1597. <p>
  1598. Next: <a href="#Assumptions" accesskey="n" rel="next">Assumptions</a>, Up: <a href="#Inaccuracy" accesskey="u" rel="up">Inaccuracy</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1599. </div>
  1600. <span id="Statistical-Sampling-Error"></span><h3 class="section">6.1 Statistical Sampling Error</h3>
  1601. <p>The run-time figures that <code>gprof</code> gives you are based on a sampling
  1602. process, so they are subject to statistical inaccuracy. If a function runs
  1603. only a small amount of time, so that on the average the sampling process
  1604. ought to catch that function in the act only once, there is a pretty good
  1605. chance it will actually find that function zero times, or twice.
  1606. </p>
  1607. <p>By contrast, the number-of-calls and basic-block figures are derived
  1608. by counting, not sampling. They are completely accurate and will not
  1609. vary from run to run if your program is deterministic and single
  1610. threaded. In multi-threaded applications, or single threaded
  1611. applications that link with multi-threaded libraries, the counts are
  1612. only deterministic if the counting function is thread-safe. (Note:
  1613. beware that the mcount counting function in glibc is <em>not</em>
  1614. thread-safe). See <a href="#Implementation">Implementation of Profiling</a>.
  1615. </p>
  1616. <p>The <em>sampling period</em> that is printed at the beginning of the flat
  1617. profile says how often samples are taken. The rule of thumb is that a
  1618. run-time figure is accurate if it is considerably bigger than the sampling
  1619. period.
  1620. </p>
  1621. <p>The actual amount of error can be predicted.
  1622. For <var>n</var> samples, the <em>expected</em> error
  1623. is the square-root of <var>n</var>. For example,
  1624. if the sampling period is 0.01 seconds and <code>foo</code>&rsquo;s run-time is 1 second,
  1625. <var>n</var> is 100 samples (1 second/0.01 seconds), sqrt(<var>n</var>) is 10 samples, so
  1626. the expected error in <code>foo</code>&rsquo;s run-time is 0.1 seconds (10*0.01 seconds),
  1627. or ten percent of the observed value.
  1628. Again, if the sampling period is 0.01 seconds and <code>bar</code>&rsquo;s run-time is
  1629. 100 seconds, <var>n</var> is 10000 samples, sqrt(<var>n</var>) is 100 samples, so
  1630. the expected error in <code>bar</code>&rsquo;s run-time is 1 second,
  1631. or one percent of the observed value.
  1632. It is likely to
  1633. vary this much <em>on the average</em> from one profiling run to the next.
  1634. (<em>Sometimes</em> it will vary more.)
  1635. </p>
  1636. <p>This does not mean that a small run-time figure is devoid of information.
  1637. If the program&rsquo;s <em>total</em> run-time is large, a small run-time for one
  1638. function does tell you that that function used an insignificant fraction of
  1639. the whole program&rsquo;s time. Usually this means it is not worth optimizing.
  1640. </p>
  1641. <p>One way to get more accuracy is to give your program more (but similar)
  1642. input data so it will take longer. Another way is to combine the data from
  1643. several runs, using the &lsquo;<samp>-s</samp>&rsquo; option of <code>gprof</code>. Here is how:
  1644. </p>
  1645. <ol>
  1646. <li> Run your program once.
  1647. </li><li> Issue the command &lsquo;<samp>mv gmon.out gmon.sum</samp>&rsquo;.
  1648. </li><li> Run your program again, the same as before.
  1649. </li><li> Merge the new data in <samp>gmon.out</samp> into <samp>gmon.sum</samp> with this command:
  1650. <div class="example">
  1651. <pre class="example">gprof -s <var>executable-file</var> gmon.out gmon.sum
  1652. </pre></div>
  1653. </li><li> Repeat the last two steps as often as you wish.
  1654. </li><li> Analyze the cumulative data using this command:
  1655. <div class="example">
  1656. <pre class="example">gprof <var>executable-file</var> gmon.sum &gt; <var>output-file</var>
  1657. </pre></div>
  1658. </li></ol>
  1659. <hr>
  1660. <span id="Assumptions"></span><div class="header">
  1661. <p>
  1662. Previous: <a href="#Sampling-Error" accesskey="p" rel="prev">Sampling Error</a>, Up: <a href="#Inaccuracy" accesskey="u" rel="up">Inaccuracy</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1663. </div>
  1664. <span id="Estimating-children-Times"></span><h3 class="section">6.2 Estimating <code>children</code> Times</h3>
  1665. <p>Some of the figures in the call graph are estimates&mdash;for example, the
  1666. <code>children</code> time values and all the time figures in caller and
  1667. subroutine lines.
  1668. </p>
  1669. <p>There is no direct information about these measurements in the profile
  1670. data itself. Instead, <code>gprof</code> estimates them by making an assumption
  1671. about your program that might or might not be true.
  1672. </p>
  1673. <p>The assumption made is that the average time spent in each call to any
  1674. function <code>foo</code> is not correlated with who called <code>foo</code>. If
  1675. <code>foo</code> used 5 seconds in all, and 2/5 of the calls to <code>foo</code> came
  1676. from <code>a</code>, then <code>foo</code> contributes 2 seconds to <code>a</code>&rsquo;s
  1677. <code>children</code> time, by assumption.
  1678. </p>
  1679. <p>This assumption is usually true enough, but for some programs it is far
  1680. from true. Suppose that <code>foo</code> returns very quickly when its argument
  1681. is zero; suppose that <code>a</code> always passes zero as an argument, while
  1682. other callers of <code>foo</code> pass other arguments. In this program, all the
  1683. time spent in <code>foo</code> is in the calls from callers other than <code>a</code>.
  1684. But <code>gprof</code> has no way of knowing this; it will blindly and
  1685. incorrectly charge 2 seconds of time in <code>foo</code> to the children of
  1686. <code>a</code>.
  1687. </p>
  1688. <p>We hope some day to put more complete data into <samp>gmon.out</samp>, so that
  1689. this assumption is no longer needed, if we can figure out how. For the
  1690. novice, the estimated figures are usually more useful than misleading.
  1691. </p>
  1692. <hr>
  1693. <span id="How-do-I_003f"></span><div class="header">
  1694. <p>
  1695. Next: <a href="#Incompatibilities" accesskey="n" rel="next">Incompatibilities</a>, Previous: <a href="#Inaccuracy" accesskey="p" rel="prev">Inaccuracy</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1696. </div>
  1697. <span id="Answers-to-Common-Questions"></span><h2 class="chapter">7 Answers to Common Questions</h2>
  1698. <dl compact="compact">
  1699. <dt>How can I get more exact information about hot spots in my program?</dt>
  1700. <dd>
  1701. <p>Looking at the per-line call counts only tells part of the story.
  1702. Because <code>gprof</code> can only report call times and counts by function,
  1703. the best way to get finer-grained information on where the program
  1704. is spending its time is to re-factor large functions into sequences
  1705. of calls to smaller ones. Beware however that this can introduce
  1706. artificial hot spots since compiling with &lsquo;<samp>-pg</samp>&rsquo; adds a significant
  1707. overhead to function calls. An alternative solution is to use a
  1708. non-intrusive profiler, e.g. oprofile.
  1709. </p>
  1710. </dd>
  1711. <dt>How do I find which lines in my program were executed the most times?</dt>
  1712. <dd>
  1713. <p>Use the <code>gcov</code> program.
  1714. </p>
  1715. </dd>
  1716. <dt>How do I find which lines in my program called a particular function?</dt>
  1717. <dd>
  1718. <p>Use &lsquo;<samp>gprof -l</samp>&rsquo; and lookup the function in the call graph.
  1719. The callers will be broken down by function and line number.
  1720. </p>
  1721. </dd>
  1722. <dt>How do I analyze a program that runs for less than a second?</dt>
  1723. <dd>
  1724. <p>Try using a shell script like this one:
  1725. </p>
  1726. <div class="example">
  1727. <pre class="example">for i in `seq 1 100`; do
  1728. fastprog
  1729. mv gmon.out gmon.out.$i
  1730. done
  1731. gprof -s fastprog gmon.out.*
  1732. gprof fastprog gmon.sum
  1733. </pre></div>
  1734. <p>If your program is completely deterministic, all the call counts
  1735. will be simple multiples of 100 (i.e., a function called once in
  1736. each run will appear with a call count of 100).
  1737. </p>
  1738. </dd>
  1739. </dl>
  1740. <hr>
  1741. <span id="Incompatibilities"></span><div class="header">
  1742. <p>
  1743. Next: <a href="#Details" accesskey="n" rel="next">Details</a>, Previous: <a href="#How-do-I_003f" accesskey="p" rel="prev">How do I?</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1744. </div>
  1745. <span id="Incompatibilities-with-Unix-gprof"></span><h2 class="chapter">8 Incompatibilities with Unix <code>gprof</code></h2>
  1746. <p><small>GNU</small> <code>gprof</code> and Berkeley Unix <code>gprof</code> use the same data
  1747. file <samp>gmon.out</samp>, and provide essentially the same information. But
  1748. there are a few differences.
  1749. </p>
  1750. <ul>
  1751. <li> <small>GNU</small> <code>gprof</code> uses a new, generalized file format with support
  1752. for basic-block execution counts and non-realtime histograms. A magic
  1753. cookie and version number allows <code>gprof</code> to easily identify
  1754. new style files. Old BSD-style files can still be read.
  1755. See <a href="#File-Format">Profiling Data File Format</a>.
  1756. </li><li> For a recursive function, Unix <code>gprof</code> lists the function as a
  1757. parent and as a child, with a <code>calls</code> field that lists the number
  1758. of recursive calls. <small>GNU</small> <code>gprof</code> omits these lines and puts
  1759. the number of recursive calls in the primary line.
  1760. </li><li> When a function is suppressed from the call graph with &lsquo;<samp>-e</samp>&rsquo;, <small>GNU</small>
  1761. <code>gprof</code> still lists it as a subroutine of functions that call it.
  1762. </li><li> <small>GNU</small> <code>gprof</code> accepts the &lsquo;<samp>-k</samp>&rsquo; with its argument
  1763. in the form &lsquo;<samp>from/to</samp>&rsquo;, instead of &lsquo;<samp>from to</samp>&rsquo;.
  1764. </li><li> In the annotated source listing,
  1765. if there are multiple basic blocks on the same line,
  1766. <small>GNU</small> <code>gprof</code> prints all of their counts, separated by commas.
  1767. </li><li> The blurbs, field widths, and output formats are different. <small>GNU</small>
  1768. <code>gprof</code> prints blurbs after the tables, so that you can see the
  1769. tables without skipping the blurbs.
  1770. </li></ul>
  1771. <hr>
  1772. <span id="Details"></span><div class="header">
  1773. <p>
  1774. Next: <a href="#GNU-Free-Documentation-License" accesskey="n" rel="next">GNU Free Documentation License</a>, Previous: <a href="#Incompatibilities" accesskey="p" rel="prev">Incompatibilities</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1775. </div>
  1776. <span id="Details-of-Profiling"></span><h2 class="chapter">9 Details of Profiling</h2>
  1777. <table class="menu" border="0" cellspacing="0">
  1778. <tr><td align="left" valign="top">&bull; <a href="#Implementation" accesskey="1">Implementation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How a program collects profiling information
  1779. </td></tr>
  1780. <tr><td align="left" valign="top">&bull; <a href="#File-Format" accesskey="2">File Format</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Format of &lsquo;<samp>gmon.out</samp>&rsquo; files
  1781. </td></tr>
  1782. <tr><td align="left" valign="top">&bull; <a href="#Internals" accesskey="3">Internals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"><code>gprof</code>&rsquo;s internal operation
  1783. </td></tr>
  1784. <tr><td align="left" valign="top">&bull; <a href="#Debugging" accesskey="4">Debugging</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Using <code>gprof</code>&rsquo;s &lsquo;<samp>-d</samp>&rsquo; option
  1785. </td></tr>
  1786. </table>
  1787. <hr>
  1788. <span id="Implementation"></span><div class="header">
  1789. <p>
  1790. Next: <a href="#File-Format" accesskey="n" rel="next">File Format</a>, Up: <a href="#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1791. </div>
  1792. <span id="Implementation-of-Profiling"></span><h3 class="section">9.1 Implementation of Profiling</h3>
  1793. <p>Profiling works by changing how every function in your program is compiled
  1794. so that when it is called, it will stash away some information about where
  1795. it was called from. From this, the profiler can figure out what function
  1796. called it, and can count how many times it was called. This change is made
  1797. by the compiler when your program is compiled with the &lsquo;<samp>-pg</samp>&rsquo; option,
  1798. which causes every function to call <code>mcount</code>
  1799. (or <code>_mcount</code>, or <code>__mcount</code>, depending on the OS and compiler)
  1800. as one of its first operations.
  1801. </p>
  1802. <p>The <code>mcount</code> routine, included in the profiling library,
  1803. is responsible for recording in an in-memory call graph table
  1804. both its parent routine (the child) and its parent&rsquo;s parent. This is
  1805. typically done by examining the stack frame to find both
  1806. the address of the child, and the return address in the original parent.
  1807. Since this is a very machine-dependent operation, <code>mcount</code>
  1808. itself is typically a short assembly-language stub routine
  1809. that extracts the required
  1810. information, and then calls <code>__mcount_internal</code>
  1811. (a normal C function) with two arguments&mdash;<code>frompc</code> and <code>selfpc</code>.
  1812. <code>__mcount_internal</code> is responsible for maintaining
  1813. the in-memory call graph, which records <code>frompc</code>, <code>selfpc</code>,
  1814. and the number of times each of these call arcs was traversed.
  1815. </p>
  1816. <p>GCC Version 2 provides a magical function (<code>__builtin_return_address</code>),
  1817. which allows a generic <code>mcount</code> function to extract the
  1818. required information from the stack frame. However, on some
  1819. architectures, most notably the SPARC, using this builtin can be
  1820. very computationally expensive, and an assembly language version
  1821. of <code>mcount</code> is used for performance reasons.
  1822. </p>
  1823. <p>Number-of-calls information for library routines is collected by using a
  1824. special version of the C library. The programs in it are the same as in
  1825. the usual C library, but they were compiled with &lsquo;<samp>-pg</samp>&rsquo;. If you
  1826. link your program with &lsquo;<samp>gcc &hellip; -pg</samp>&rsquo;, it automatically uses the
  1827. profiling version of the library.
  1828. </p>
  1829. <p>Profiling also involves watching your program as it runs, and keeping a
  1830. histogram of where the program counter happens to be every now and then.
  1831. Typically the program counter is looked at around 100 times per second of
  1832. run time, but the exact frequency may vary from system to system.
  1833. </p>
  1834. <p>This is done is one of two ways. Most UNIX-like operating systems
  1835. provide a <code>profil()</code> system call, which registers a memory
  1836. array with the kernel, along with a scale
  1837. factor that determines how the program&rsquo;s address space maps
  1838. into the array.
  1839. Typical scaling values cause every 2 to 8 bytes of address space
  1840. to map into a single array slot.
  1841. On every tick of the system clock
  1842. (assuming the profiled program is running), the value of the
  1843. program counter is examined and the corresponding slot in
  1844. the memory array is incremented. Since this is done in the kernel,
  1845. which had to interrupt the process anyway to handle the clock
  1846. interrupt, very little additional system overhead is required.
  1847. </p>
  1848. <p>However, some operating systems, most notably Linux 2.0 (and earlier),
  1849. do not provide a <code>profil()</code> system call. On such a system,
  1850. arrangements are made for the kernel to periodically deliver
  1851. a signal to the process (typically via <code>setitimer()</code>),
  1852. which then performs the same operation of examining the
  1853. program counter and incrementing a slot in the memory array.
  1854. Since this method requires a signal to be delivered to
  1855. user space every time a sample is taken, it uses considerably
  1856. more overhead than kernel-based profiling. Also, due to the
  1857. added delay required to deliver the signal, this method is
  1858. less accurate as well.
  1859. </p>
  1860. <p>A special startup routine allocates memory for the histogram and
  1861. either calls <code>profil()</code> or sets up
  1862. a clock signal handler.
  1863. This routine (<code>monstartup</code>) can be invoked in several ways.
  1864. On Linux systems, a special profiling startup file <code>gcrt0.o</code>,
  1865. which invokes <code>monstartup</code> before <code>main</code>,
  1866. is used instead of the default <code>crt0.o</code>.
  1867. Use of this special startup file is one of the effects
  1868. of using &lsquo;<samp>gcc &hellip; -pg</samp>&rsquo; to link.
  1869. On SPARC systems, no special startup files are used.
  1870. Rather, the <code>mcount</code> routine, when it is invoked for
  1871. the first time (typically when <code>main</code> is called),
  1872. calls <code>monstartup</code>.
  1873. </p>
  1874. <p>If the compiler&rsquo;s &lsquo;<samp>-a</samp>&rsquo; option was used, basic-block counting
  1875. is also enabled. Each object file is then compiled with a static array
  1876. of counts, initially zero.
  1877. In the executable code, every time a new basic-block begins
  1878. (i.e., when an <code>if</code> statement appears), an extra instruction
  1879. is inserted to increment the corresponding count in the array.
  1880. At compile time, a paired array was constructed that recorded
  1881. the starting address of each basic-block. Taken together,
  1882. the two arrays record the starting address of every basic-block,
  1883. along with the number of times it was executed.
  1884. </p>
  1885. <p>The profiling library also includes a function (<code>mcleanup</code>) which is
  1886. typically registered using <code>atexit()</code> to be called as the
  1887. program exits, and is responsible for writing the file <samp>gmon.out</samp>.
  1888. Profiling is turned off, various headers are output, and the histogram
  1889. is written, followed by the call-graph arcs and the basic-block counts.
  1890. </p>
  1891. <p>The output from <code>gprof</code> gives no indication of parts of your program that
  1892. are limited by I/O or swapping bandwidth. This is because samples of the
  1893. program counter are taken at fixed intervals of the program&rsquo;s run time.
  1894. Therefore, the
  1895. time measurements in <code>gprof</code> output say nothing about time that your
  1896. program was not running. For example, a part of the program that creates
  1897. so much data that it cannot all fit in physical memory at once may run very
  1898. slowly due to thrashing, but <code>gprof</code> will say it uses little time. On
  1899. the other hand, sampling by run time has the advantage that the amount of
  1900. load due to other users won&rsquo;t directly affect the output you get.
  1901. </p>
  1902. <hr>
  1903. <span id="File-Format"></span><div class="header">
  1904. <p>
  1905. Next: <a href="#Internals" accesskey="n" rel="next">Internals</a>, Previous: <a href="#Implementation" accesskey="p" rel="prev">Implementation</a>, Up: <a href="#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1906. </div>
  1907. <span id="Profiling-Data-File-Format"></span><h3 class="section">9.2 Profiling Data File Format</h3>
  1908. <p>The old BSD-derived file format used for profile data does not contain a
  1909. magic cookie that allows one to check whether a data file really is a
  1910. <code>gprof</code> file. Furthermore, it does not provide a version number, thus
  1911. rendering changes to the file format almost impossible. <small>GNU</small> <code>gprof</code>
  1912. uses a new file format that provides these features. For backward
  1913. compatibility, <small>GNU</small> <code>gprof</code> continues to support the old BSD-derived
  1914. format, but not all features are supported with it. For example,
  1915. basic-block execution counts cannot be accommodated by the old file
  1916. format.
  1917. </p>
  1918. <p>The new file format is defined in header file <samp>gmon_out.h</samp>. It
  1919. consists of a header containing the magic cookie and a version number,
  1920. as well as some spare bytes available for future extensions. All data
  1921. in a profile data file is in the native format of the target for which
  1922. the profile was collected. <small>GNU</small> <code>gprof</code> adapts automatically
  1923. to the byte-order in use.
  1924. </p>
  1925. <p>In the new file format, the header is followed by a sequence of
  1926. records. Currently, there are three different record types: histogram
  1927. records, call-graph arc records, and basic-block execution count
  1928. records. Each file can contain any number of each record type. When
  1929. reading a file, <small>GNU</small> <code>gprof</code> will ensure records of the same type are
  1930. compatible with each other and compute the union of all records. For
  1931. example, for basic-block execution counts, the union is simply the sum
  1932. of all execution counts for each basic-block.
  1933. </p>
  1934. <span id="Histogram-Records"></span><h4 class="subsection">9.2.1 Histogram Records</h4>
  1935. <p>Histogram records consist of a header that is followed by an array of
  1936. bins. The header contains the text-segment range that the histogram
  1937. spans, the size of the histogram in bytes (unlike in the old BSD
  1938. format, this does not include the size of the header), the rate of the
  1939. profiling clock, and the physical dimension that the bin counts
  1940. represent after being scaled by the profiling clock rate. The
  1941. physical dimension is specified in two parts: a long name of up to 15
  1942. characters and a single character abbreviation. For example, a
  1943. histogram representing real-time would specify the long name as
  1944. &ldquo;seconds&rdquo; and the abbreviation as &ldquo;s&rdquo;. This feature is useful for
  1945. architectures that support performance monitor hardware (which,
  1946. fortunately, is becoming increasingly common). For example, under DEC
  1947. OSF/1, the &ldquo;uprofile&rdquo; command can be used to produce a histogram of,
  1948. say, instruction cache misses. In this case, the dimension in the
  1949. histogram header could be set to &ldquo;i-cache misses&rdquo; and the abbreviation
  1950. could be set to &ldquo;1&rdquo; (because it is simply a count, not a physical
  1951. dimension). Also, the profiling rate would have to be set to 1 in
  1952. this case.
  1953. </p>
  1954. <p>Histogram bins are 16-bit numbers and each bin represent an equal
  1955. amount of text-space. For example, if the text-segment is one
  1956. thousand bytes long and if there are ten bins in the histogram, each
  1957. bin represents one hundred bytes.
  1958. </p>
  1959. <span id="Call_002dGraph-Records"></span><h4 class="subsection">9.2.2 Call-Graph Records</h4>
  1960. <p>Call-graph records have a format that is identical to the one used in
  1961. the BSD-derived file format. It consists of an arc in the call graph
  1962. and a count indicating the number of times the arc was traversed
  1963. during program execution. Arcs are specified by a pair of addresses:
  1964. the first must be within caller&rsquo;s function and the second must be
  1965. within the callee&rsquo;s function. When performing profiling at the
  1966. function level, these addresses can point anywhere within the
  1967. respective function. However, when profiling at the line-level, it is
  1968. better if the addresses are as close to the call-site/entry-point as
  1969. possible. This will ensure that the line-level call-graph is able to
  1970. identify exactly which line of source code performed calls to a
  1971. function.
  1972. </p>
  1973. <span id="Basic_002dBlock-Execution-Count-Records"></span><h4 class="subsection">9.2.3 Basic-Block Execution Count Records</h4>
  1974. <p>Basic-block execution count records consist of a header followed by a
  1975. sequence of address/count pairs. The header simply specifies the
  1976. length of the sequence. In an address/count pair, the address
  1977. identifies a basic-block and the count specifies the number of times
  1978. that basic-block was executed. Any address within the basic-address can
  1979. be used.
  1980. </p>
  1981. <hr>
  1982. <span id="Internals"></span><div class="header">
  1983. <p>
  1984. Next: <a href="#Debugging" accesskey="n" rel="next">Debugging</a>, Previous: <a href="#File-Format" accesskey="p" rel="prev">File Format</a>, Up: <a href="#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  1985. </div>
  1986. <span id="gprof_0027s-Internal-Operation"></span><h3 class="section">9.3 <code>gprof</code>&rsquo;s Internal Operation</h3>
  1987. <p>Like most programs, <code>gprof</code> begins by processing its options.
  1988. During this stage, it may building its symspec list
  1989. (<code>sym_ids.c:sym_id_add</code>), if
  1990. options are specified which use symspecs.
  1991. <code>gprof</code> maintains a single linked list of symspecs,
  1992. which will eventually get turned into 12 symbol tables,
  1993. organized into six include/exclude pairs&mdash;one
  1994. pair each for the flat profile (INCL_FLAT/EXCL_FLAT),
  1995. the call graph arcs (INCL_ARCS/EXCL_ARCS),
  1996. printing in the call graph (INCL_GRAPH/EXCL_GRAPH),
  1997. timing propagation in the call graph (INCL_TIME/EXCL_TIME),
  1998. the annotated source listing (INCL_ANNO/EXCL_ANNO),
  1999. and the execution count listing (INCL_EXEC/EXCL_EXEC).
  2000. </p>
  2001. <p>After option processing, <code>gprof</code> finishes
  2002. building the symspec list by adding all the symspecs in
  2003. <code>default_excluded_list</code> to the exclude lists
  2004. EXCL_TIME and EXCL_GRAPH, and if line-by-line profiling is specified,
  2005. EXCL_FLAT as well.
  2006. These default excludes are not added to EXCL_ANNO, EXCL_ARCS, and EXCL_EXEC.
  2007. </p>
  2008. <p>Next, the BFD library is called to open the object file,
  2009. verify that it is an object file,
  2010. and read its symbol table (<code>core.c:core_init</code>),
  2011. using <code>bfd_canonicalize_symtab</code> after mallocing
  2012. an appropriately sized array of symbols. At this point,
  2013. function mappings are read (if the &lsquo;<samp>--file-ordering</samp>&rsquo; option
  2014. has been specified), and the core text space is read into
  2015. memory (if the &lsquo;<samp>-c</samp>&rsquo; option was given).
  2016. </p>
  2017. <p><code>gprof</code>&rsquo;s own symbol table, an array of Sym structures,
  2018. is now built.
  2019. This is done in one of two ways, by one of two routines, depending
  2020. on whether line-by-line profiling (&lsquo;<samp>-l</samp>&rsquo; option) has been
  2021. enabled.
  2022. For normal profiling, the BFD canonical symbol table is scanned.
  2023. For line-by-line profiling, every
  2024. text space address is examined, and a new symbol table entry
  2025. gets created every time the line number changes.
  2026. In either case, two passes are made through the symbol
  2027. table&mdash;one to count the size of the symbol table required,
  2028. and the other to actually read the symbols. In between the
  2029. two passes, a single array of type <code>Sym</code> is created of
  2030. the appropriate length.
  2031. Finally, <code>symtab.c:symtab_finalize</code>
  2032. is called to sort the symbol table and remove duplicate entries
  2033. (entries with the same memory address).
  2034. </p>
  2035. <p>The symbol table must be a contiguous array for two reasons.
  2036. First, the <code>qsort</code> library function (which sorts an array)
  2037. will be used to sort the symbol table.
  2038. Also, the symbol lookup routine (<code>symtab.c:sym_lookup</code>),
  2039. which finds symbols
  2040. based on memory address, uses a binary search algorithm
  2041. which requires the symbol table to be a sorted array.
  2042. Function symbols are indicated with an <code>is_func</code> flag.
  2043. Line number symbols have no special flags set.
  2044. Additionally, a symbol can have an <code>is_static</code> flag
  2045. to indicate that it is a local symbol.
  2046. </p>
  2047. <p>With the symbol table read, the symspecs can now be translated
  2048. into Syms (<code>sym_ids.c:sym_id_parse</code>). Remember that a single
  2049. symspec can match multiple symbols.
  2050. An array of symbol tables
  2051. (<code>syms</code>) is created, each entry of which is a symbol table
  2052. of Syms to be included or excluded from a particular listing.
  2053. The master symbol table and the symspecs are examined by nested
  2054. loops, and every symbol that matches a symspec is inserted
  2055. into the appropriate syms table. This is done twice, once to
  2056. count the size of each required symbol table, and again to build
  2057. the tables, which have been malloced between passes.
  2058. From now on, to determine whether a symbol is on an include
  2059. or exclude symspec list, <code>gprof</code> simply uses its
  2060. standard symbol lookup routine on the appropriate table
  2061. in the <code>syms</code> array.
  2062. </p>
  2063. <p>Now the profile data file(s) themselves are read
  2064. (<code>gmon_io.c:gmon_out_read</code>),
  2065. first by checking for a new-style &lsquo;<samp>gmon.out</samp>&rsquo; header,
  2066. then assuming this is an old-style BSD &lsquo;<samp>gmon.out</samp>&rsquo;
  2067. if the magic number test failed.
  2068. </p>
  2069. <p>New-style histogram records are read by <code>hist.c:hist_read_rec</code>.
  2070. For the first histogram record, allocate a memory array to hold
  2071. all the bins, and read them in.
  2072. When multiple profile data files (or files with multiple histogram
  2073. records) are read, the memory ranges of each pair of histogram records
  2074. must be either equal, or non-overlapping. For each pair of histogram
  2075. records, the resolution (memory region size divided by the number of
  2076. bins) must be the same. The time unit must be the same for all
  2077. histogram records. If the above containts are met, all histograms
  2078. for the same memory range are merged.
  2079. </p>
  2080. <p>As each call graph record is read (<code>call_graph.c:cg_read_rec</code>),
  2081. the parent and child addresses
  2082. are matched to symbol table entries, and a call graph arc is
  2083. created by <code>cg_arcs.c:arc_add</code>, unless the arc fails a symspec
  2084. check against INCL_ARCS/EXCL_ARCS. As each arc is added,
  2085. a linked list is maintained of the parent&rsquo;s child arcs, and of the child&rsquo;s
  2086. parent arcs.
  2087. Both the child&rsquo;s call count and the arc&rsquo;s call count are
  2088. incremented by the record&rsquo;s call count.
  2089. </p>
  2090. <p>Basic-block records are read (<code>basic_blocks.c:bb_read_rec</code>),
  2091. but only if line-by-line profiling has been selected.
  2092. Each basic-block address is matched to a corresponding line
  2093. symbol in the symbol table, and an entry made in the symbol&rsquo;s
  2094. bb_addr and bb_calls arrays. Again, if multiple basic-block
  2095. records are present for the same address, the call counts
  2096. are cumulative.
  2097. </p>
  2098. <p>A gmon.sum file is dumped, if requested (<code>gmon_io.c:gmon_out_write</code>).
  2099. </p>
  2100. <p>If histograms were present in the data files, assign them to symbols
  2101. (<code>hist.c:hist_assign_samples</code>) by iterating over all the sample
  2102. bins and assigning them to symbols. Since the symbol table
  2103. is sorted in order of ascending memory addresses, we can
  2104. simple follow along in the symbol table as we make our pass
  2105. over the sample bins.
  2106. This step includes a symspec check against INCL_FLAT/EXCL_FLAT.
  2107. Depending on the histogram
  2108. scale factor, a sample bin may span multiple symbols,
  2109. in which case a fraction of the sample count is allocated
  2110. to each symbol, proportional to the degree of overlap.
  2111. This effect is rare for normal profiling, but overlaps
  2112. are more common during line-by-line profiling, and can
  2113. cause each of two adjacent lines to be credited with half
  2114. a hit, for example.
  2115. </p>
  2116. <p>If call graph data is present, <code>cg_arcs.c:cg_assemble</code> is called.
  2117. First, if &lsquo;<samp>-c</samp>&rsquo; was specified, a machine-dependent
  2118. routine (<code>find_call</code>) scans through each symbol&rsquo;s machine code,
  2119. looking for subroutine call instructions, and adding them
  2120. to the call graph with a zero call count.
  2121. A topological sort is performed by depth-first numbering
  2122. all the symbols (<code>cg_dfn.c:cg_dfn</code>), so that
  2123. children are always numbered less than their parents,
  2124. then making a array of pointers into the symbol table and sorting it into
  2125. numerical order, which is reverse topological
  2126. order (children appear before parents).
  2127. Cycles are also detected at this point, all members
  2128. of which are assigned the same topological number.
  2129. Two passes are now made through this sorted array of symbol pointers.
  2130. The first pass, from end to beginning (parents to children),
  2131. computes the fraction of child time to propagate to each parent
  2132. and a print flag.
  2133. The print flag reflects symspec handling of INCL_GRAPH/EXCL_GRAPH,
  2134. with a parent&rsquo;s include or exclude (print or no print) property
  2135. being propagated to its children, unless they themselves explicitly appear
  2136. in INCL_GRAPH or EXCL_GRAPH.
  2137. A second pass, from beginning to end (children to parents) actually
  2138. propagates the timings along the call graph, subject
  2139. to a check against INCL_TIME/EXCL_TIME.
  2140. With the print flag, fractions, and timings now stored in the symbol
  2141. structures, the topological sort array is now discarded, and a
  2142. new array of pointers is assembled, this time sorted by propagated time.
  2143. </p>
  2144. <p>Finally, print the various outputs the user requested, which is now fairly
  2145. straightforward. The call graph (<code>cg_print.c:cg_print</code>) and
  2146. flat profile (<code>hist.c:hist_print</code>) are regurgitations of values
  2147. already computed. The annotated source listing
  2148. (<code>basic_blocks.c:print_annotated_source</code>) uses basic-block
  2149. information, if present, to label each line of code with call counts,
  2150. otherwise only the function call counts are presented.
  2151. </p>
  2152. <p>The function ordering code is marginally well documented
  2153. in the source code itself (<code>cg_print.c</code>). Basically,
  2154. the functions with the most use and the most parents are
  2155. placed first, followed by other functions with the most use,
  2156. followed by lower use functions, followed by unused functions
  2157. at the end.
  2158. </p>
  2159. <hr>
  2160. <span id="Debugging"></span><div class="header">
  2161. <p>
  2162. Previous: <a href="#Internals" accesskey="p" rel="prev">Internals</a>, Up: <a href="#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  2163. </div>
  2164. <span id="Debugging-gprof"></span><h3 class="section">9.4 Debugging <code>gprof</code></h3>
  2165. <p>If <code>gprof</code> was compiled with debugging enabled,
  2166. the &lsquo;<samp>-d</samp>&rsquo; option triggers debugging output
  2167. (to stdout) which can be helpful in understanding its operation.
  2168. The debugging number specified is interpreted as a sum of the following
  2169. options:
  2170. </p>
  2171. <dl compact="compact">
  2172. <dt>2 - Topological sort</dt>
  2173. <dd><p>Monitor depth-first numbering of symbols during call graph analysis
  2174. </p></dd>
  2175. <dt>4 - Cycles</dt>
  2176. <dd><p>Shows symbols as they are identified as cycle heads
  2177. </p></dd>
  2178. <dt>16 - Tallying</dt>
  2179. <dd><p>As the call graph arcs are read, show each arc and how
  2180. the total calls to each function are tallied
  2181. </p></dd>
  2182. <dt>32 - Call graph arc sorting</dt>
  2183. <dd><p>Details sorting individual parents/children within each call graph entry
  2184. </p></dd>
  2185. <dt>64 - Reading histogram and call graph records</dt>
  2186. <dd><p>Shows address ranges of histograms as they are read, and each
  2187. call graph arc
  2188. </p></dd>
  2189. <dt>128 - Symbol table</dt>
  2190. <dd><p>Reading, classifying, and sorting the symbol table from the object file.
  2191. For line-by-line profiling (&lsquo;<samp>-l</samp>&rsquo; option), also shows line numbers
  2192. being assigned to memory addresses.
  2193. </p></dd>
  2194. <dt>256 - Static call graph</dt>
  2195. <dd><p>Trace operation of &lsquo;<samp>-c</samp>&rsquo; option
  2196. </p></dd>
  2197. <dt>512 - Symbol table and arc table lookups</dt>
  2198. <dd><p>Detail operation of lookup routines
  2199. </p></dd>
  2200. <dt>1024 - Call graph propagation</dt>
  2201. <dd><p>Shows how function times are propagated along the call graph
  2202. </p></dd>
  2203. <dt>2048 - Basic-blocks</dt>
  2204. <dd><p>Shows basic-block records as they are read from profile data
  2205. (only meaningful with &lsquo;<samp>-l</samp>&rsquo; option)
  2206. </p></dd>
  2207. <dt>4096 - Symspecs</dt>
  2208. <dd><p>Shows symspec-to-symbol pattern matching operation
  2209. </p></dd>
  2210. <dt>8192 - Annotate source</dt>
  2211. <dd><p>Tracks operation of &lsquo;<samp>-A</samp>&rsquo; option
  2212. </p></dd>
  2213. </dl>
  2214. <hr>
  2215. <span id="GNU-Free-Documentation-License"></span><div class="header">
  2216. <p>
  2217. Previous: <a href="#Details" accesskey="p" rel="prev">Details</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  2218. </div>
  2219. <span id="GNU-Free-Documentation-License-1"></span><h2 class="appendix">Appendix A GNU Free Documentation License</h2>
  2220. <div align="center">Version 1.3, 3 November 2008
  2221. </div>
  2222. <div class="display">
  2223. <pre class="display">Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
  2224. <a href="http://fsf.org/">http://fsf.org/</a>
  2225. Everyone is permitted to copy and distribute verbatim copies
  2226. of this license document, but changing it is not allowed.
  2227. </pre></div>
  2228. <ol start="0">
  2229. <li> PREAMBLE
  2230. <p>The purpose of this License is to make a manual, textbook, or other
  2231. functional and useful document <em>free</em> in the sense of freedom: to
  2232. assure everyone the effective freedom to copy and redistribute it,
  2233. with or without modifying it, either commercially or noncommercially.
  2234. Secondarily, this License preserves for the author and publisher a way
  2235. to get credit for their work, while not being considered responsible
  2236. for modifications made by others.
  2237. </p>
  2238. <p>This License is a kind of &ldquo;copyleft&rdquo;, which means that derivative
  2239. works of the document must themselves be free in the same sense. It
  2240. complements the GNU General Public License, which is a copyleft
  2241. license designed for free software.
  2242. </p>
  2243. <p>We have designed this License in order to use it for manuals for free
  2244. software, because free software needs free documentation: a free
  2245. program should come with manuals providing the same freedoms that the
  2246. software does. But this License is not limited to software manuals;
  2247. it can be used for any textual work, regardless of subject matter or
  2248. whether it is published as a printed book. We recommend this License
  2249. principally for works whose purpose is instruction or reference.
  2250. </p>
  2251. </li><li> APPLICABILITY AND DEFINITIONS
  2252. <p>This License applies to any manual or other work, in any medium, that
  2253. contains a notice placed by the copyright holder saying it can be
  2254. distributed under the terms of this License. Such a notice grants a
  2255. world-wide, royalty-free license, unlimited in duration, to use that
  2256. work under the conditions stated herein. The &ldquo;Document&rdquo;, below,
  2257. refers to any such manual or work. Any member of the public is a
  2258. licensee, and is addressed as &ldquo;you&rdquo;. You accept the license if you
  2259. copy, modify or distribute the work in a way requiring permission
  2260. under copyright law.
  2261. </p>
  2262. <p>A &ldquo;Modified Version&rdquo; of the Document means any work containing the
  2263. Document or a portion of it, either copied verbatim, or with
  2264. modifications and/or translated into another language.
  2265. </p>
  2266. <p>A &ldquo;Secondary Section&rdquo; is a named appendix or a front-matter section
  2267. of the Document that deals exclusively with the relationship of the
  2268. publishers or authors of the Document to the Document&rsquo;s overall
  2269. subject (or to related matters) and contains nothing that could fall
  2270. directly within that overall subject. (Thus, if the Document is in
  2271. part a textbook of mathematics, a Secondary Section may not explain
  2272. any mathematics.) The relationship could be a matter of historical
  2273. connection with the subject or with related matters, or of legal,
  2274. commercial, philosophical, ethical or political position regarding
  2275. them.
  2276. </p>
  2277. <p>The &ldquo;Invariant Sections&rdquo; are certain Secondary Sections whose titles
  2278. are designated, as being those of Invariant Sections, in the notice
  2279. that says that the Document is released under this License. If a
  2280. section does not fit the above definition of Secondary then it is not
  2281. allowed to be designated as Invariant. The Document may contain zero
  2282. Invariant Sections. If the Document does not identify any Invariant
  2283. Sections then there are none.
  2284. </p>
  2285. <p>The &ldquo;Cover Texts&rdquo; are certain short passages of text that are listed,
  2286. as Front-Cover Texts or Back-Cover Texts, in the notice that says that
  2287. the Document is released under this License. A Front-Cover Text may
  2288. be at most 5 words, and a Back-Cover Text may be at most 25 words.
  2289. </p>
  2290. <p>A &ldquo;Transparent&rdquo; copy of the Document means a machine-readable copy,
  2291. represented in a format whose specification is available to the
  2292. general public, that is suitable for revising the document
  2293. straightforwardly with generic text editors or (for images composed of
  2294. pixels) generic paint programs or (for drawings) some widely available
  2295. drawing editor, and that is suitable for input to text formatters or
  2296. for automatic translation to a variety of formats suitable for input
  2297. to text formatters. A copy made in an otherwise Transparent file
  2298. format whose markup, or absence of markup, has been arranged to thwart
  2299. or discourage subsequent modification by readers is not Transparent.
  2300. An image format is not Transparent if used for any substantial amount
  2301. of text. A copy that is not &ldquo;Transparent&rdquo; is called &ldquo;Opaque&rdquo;.
  2302. </p>
  2303. <p>Examples of suitable formats for Transparent copies include plain
  2304. <small>ASCII</small> without markup, Texinfo input format, LaTeX input
  2305. format, <acronym>SGML</acronym> or <acronym>XML</acronym> using a publicly available
  2306. <acronym>DTD</acronym>, and standard-conforming simple <acronym>HTML</acronym>,
  2307. PostScript or <acronym>PDF</acronym> designed for human modification. Examples
  2308. of transparent image formats include <acronym>PNG</acronym>, <acronym>XCF</acronym> and
  2309. <acronym>JPG</acronym>. Opaque formats include proprietary formats that can be
  2310. read and edited only by proprietary word processors, <acronym>SGML</acronym> or
  2311. <acronym>XML</acronym> for which the <acronym>DTD</acronym> and/or processing tools are
  2312. not generally available, and the machine-generated <acronym>HTML</acronym>,
  2313. PostScript or <acronym>PDF</acronym> produced by some word processors for
  2314. output purposes only.
  2315. </p>
  2316. <p>The &ldquo;Title Page&rdquo; means, for a printed book, the title page itself,
  2317. plus such following pages as are needed to hold, legibly, the material
  2318. this License requires to appear in the title page. For works in
  2319. formats which do not have any title page as such, &ldquo;Title Page&rdquo; means
  2320. the text near the most prominent appearance of the work&rsquo;s title,
  2321. preceding the beginning of the body of the text.
  2322. </p>
  2323. <p>The &ldquo;publisher&rdquo; means any person or entity that distributes copies
  2324. of the Document to the public.
  2325. </p>
  2326. <p>A section &ldquo;Entitled XYZ&rdquo; means a named subunit of the Document whose
  2327. title either is precisely XYZ or contains XYZ in parentheses following
  2328. text that translates XYZ in another language. (Here XYZ stands for a
  2329. specific section name mentioned below, such as &ldquo;Acknowledgements&rdquo;,
  2330. &ldquo;Dedications&rdquo;, &ldquo;Endorsements&rdquo;, or &ldquo;History&rdquo;.) To &ldquo;Preserve the Title&rdquo;
  2331. of such a section when you modify the Document means that it remains a
  2332. section &ldquo;Entitled XYZ&rdquo; according to this definition.
  2333. </p>
  2334. <p>The Document may include Warranty Disclaimers next to the notice which
  2335. states that this License applies to the Document. These Warranty
  2336. Disclaimers are considered to be included by reference in this
  2337. License, but only as regards disclaiming warranties: any other
  2338. implication that these Warranty Disclaimers may have is void and has
  2339. no effect on the meaning of this License.
  2340. </p>
  2341. </li><li> VERBATIM COPYING
  2342. <p>You may copy and distribute the Document in any medium, either
  2343. commercially or noncommercially, provided that this License, the
  2344. copyright notices, and the license notice saying this License applies
  2345. to the Document are reproduced in all copies, and that you add no other
  2346. conditions whatsoever to those of this License. You may not use
  2347. technical measures to obstruct or control the reading or further
  2348. copying of the copies you make or distribute. However, you may accept
  2349. compensation in exchange for copies. If you distribute a large enough
  2350. number of copies you must also follow the conditions in section 3.
  2351. </p>
  2352. <p>You may also lend copies, under the same conditions stated above, and
  2353. you may publicly display copies.
  2354. </p>
  2355. </li><li> COPYING IN QUANTITY
  2356. <p>If you publish printed copies (or copies in media that commonly have
  2357. printed covers) of the Document, numbering more than 100, and the
  2358. Document&rsquo;s license notice requires Cover Texts, you must enclose the
  2359. copies in covers that carry, clearly and legibly, all these Cover
  2360. Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
  2361. the back cover. Both covers must also clearly and legibly identify
  2362. you as the publisher of these copies. The front cover must present
  2363. the full title with all words of the title equally prominent and
  2364. visible. You may add other material on the covers in addition.
  2365. Copying with changes limited to the covers, as long as they preserve
  2366. the title of the Document and satisfy these conditions, can be treated
  2367. as verbatim copying in other respects.
  2368. </p>
  2369. <p>If the required texts for either cover are too voluminous to fit
  2370. legibly, you should put the first ones listed (as many as fit
  2371. reasonably) on the actual cover, and continue the rest onto adjacent
  2372. pages.
  2373. </p>
  2374. <p>If you publish or distribute Opaque copies of the Document numbering
  2375. more than 100, you must either include a machine-readable Transparent
  2376. copy along with each Opaque copy, or state in or with each Opaque copy
  2377. a computer-network location from which the general network-using
  2378. public has access to download using public-standard network protocols
  2379. a complete Transparent copy of the Document, free of added material.
  2380. If you use the latter option, you must take reasonably prudent steps,
  2381. when you begin distribution of Opaque copies in quantity, to ensure
  2382. that this Transparent copy will remain thus accessible at the stated
  2383. location until at least one year after the last time you distribute an
  2384. Opaque copy (directly or through your agents or retailers) of that
  2385. edition to the public.
  2386. </p>
  2387. <p>It is requested, but not required, that you contact the authors of the
  2388. Document well before redistributing any large number of copies, to give
  2389. them a chance to provide you with an updated version of the Document.
  2390. </p>
  2391. </li><li> MODIFICATIONS
  2392. <p>You may copy and distribute a Modified Version of the Document under
  2393. the conditions of sections 2 and 3 above, provided that you release
  2394. the Modified Version under precisely this License, with the Modified
  2395. Version filling the role of the Document, thus licensing distribution
  2396. and modification of the Modified Version to whoever possesses a copy
  2397. of it. In addition, you must do these things in the Modified Version:
  2398. </p>
  2399. <ol type="A" start="1">
  2400. <li> Use in the Title Page (and on the covers, if any) a title distinct
  2401. from that of the Document, and from those of previous versions
  2402. (which should, if there were any, be listed in the History section
  2403. of the Document). You may use the same title as a previous version
  2404. if the original publisher of that version gives permission.
  2405. </li><li> List on the Title Page, as authors, one or more persons or entities
  2406. responsible for authorship of the modifications in the Modified
  2407. Version, together with at least five of the principal authors of the
  2408. Document (all of its principal authors, if it has fewer than five),
  2409. unless they release you from this requirement.
  2410. </li><li> State on the Title page the name of the publisher of the
  2411. Modified Version, as the publisher.
  2412. </li><li> Preserve all the copyright notices of the Document.
  2413. </li><li> Add an appropriate copyright notice for your modifications
  2414. adjacent to the other copyright notices.
  2415. </li><li> Include, immediately after the copyright notices, a license notice
  2416. giving the public permission to use the Modified Version under the
  2417. terms of this License, in the form shown in the Addendum below.
  2418. </li><li> Preserve in that license notice the full lists of Invariant Sections
  2419. and required Cover Texts given in the Document&rsquo;s license notice.
  2420. </li><li> Include an unaltered copy of this License.
  2421. </li><li> Preserve the section Entitled &ldquo;History&rdquo;, Preserve its Title, and add
  2422. to it an item stating at least the title, year, new authors, and
  2423. publisher of the Modified Version as given on the Title Page. If
  2424. there is no section Entitled &ldquo;History&rdquo; in the Document, create one
  2425. stating the title, year, authors, and publisher of the Document as
  2426. given on its Title Page, then add an item describing the Modified
  2427. Version as stated in the previous sentence.
  2428. </li><li> Preserve the network location, if any, given in the Document for
  2429. public access to a Transparent copy of the Document, and likewise
  2430. the network locations given in the Document for previous versions
  2431. it was based on. These may be placed in the &ldquo;History&rdquo; section.
  2432. You may omit a network location for a work that was published at
  2433. least four years before the Document itself, or if the original
  2434. publisher of the version it refers to gives permission.
  2435. </li><li> For any section Entitled &ldquo;Acknowledgements&rdquo; or &ldquo;Dedications&rdquo;, Preserve
  2436. the Title of the section, and preserve in the section all the
  2437. substance and tone of each of the contributor acknowledgements and/or
  2438. dedications given therein.
  2439. </li><li> Preserve all the Invariant Sections of the Document,
  2440. unaltered in their text and in their titles. Section numbers
  2441. or the equivalent are not considered part of the section titles.
  2442. </li><li> Delete any section Entitled &ldquo;Endorsements&rdquo;. Such a section
  2443. may not be included in the Modified Version.
  2444. </li><li> Do not retitle any existing section to be Entitled &ldquo;Endorsements&rdquo; or
  2445. to conflict in title with any Invariant Section.
  2446. </li><li> Preserve any Warranty Disclaimers.
  2447. </li></ol>
  2448. <p>If the Modified Version includes new front-matter sections or
  2449. appendices that qualify as Secondary Sections and contain no material
  2450. copied from the Document, you may at your option designate some or all
  2451. of these sections as invariant. To do this, add their titles to the
  2452. list of Invariant Sections in the Modified Version&rsquo;s license notice.
  2453. These titles must be distinct from any other section titles.
  2454. </p>
  2455. <p>You may add a section Entitled &ldquo;Endorsements&rdquo;, provided it contains
  2456. nothing but endorsements of your Modified Version by various
  2457. parties&mdash;for example, statements of peer review or that the text has
  2458. been approved by an organization as the authoritative definition of a
  2459. standard.
  2460. </p>
  2461. <p>You may add a passage of up to five words as a Front-Cover Text, and a
  2462. passage of up to 25 words as a Back-Cover Text, to the end of the list
  2463. of Cover Texts in the Modified Version. Only one passage of
  2464. Front-Cover Text and one of Back-Cover Text may be added by (or
  2465. through arrangements made by) any one entity. If the Document already
  2466. includes a cover text for the same cover, previously added by you or
  2467. by arrangement made by the same entity you are acting on behalf of,
  2468. you may not add another; but you may replace the old one, on explicit
  2469. permission from the previous publisher that added the old one.
  2470. </p>
  2471. <p>The author(s) and publisher(s) of the Document do not by this License
  2472. give permission to use their names for publicity for or to assert or
  2473. imply endorsement of any Modified Version.
  2474. </p>
  2475. </li><li> COMBINING DOCUMENTS
  2476. <p>You may combine the Document with other documents released under this
  2477. License, under the terms defined in section 4 above for modified
  2478. versions, provided that you include in the combination all of the
  2479. Invariant Sections of all of the original documents, unmodified, and
  2480. list them all as Invariant Sections of your combined work in its
  2481. license notice, and that you preserve all their Warranty Disclaimers.
  2482. </p>
  2483. <p>The combined work need only contain one copy of this License, and
  2484. multiple identical Invariant Sections may be replaced with a single
  2485. copy. If there are multiple Invariant Sections with the same name but
  2486. different contents, make the title of each such section unique by
  2487. adding at the end of it, in parentheses, the name of the original
  2488. author or publisher of that section if known, or else a unique number.
  2489. Make the same adjustment to the section titles in the list of
  2490. Invariant Sections in the license notice of the combined work.
  2491. </p>
  2492. <p>In the combination, you must combine any sections Entitled &ldquo;History&rdquo;
  2493. in the various original documents, forming one section Entitled
  2494. &ldquo;History&rdquo;; likewise combine any sections Entitled &ldquo;Acknowledgements&rdquo;,
  2495. and any sections Entitled &ldquo;Dedications&rdquo;. You must delete all
  2496. sections Entitled &ldquo;Endorsements.&rdquo;
  2497. </p>
  2498. </li><li> COLLECTIONS OF DOCUMENTS
  2499. <p>You may make a collection consisting of the Document and other documents
  2500. released under this License, and replace the individual copies of this
  2501. License in the various documents with a single copy that is included in
  2502. the collection, provided that you follow the rules of this License for
  2503. verbatim copying of each of the documents in all other respects.
  2504. </p>
  2505. <p>You may extract a single document from such a collection, and distribute
  2506. it individually under this License, provided you insert a copy of this
  2507. License into the extracted document, and follow this License in all
  2508. other respects regarding verbatim copying of that document.
  2509. </p>
  2510. </li><li> AGGREGATION WITH INDEPENDENT WORKS
  2511. <p>A compilation of the Document or its derivatives with other separate
  2512. and independent documents or works, in or on a volume of a storage or
  2513. distribution medium, is called an &ldquo;aggregate&rdquo; if the copyright
  2514. resulting from the compilation is not used to limit the legal rights
  2515. of the compilation&rsquo;s users beyond what the individual works permit.
  2516. When the Document is included in an aggregate, this License does not
  2517. apply to the other works in the aggregate which are not themselves
  2518. derivative works of the Document.
  2519. </p>
  2520. <p>If the Cover Text requirement of section 3 is applicable to these
  2521. copies of the Document, then if the Document is less than one half of
  2522. the entire aggregate, the Document&rsquo;s Cover Texts may be placed on
  2523. covers that bracket the Document within the aggregate, or the
  2524. electronic equivalent of covers if the Document is in electronic form.
  2525. Otherwise they must appear on printed covers that bracket the whole
  2526. aggregate.
  2527. </p>
  2528. </li><li> TRANSLATION
  2529. <p>Translation is considered a kind of modification, so you may
  2530. distribute translations of the Document under the terms of section 4.
  2531. Replacing Invariant Sections with translations requires special
  2532. permission from their copyright holders, but you may include
  2533. translations of some or all Invariant Sections in addition to the
  2534. original versions of these Invariant Sections. You may include a
  2535. translation of this License, and all the license notices in the
  2536. Document, and any Warranty Disclaimers, provided that you also include
  2537. the original English version of this License and the original versions
  2538. of those notices and disclaimers. In case of a disagreement between
  2539. the translation and the original version of this License or a notice
  2540. or disclaimer, the original version will prevail.
  2541. </p>
  2542. <p>If a section in the Document is Entitled &ldquo;Acknowledgements&rdquo;,
  2543. &ldquo;Dedications&rdquo;, or &ldquo;History&rdquo;, the requirement (section 4) to Preserve
  2544. its Title (section 1) will typically require changing the actual
  2545. title.
  2546. </p>
  2547. </li><li> TERMINATION
  2548. <p>You may not copy, modify, sublicense, or distribute the Document
  2549. except as expressly provided under this License. Any attempt
  2550. otherwise to copy, modify, sublicense, or distribute it is void, and
  2551. will automatically terminate your rights under this License.
  2552. </p>
  2553. <p>However, if you cease all violation of this License, then your license
  2554. from a particular copyright holder is reinstated (a) provisionally,
  2555. unless and until the copyright holder explicitly and finally
  2556. terminates your license, and (b) permanently, if the copyright holder
  2557. fails to notify you of the violation by some reasonable means prior to
  2558. 60 days after the cessation.
  2559. </p>
  2560. <p>Moreover, your license from a particular copyright holder is
  2561. reinstated permanently if the copyright holder notifies you of the
  2562. violation by some reasonable means, this is the first time you have
  2563. received notice of violation of this License (for any work) from that
  2564. copyright holder, and you cure the violation prior to 30 days after
  2565. your receipt of the notice.
  2566. </p>
  2567. <p>Termination of your rights under this section does not terminate the
  2568. licenses of parties who have received copies or rights from you under
  2569. this License. If your rights have been terminated and not permanently
  2570. reinstated, receipt of a copy of some or all of the same material does
  2571. not give you any rights to use it.
  2572. </p>
  2573. </li><li> FUTURE REVISIONS OF THIS LICENSE
  2574. <p>The Free Software Foundation may publish new, revised versions
  2575. of the GNU Free Documentation License from time to time. Such new
  2576. versions will be similar in spirit to the present version, but may
  2577. differ in detail to address new problems or concerns. See
  2578. <a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>.
  2579. </p>
  2580. <p>Each version of the License is given a distinguishing version number.
  2581. If the Document specifies that a particular numbered version of this
  2582. License &ldquo;or any later version&rdquo; applies to it, you have the option of
  2583. following the terms and conditions either of that specified version or
  2584. of any later version that has been published (not as a draft) by the
  2585. Free Software Foundation. If the Document does not specify a version
  2586. number of this License, you may choose any version ever published (not
  2587. as a draft) by the Free Software Foundation. If the Document
  2588. specifies that a proxy can decide which future versions of this
  2589. License can be used, that proxy&rsquo;s public statement of acceptance of a
  2590. version permanently authorizes you to choose that version for the
  2591. Document.
  2592. </p>
  2593. </li><li> RELICENSING
  2594. <p>&ldquo;Massive Multiauthor Collaboration Site&rdquo; (or &ldquo;MMC Site&rdquo;) means any
  2595. World Wide Web server that publishes copyrightable works and also
  2596. provides prominent facilities for anybody to edit those works. A
  2597. public wiki that anybody can edit is an example of such a server. A
  2598. &ldquo;Massive Multiauthor Collaboration&rdquo; (or &ldquo;MMC&rdquo;) contained in the
  2599. site means any set of copyrightable works thus published on the MMC
  2600. site.
  2601. </p>
  2602. <p>&ldquo;CC-BY-SA&rdquo; means the Creative Commons Attribution-Share Alike 3.0
  2603. license published by Creative Commons Corporation, a not-for-profit
  2604. corporation with a principal place of business in San Francisco,
  2605. California, as well as future copyleft versions of that license
  2606. published by that same organization.
  2607. </p>
  2608. <p>&ldquo;Incorporate&rdquo; means to publish or republish a Document, in whole or
  2609. in part, as part of another Document.
  2610. </p>
  2611. <p>An MMC is &ldquo;eligible for relicensing&rdquo; if it is licensed under this
  2612. License, and if all works that were first published under this License
  2613. somewhere other than this MMC, and subsequently incorporated in whole
  2614. or in part into the MMC, (1) had no cover texts or invariant sections,
  2615. and (2) were thus incorporated prior to November 1, 2008.
  2616. </p>
  2617. <p>The operator of an MMC Site may republish an MMC contained in the site
  2618. under CC-BY-SA on the same site at any time before August 1, 2009,
  2619. provided the MMC is eligible for relicensing.
  2620. </p>
  2621. </li></ol>
  2622. <span id="ADDENDUM_003a-How-to-use-this-License-for-your-documents"></span><h3 class="heading">ADDENDUM: How to use this License for your documents</h3>
  2623. <p>To use this License in a document you have written, include a copy of
  2624. the License in the document and put the following copyright and
  2625. license notices just after the title page:
  2626. </p>
  2627. <div class="example">
  2628. <pre class="example"> Copyright (C) <var>year</var> <var>your name</var>.
  2629. Permission is granted to copy, distribute and/or modify this document
  2630. under the terms of the GNU Free Documentation License, Version 1.3
  2631. or any later version published by the Free Software Foundation;
  2632. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  2633. Texts. A copy of the license is included in the section entitled ``GNU
  2634. Free Documentation License''.
  2635. </pre></div>
  2636. <p>If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
  2637. replace the &ldquo;with&hellip;Texts.&rdquo; line with this:
  2638. </p>
  2639. <div class="example">
  2640. <pre class="example"> with the Invariant Sections being <var>list their titles</var>, with
  2641. the Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts
  2642. being <var>list</var>.
  2643. </pre></div>
  2644. <p>If you have Invariant Sections without Cover Texts, or some other
  2645. combination of the three, merge those two alternatives to suit the
  2646. situation.
  2647. </p>
  2648. <p>If your document contains nontrivial examples of program code, we
  2649. recommend releasing these examples in parallel under your choice of
  2650. free software license, such as the GNU General Public License,
  2651. to permit their use in free software.
  2652. </p>
  2653. <hr>
  2654. </body>
  2655. </html>