Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Invoking-Gcov.html 29KB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Invoking Gcov (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Invoking Gcov (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Invoking Gcov (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Gcov.html#Gcov" rel="up" title="Gcov">
  30. <link href="Gcov-and-Optimization.html#Gcov-and-Optimization" rel="next" title="Gcov and Optimization">
  31. <link href="Gcov-Intro.html#Gcov-Intro" rel="prev" title="Gcov Intro">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Invoking-Gcov"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Gcov-and-Optimization.html#Gcov-and-Optimization" accesskey="n" rel="next">Gcov and Optimization</a>, Previous: <a href="Gcov-Intro.html#Gcov-Intro" accesskey="p" rel="prev">Gcov Intro</a>, Up: <a href="Gcov.html#Gcov" accesskey="u" rel="up">Gcov</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Invoking-gcov"></a>
  68. <h3 class="section">10.2 Invoking <code>gcov</code></h3>
  69. <div class="smallexample">
  70. <pre class="smallexample">gcov <span class="roman">[</span><var>options</var><span class="roman">]</span> <var>files</var>
  71. </pre></div>
  72. <p><code>gcov</code> accepts the following options:
  73. </p>
  74. <dl compact="compact">
  75. <dt><code>-a</code></dt>
  76. <dt><code>--all-blocks</code></dt>
  77. <dd><p>Write individual execution counts for every basic block. Normally gcov
  78. outputs execution counts only for the main blocks of a line. With this
  79. option you can determine if blocks within a single line are not being
  80. executed.
  81. </p>
  82. </dd>
  83. <dt><code>-b</code></dt>
  84. <dt><code>--branch-probabilities</code></dt>
  85. <dd><p>Write branch frequencies to the output file, and write branch summary
  86. info to the standard output. This option allows you to see how often
  87. each branch in your program was taken. Unconditional branches will not
  88. be shown, unless the <samp>-u</samp> option is given.
  89. </p>
  90. </dd>
  91. <dt><code>-c</code></dt>
  92. <dt><code>--branch-counts</code></dt>
  93. <dd><p>Write branch frequencies as the number of branches taken, rather than
  94. the percentage of branches taken.
  95. </p>
  96. </dd>
  97. <dt><code>-d</code></dt>
  98. <dt><code>--display-progress</code></dt>
  99. <dd><p>Display the progress on the standard output.
  100. </p>
  101. </dd>
  102. <dt><code>-f</code></dt>
  103. <dt><code>--function-summaries</code></dt>
  104. <dd><p>Output summaries for each function in addition to the file level summary.
  105. </p>
  106. </dd>
  107. <dt><code>-h</code></dt>
  108. <dt><code>--help</code></dt>
  109. <dd><p>Display help about using <code>gcov</code> (on the standard output), and
  110. exit without doing any further processing.
  111. </p>
  112. </dd>
  113. <dt><code>-i</code></dt>
  114. <dt><code>--json-format</code></dt>
  115. <dd><p>Output gcov file in an easy-to-parse JSON intermediate format
  116. which does not require source code for generation. The JSON
  117. file is compressed with gzip compression algorithm
  118. and the files have <samp>.gcov.json.gz</samp> extension.
  119. </p>
  120. <p>Structure of the JSON is following:
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">{
  124. &quot;current_working_directory&quot;: <var>current_working_directory</var>,
  125. &quot;data_file&quot;: <var>data_file</var>,
  126. &quot;format_version&quot;: <var>format_version</var>,
  127. &quot;gcc_version&quot;: <var>gcc_version</var>
  128. &quot;files&quot;: [<var>file</var>]
  129. }
  130. </pre></div>
  131. <p>Fields of the root element have following semantics:
  132. </p>
  133. <ul>
  134. <li> <var>current_working_directory</var>: working directory where
  135. a compilation unit was compiled
  136. </li><li> <var>data_file</var>: name of the data file (GCDA)
  137. </li><li> <var>format_version</var>: semantic version of the format
  138. </li><li> <var>gcc_version</var>: version of the GCC compiler
  139. </li></ul>
  140. <p>Each <var>file</var> has the following form:
  141. </p>
  142. <div class="smallexample">
  143. <pre class="smallexample">{
  144. &quot;file&quot;: <var>file_name</var>,
  145. &quot;functions&quot;: [<var>function</var>],
  146. &quot;lines&quot;: [<var>line</var>]
  147. }
  148. </pre></div>
  149. <p>Fields of the <var>file</var> element have following semantics:
  150. </p>
  151. <ul>
  152. <li> <var>file_name</var>: name of the source file
  153. </li></ul>
  154. <p>Each <var>function</var> has the following form:
  155. </p>
  156. <div class="smallexample">
  157. <pre class="smallexample">{
  158. &quot;blocks&quot;: <var>blocks</var>,
  159. &quot;blocks_executed&quot;: <var>blocks_executed</var>,
  160. &quot;demangled_name&quot;: &quot;<var>demangled_name</var>,
  161. &quot;end_column&quot;: <var>end_column</var>,
  162. &quot;end_line&quot;: <var>end_line</var>,
  163. &quot;execution_count&quot;: <var>execution_count</var>,
  164. &quot;name&quot;: <var>name</var>,
  165. &quot;start_column&quot;: <var>start_column</var>
  166. &quot;start_line&quot;: <var>start_line</var>
  167. }
  168. </pre></div>
  169. <p>Fields of the <var>function</var> element have following semantics:
  170. </p>
  171. <ul>
  172. <li> <var>blocks</var>: number of blocks that are in the function
  173. </li><li> <var>blocks_executed</var>: number of executed blocks of the function
  174. </li><li> <var>demangled_name</var>: demangled name of the function
  175. </li><li> <var>end_column</var>: column in the source file where the function ends
  176. </li><li> <var>end_line</var>: line in the source file where the function ends
  177. </li><li> <var>execution_count</var>: number of executions of the function
  178. </li><li> <var>name</var>: name of the function
  179. </li><li> <var>start_column</var>: column in the source file where the function begins
  180. </li><li> <var>start_line</var>: line in the source file where the function begins
  181. </li></ul>
  182. <p>Note that line numbers and column numbers number from 1. In the current
  183. implementation, <var>start_line</var> and <var>start_column</var> do not include
  184. any template parameters and the leading return type but that
  185. this is likely to be fixed in the future.
  186. </p>
  187. <p>Each <var>line</var> has the following form:
  188. </p>
  189. <div class="smallexample">
  190. <pre class="smallexample">{
  191. &quot;branches&quot;: [<var>branch</var>],
  192. &quot;count&quot;: <var>count</var>,
  193. &quot;line_number&quot;: <var>line_number</var>,
  194. &quot;unexecuted_block&quot;: <var>unexecuted_block</var>
  195. &quot;function_name&quot;: <var>function_name</var>,
  196. }
  197. </pre></div>
  198. <p>Branches are present only with <var>-b</var> option.
  199. Fields of the <var>line</var> element have following semantics:
  200. </p>
  201. <ul>
  202. <li> <var>count</var>: number of executions of the line
  203. </li><li> <var>line_number</var>: line number
  204. </li><li> <var>unexecuted_block</var>: flag whether the line contains an unexecuted block
  205. (not all statements on the line are executed)
  206. </li><li> <var>function_name</var>: a name of a function this <var>line</var> belongs to
  207. (for a line with an inlined statements can be not set)
  208. </li></ul>
  209. <p>Each <var>branch</var> has the following form:
  210. </p>
  211. <div class="smallexample">
  212. <pre class="smallexample">{
  213. &quot;count&quot;: <var>count</var>,
  214. &quot;fallthrough&quot;: <var>fallthrough</var>,
  215. &quot;throw&quot;: <var>throw</var>
  216. }
  217. </pre></div>
  218. <p>Fields of the <var>branch</var> element have following semantics:
  219. </p>
  220. <ul>
  221. <li> <var>count</var>: number of executions of the branch
  222. </li><li> <var>fallthrough</var>: true when the branch is a fall through branch
  223. </li><li> <var>throw</var>: true when the branch is an exceptional branch
  224. </li></ul>
  225. </dd>
  226. <dt><code>-j</code></dt>
  227. <dt><code>--human-readable</code></dt>
  228. <dd><p>Write counts in human readable format (like 24.6k).
  229. </p>
  230. </dd>
  231. <dt><code>-k</code></dt>
  232. <dt><code>--use-colors</code></dt>
  233. <dd>
  234. <p>Use colors for lines of code that have zero coverage. We use red color for
  235. non-exceptional lines and cyan for exceptional. Same colors are used for
  236. basic blocks with <samp>-a</samp> option.
  237. </p>
  238. </dd>
  239. <dt><code>-l</code></dt>
  240. <dt><code>--long-file-names</code></dt>
  241. <dd><p>Create long file names for included source files. For example, if the
  242. header file <samp>x.h</samp> contains code, and was included in the file
  243. <samp>a.c</samp>, then running <code>gcov</code> on the file <samp>a.c</samp> will
  244. produce an output file called <samp>a.c##x.h.gcov</samp> instead of
  245. <samp>x.h.gcov</samp>. This can be useful if <samp>x.h</samp> is included in
  246. multiple source files and you want to see the individual
  247. contributions. If you use the &lsquo;<samp>-p</samp>&rsquo; option, both the including
  248. and included file names will be complete path names.
  249. </p>
  250. </dd>
  251. <dt><code>-m</code></dt>
  252. <dt><code>--demangled-names</code></dt>
  253. <dd><p>Display demangled function names in output. The default is to show
  254. mangled function names.
  255. </p>
  256. </dd>
  257. <dt><code>-n</code></dt>
  258. <dt><code>--no-output</code></dt>
  259. <dd><p>Do not create the <code>gcov</code> output file.
  260. </p>
  261. </dd>
  262. <dt><code>-o <var>directory|file</var></code></dt>
  263. <dt><code>--object-directory <var>directory</var></code></dt>
  264. <dt><code>--object-file <var>file</var></code></dt>
  265. <dd><p>Specify either the directory containing the gcov data files, or the
  266. object path name. The <samp>.gcno</samp>, and
  267. <samp>.gcda</samp> data files are searched for using this option. If a directory
  268. is specified, the data files are in that directory and named after the
  269. input file name, without its extension. If a file is specified here,
  270. the data files are named after that file, without its extension.
  271. </p>
  272. </dd>
  273. <dt><code>-p</code></dt>
  274. <dt><code>--preserve-paths</code></dt>
  275. <dd><p>Preserve complete path information in the names of generated
  276. <samp>.gcov</samp> files. Without this option, just the filename component is
  277. used. With this option, all directories are used, with &lsquo;<samp>/</samp>&rsquo; characters
  278. translated to &lsquo;<samp>#</samp>&rsquo; characters, <samp>.</samp> directory components
  279. removed and unremoveable <samp>..</samp>
  280. components renamed to &lsquo;<samp>^</samp>&rsquo;. This is useful if sourcefiles are in several
  281. different directories.
  282. </p>
  283. </dd>
  284. <dt><code>-q</code></dt>
  285. <dt><code>--use-hotness-colors</code></dt>
  286. <dd>
  287. <p>Emit perf-like colored output for hot lines. Legend of the color scale
  288. is printed at the very beginning of the output file.
  289. </p>
  290. </dd>
  291. <dt><code>-r</code></dt>
  292. <dt><code>--relative-only</code></dt>
  293. <dd><p>Only output information about source files with a relative pathname
  294. (after source prefix elision). Absolute paths are usually system
  295. header files and coverage of any inline functions therein is normally
  296. uninteresting.
  297. </p>
  298. </dd>
  299. <dt><code>-s <var>directory</var></code></dt>
  300. <dt><code>--source-prefix <var>directory</var></code></dt>
  301. <dd><p>A prefix for source file names to remove when generating the output
  302. coverage files. This option is useful when building in a separate
  303. directory, and the pathname to the source directory is not wanted when
  304. determining the output file names. Note that this prefix detection is
  305. applied before determining whether the source file is absolute.
  306. </p>
  307. </dd>
  308. <dt><code>-t</code></dt>
  309. <dt><code>--stdout</code></dt>
  310. <dd><p>Output to standard output instead of output files.
  311. </p>
  312. </dd>
  313. <dt><code>-u</code></dt>
  314. <dt><code>--unconditional-branches</code></dt>
  315. <dd><p>When branch probabilities are given, include those of unconditional branches.
  316. Unconditional branches are normally not interesting.
  317. </p>
  318. </dd>
  319. <dt><code>-v</code></dt>
  320. <dt><code>--version</code></dt>
  321. <dd><p>Display the <code>gcov</code> version number (on the standard output),
  322. and exit without doing any further processing.
  323. </p>
  324. </dd>
  325. <dt><code>-w</code></dt>
  326. <dt><code>--verbose</code></dt>
  327. <dd><p>Print verbose informations related to basic blocks and arcs.
  328. </p>
  329. </dd>
  330. <dt><code>-x</code></dt>
  331. <dt><code>--hash-filenames</code></dt>
  332. <dd><p>When using <var>&ndash;preserve-paths</var>,
  333. gcov uses the full pathname of the source files to create
  334. an output filename. This can lead to long filenames that can overflow
  335. filesystem limits. This option creates names of the form
  336. <samp><var>source-file</var>##<var>md5</var>.gcov</samp>,
  337. where the <var>source-file</var> component is the final filename part and
  338. the <var>md5</var> component is calculated from the full mangled name that
  339. would have been used otherwise. The option is an alternative
  340. to the <var>&ndash;preserve-paths</var> on systems which have a filesystem limit.
  341. </p>
  342. </dd>
  343. </dl>
  344. <p><code>gcov</code> should be run with the current directory the same as that
  345. when you invoked the compiler. Otherwise it will not be able to locate
  346. the source files. <code>gcov</code> produces files called
  347. <samp><var>mangledname</var>.gcov</samp> in the current directory. These contain
  348. the coverage information of the source file they correspond to.
  349. One <samp>.gcov</samp> file is produced for each source (or header) file
  350. containing code,
  351. which was compiled to produce the data files. The <var>mangledname</var> part
  352. of the output file name is usually simply the source file name, but can
  353. be something more complicated if the &lsquo;<samp>-l</samp>&rsquo; or &lsquo;<samp>-p</samp>&rsquo; options are
  354. given. Refer to those options for details.
  355. </p>
  356. <p>If you invoke <code>gcov</code> with multiple input files, the
  357. contributions from each input file are summed. Typically you would
  358. invoke it with the same list of files as the final link of your executable.
  359. </p>
  360. <p>The <samp>.gcov</samp> files contain the &lsquo;<samp>:</samp>&rsquo; separated fields along with
  361. program source code. The format is
  362. </p>
  363. <div class="smallexample">
  364. <pre class="smallexample"><var>execution_count</var>:<var>line_number</var>:<var>source line text</var>
  365. </pre></div>
  366. <p>Additional block information may succeed each line, when requested by
  367. command line option. The <var>execution_count</var> is &lsquo;<samp>-</samp>&rsquo; for lines
  368. containing no code. Unexecuted lines are marked &lsquo;<samp>#####</samp>&rsquo; or
  369. &lsquo;<samp>=====</samp>&rsquo;, depending on whether they are reachable by
  370. non-exceptional paths or only exceptional paths such as C++ exception
  371. handlers, respectively. Given the &lsquo;<samp>-a</samp>&rsquo; option, unexecuted blocks are
  372. marked &lsquo;<samp>$$$$$</samp>&rsquo; or &lsquo;<samp>%%%%%</samp>&rsquo;, depending on whether a basic block
  373. is reachable via non-exceptional or exceptional paths.
  374. Executed basic blocks having a statement with zero <var>execution_count</var>
  375. end with &lsquo;<samp>*</samp>&rsquo; character and are colored with magenta color with
  376. the <samp>-k</samp> option. This functionality is not supported in Ada.
  377. </p>
  378. <p>Note that GCC can completely remove the bodies of functions that are
  379. not needed &ndash; for instance if they are inlined everywhere. Such functions
  380. are marked with &lsquo;<samp>-</samp>&rsquo;, which can be confusing.
  381. Use the <samp>-fkeep-inline-functions</samp> and <samp>-fkeep-static-functions</samp>
  382. options to retain these functions and
  383. allow gcov to properly show their <var>execution_count</var>.
  384. </p>
  385. <p>Some lines of information at the start have <var>line_number</var> of zero.
  386. These preamble lines are of the form
  387. </p>
  388. <div class="smallexample">
  389. <pre class="smallexample">-:0:<var>tag</var>:<var>value</var>
  390. </pre></div>
  391. <p>The ordering and number of these preamble lines will be augmented as
  392. <code>gcov</code> development progresses &mdash; do not rely on them remaining
  393. unchanged. Use <var>tag</var> to locate a particular preamble line.
  394. </p>
  395. <p>The additional block information is of the form
  396. </p>
  397. <div class="smallexample">
  398. <pre class="smallexample"><var>tag</var> <var>information</var>
  399. </pre></div>
  400. <p>The <var>information</var> is human readable, but designed to be simple
  401. enough for machine parsing too.
  402. </p>
  403. <p>When printing percentages, 0% and 100% are only printed when the values
  404. are <em>exactly</em> 0% and 100% respectively. Other values which would
  405. conventionally be rounded to 0% or 100% are instead printed as the
  406. nearest non-boundary value.
  407. </p>
  408. <p>When using <code>gcov</code>, you must first compile your program
  409. with a special GCC option &lsquo;<samp>--coverage</samp>&rsquo;.
  410. This tells the compiler to generate additional information needed by
  411. gcov (basically a flow graph of the program) and also includes
  412. additional code in the object files for generating the extra profiling
  413. information needed by gcov. These additional files are placed in the
  414. directory where the object file is located.
  415. </p>
  416. <p>Running the program will cause profile output to be generated. For each
  417. source file compiled with <samp>-fprofile-arcs</samp>, an accompanying
  418. <samp>.gcda</samp> file will be placed in the object file directory.
  419. </p>
  420. <p>Running <code>gcov</code> with your program&rsquo;s source file names as arguments
  421. will now produce a listing of the code along with frequency of execution
  422. for each line. For example, if your program is called <samp>tmp.cpp</samp>, this
  423. is what you see when you use the basic <code>gcov</code> facility:
  424. </p>
  425. <div class="smallexample">
  426. <pre class="smallexample">$ g++ --coverage tmp.cpp
  427. $ a.out
  428. $ gcov tmp.cpp -m
  429. File 'tmp.cpp'
  430. Lines executed:92.86% of 14
  431. Creating 'tmp.cpp.gcov'
  432. </pre></div>
  433. <p>The file <samp>tmp.cpp.gcov</samp> contains output from <code>gcov</code>.
  434. Here is a sample:
  435. </p>
  436. <div class="smallexample">
  437. <pre class="smallexample"> -: 0:Source:tmp.cpp
  438. -: 0:Working directory:/home/gcc/testcase
  439. -: 0:Graph:tmp.gcno
  440. -: 0:Data:tmp.gcda
  441. -: 0:Runs:1
  442. -: 0:Programs:1
  443. -: 1:#include &lt;stdio.h&gt;
  444. -: 2:
  445. -: 3:template&lt;class T&gt;
  446. -: 4:class Foo
  447. -: 5:{
  448. -: 6: public:
  449. 1*: 7: Foo(): b (1000) {}
  450. ------------------
  451. Foo&lt;char&gt;::Foo():
  452. #####: 7: Foo(): b (1000) {}
  453. ------------------
  454. Foo&lt;int&gt;::Foo():
  455. 1: 7: Foo(): b (1000) {}
  456. ------------------
  457. 2*: 8: void inc () { b++; }
  458. ------------------
  459. Foo&lt;char&gt;::inc():
  460. #####: 8: void inc () { b++; }
  461. ------------------
  462. Foo&lt;int&gt;::inc():
  463. 2: 8: void inc () { b++; }
  464. ------------------
  465. -: 9:
  466. -: 10: private:
  467. -: 11: int b;
  468. -: 12:};
  469. -: 13:
  470. -: 14:template class Foo&lt;int&gt;;
  471. -: 15:template class Foo&lt;char&gt;;
  472. -: 16:
  473. -: 17:int
  474. 1: 18:main (void)
  475. -: 19:{
  476. -: 20: int i, total;
  477. 1: 21: Foo&lt;int&gt; counter;
  478. -: 22:
  479. 1: 23: counter.inc();
  480. 1: 24: counter.inc();
  481. 1: 25: total = 0;
  482. -: 26:
  483. 11: 27: for (i = 0; i &lt; 10; i++)
  484. 10: 28: total += i;
  485. -: 29:
  486. 1*: 30: int v = total &gt; 100 ? 1 : 2;
  487. -: 31:
  488. 1: 32: if (total != 45)
  489. #####: 33: printf (&quot;Failure\n&quot;);
  490. -: 34: else
  491. 1: 35: printf (&quot;Success\n&quot;);
  492. 1: 36: return 0;
  493. -: 37:}
  494. </pre></div>
  495. <p>Note that line 7 is shown in the report multiple times. First occurrence
  496. presents total number of execution of the line and the next two belong
  497. to instances of class Foo constructors. As you can also see, line 30 contains
  498. some unexecuted basic blocks and thus execution count has asterisk symbol.
  499. </p>
  500. <p>When you use the <samp>-a</samp> option, you will get individual block
  501. counts, and the output looks like this:
  502. </p>
  503. <div class="smallexample">
  504. <pre class="smallexample"> -: 0:Source:tmp.cpp
  505. -: 0:Working directory:/home/gcc/testcase
  506. -: 0:Graph:tmp.gcno
  507. -: 0:Data:tmp.gcda
  508. -: 0:Runs:1
  509. -: 0:Programs:1
  510. -: 1:#include &lt;stdio.h&gt;
  511. -: 2:
  512. -: 3:template&lt;class T&gt;
  513. -: 4:class Foo
  514. -: 5:{
  515. -: 6: public:
  516. 1*: 7: Foo(): b (1000) {}
  517. ------------------
  518. Foo&lt;char&gt;::Foo():
  519. #####: 7: Foo(): b (1000) {}
  520. ------------------
  521. Foo&lt;int&gt;::Foo():
  522. 1: 7: Foo(): b (1000) {}
  523. ------------------
  524. 2*: 8: void inc () { b++; }
  525. ------------------
  526. Foo&lt;char&gt;::inc():
  527. #####: 8: void inc () { b++; }
  528. ------------------
  529. Foo&lt;int&gt;::inc():
  530. 2: 8: void inc () { b++; }
  531. ------------------
  532. -: 9:
  533. -: 10: private:
  534. -: 11: int b;
  535. -: 12:};
  536. -: 13:
  537. -: 14:template class Foo&lt;int&gt;;
  538. -: 15:template class Foo&lt;char&gt;;
  539. -: 16:
  540. -: 17:int
  541. 1: 18:main (void)
  542. -: 19:{
  543. -: 20: int i, total;
  544. 1: 21: Foo&lt;int&gt; counter;
  545. 1: 21-block 0
  546. -: 22:
  547. 1: 23: counter.inc();
  548. 1: 23-block 0
  549. 1: 24: counter.inc();
  550. 1: 24-block 0
  551. 1: 25: total = 0;
  552. -: 26:
  553. 11: 27: for (i = 0; i &lt; 10; i++)
  554. 1: 27-block 0
  555. 11: 27-block 1
  556. 10: 28: total += i;
  557. 10: 28-block 0
  558. -: 29:
  559. 1*: 30: int v = total &gt; 100 ? 1 : 2;
  560. 1: 30-block 0
  561. %%%%%: 30-block 1
  562. 1: 30-block 2
  563. -: 31:
  564. 1: 32: if (total != 45)
  565. 1: 32-block 0
  566. #####: 33: printf (&quot;Failure\n&quot;);
  567. %%%%%: 33-block 0
  568. -: 34: else
  569. 1: 35: printf (&quot;Success\n&quot;);
  570. 1: 35-block 0
  571. 1: 36: return 0;
  572. 1: 36-block 0
  573. -: 37:}
  574. </pre></div>
  575. <p>In this mode, each basic block is only shown on one line &ndash; the last
  576. line of the block. A multi-line block will only contribute to the
  577. execution count of that last line, and other lines will not be shown
  578. to contain code, unless previous blocks end on those lines.
  579. The total execution count of a line is shown and subsequent lines show
  580. the execution counts for individual blocks that end on that line. After each
  581. block, the branch and call counts of the block will be shown, if the
  582. <samp>-b</samp> option is given.
  583. </p>
  584. <p>Because of the way GCC instruments calls, a call count can be shown
  585. after a line with no individual blocks.
  586. As you can see, line 33 contains a basic block that was not executed.
  587. </p>
  588. <p>When you use the <samp>-b</samp> option, your output looks like this:
  589. </p>
  590. <div class="smallexample">
  591. <pre class="smallexample"> -: 0:Source:tmp.cpp
  592. -: 0:Working directory:/home/gcc/testcase
  593. -: 0:Graph:tmp.gcno
  594. -: 0:Data:tmp.gcda
  595. -: 0:Runs:1
  596. -: 0:Programs:1
  597. -: 1:#include &lt;stdio.h&gt;
  598. -: 2:
  599. -: 3:template&lt;class T&gt;
  600. -: 4:class Foo
  601. -: 5:{
  602. -: 6: public:
  603. 1*: 7: Foo(): b (1000) {}
  604. ------------------
  605. Foo&lt;char&gt;::Foo():
  606. function Foo&lt;char&gt;::Foo() called 0 returned 0% blocks executed 0%
  607. #####: 7: Foo(): b (1000) {}
  608. ------------------
  609. Foo&lt;int&gt;::Foo():
  610. function Foo&lt;int&gt;::Foo() called 1 returned 100% blocks executed 100%
  611. 1: 7: Foo(): b (1000) {}
  612. ------------------
  613. 2*: 8: void inc () { b++; }
  614. ------------------
  615. Foo&lt;char&gt;::inc():
  616. function Foo&lt;char&gt;::inc() called 0 returned 0% blocks executed 0%
  617. #####: 8: void inc () { b++; }
  618. ------------------
  619. Foo&lt;int&gt;::inc():
  620. function Foo&lt;int&gt;::inc() called 2 returned 100% blocks executed 100%
  621. 2: 8: void inc () { b++; }
  622. ------------------
  623. -: 9:
  624. -: 10: private:
  625. -: 11: int b;
  626. -: 12:};
  627. -: 13:
  628. -: 14:template class Foo&lt;int&gt;;
  629. -: 15:template class Foo&lt;char&gt;;
  630. -: 16:
  631. -: 17:int
  632. function main called 1 returned 100% blocks executed 81%
  633. 1: 18:main (void)
  634. -: 19:{
  635. -: 20: int i, total;
  636. 1: 21: Foo&lt;int&gt; counter;
  637. call 0 returned 100%
  638. branch 1 taken 100% (fallthrough)
  639. branch 2 taken 0% (throw)
  640. -: 22:
  641. 1: 23: counter.inc();
  642. call 0 returned 100%
  643. branch 1 taken 100% (fallthrough)
  644. branch 2 taken 0% (throw)
  645. 1: 24: counter.inc();
  646. call 0 returned 100%
  647. branch 1 taken 100% (fallthrough)
  648. branch 2 taken 0% (throw)
  649. 1: 25: total = 0;
  650. -: 26:
  651. 11: 27: for (i = 0; i &lt; 10; i++)
  652. branch 0 taken 91% (fallthrough)
  653. branch 1 taken 9%
  654. 10: 28: total += i;
  655. -: 29:
  656. 1*: 30: int v = total &gt; 100 ? 1 : 2;
  657. branch 0 taken 0% (fallthrough)
  658. branch 1 taken 100%
  659. -: 31:
  660. 1: 32: if (total != 45)
  661. branch 0 taken 0% (fallthrough)
  662. branch 1 taken 100%
  663. #####: 33: printf (&quot;Failure\n&quot;);
  664. call 0 never executed
  665. branch 1 never executed
  666. branch 2 never executed
  667. -: 34: else
  668. 1: 35: printf (&quot;Success\n&quot;);
  669. call 0 returned 100%
  670. branch 1 taken 100% (fallthrough)
  671. branch 2 taken 0% (throw)
  672. 1: 36: return 0;
  673. -: 37:}
  674. </pre></div>
  675. <p>For each function, a line is printed showing how many times the function
  676. is called, how many times it returns and what percentage of the
  677. function&rsquo;s blocks were executed.
  678. </p>
  679. <p>For each basic block, a line is printed after the last line of the basic
  680. block describing the branch or call that ends the basic block. There can
  681. be multiple branches and calls listed for a single source line if there
  682. are multiple basic blocks that end on that line. In this case, the
  683. branches and calls are each given a number. There is no simple way to map
  684. these branches and calls back to source constructs. In general, though,
  685. the lowest numbered branch or call will correspond to the leftmost construct
  686. on the source line.
  687. </p>
  688. <p>For a branch, if it was executed at least once, then a percentage
  689. indicating the number of times the branch was taken divided by the
  690. number of times the branch was executed will be printed. Otherwise, the
  691. message &ldquo;never executed&rdquo; is printed.
  692. </p>
  693. <p>For a call, if it was executed at least once, then a percentage
  694. indicating the number of times the call returned divided by the number
  695. of times the call was executed will be printed. This will usually be
  696. 100%, but may be less for functions that call <code>exit</code> or <code>longjmp</code>,
  697. and thus may not return every time they are called.
  698. </p>
  699. <p>The execution counts are cumulative. If the example program were
  700. executed again without removing the <samp>.gcda</samp> file, the count for the
  701. number of times each line in the source was executed would be added to
  702. the results of the previous run(s). This is potentially useful in
  703. several ways. For example, it could be used to accumulate data over a
  704. number of program runs as part of a test verification suite, or to
  705. provide more accurate long-term information over a large number of
  706. program runs.
  707. </p>
  708. <p>The data in the <samp>.gcda</samp> files is saved immediately before the program
  709. exits. For each source file compiled with <samp>-fprofile-arcs</samp>, the
  710. profiling code first attempts to read in an existing <samp>.gcda</samp> file; if
  711. the file doesn&rsquo;t match the executable (differing number of basic block
  712. counts) it will ignore the contents of the file. It then adds in the
  713. new execution counts and finally writes the data to the file.
  714. </p>
  715. <hr>
  716. <div class="header">
  717. <p>
  718. Next: <a href="Gcov-and-Optimization.html#Gcov-and-Optimization" accesskey="n" rel="next">Gcov and Optimization</a>, Previous: <a href="Gcov-Intro.html#Gcov-Intro" accesskey="p" rel="prev">Gcov Intro</a>, Up: <a href="Gcov.html#Gcov" accesskey="u" rel="up">Gcov</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  719. </div>
  720. </body>
  721. </html>