Gcov-Intro.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Gcov Intro</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Gcov Intro">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Gcov Intro">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Invoking-Gcov.html#Invoking-Gcov" rel="next" title="Invoking Gcov">
  31. <link href="Gcov.html#Gcov" rel="prev" title="Gcov">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Gcov-Intro"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Invoking-Gcov.html#Invoking-Gcov" accesskey="n" rel="next">Invoking Gcov</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>
  66. </div>
  67. <hr>
  68. <a name="Introduction-to-gcov"></a>
  69. <h3 class="section">10.1 Introduction to <code>gcov</code></h3>
  70. <p><code>gcov</code> is a test coverage program. Use it in concert with GCC
  71. to analyze your programs to help create more efficient, faster running
  72. code and to discover untested parts of your program. You can use
  73. <code>gcov</code> as a profiling tool to help discover where your
  74. optimization efforts will best affect your code. You can also use
  75. <code>gcov</code> along with the other profiling tool, <code>gprof</code>, to
  76. assess which parts of your code use the greatest amount of computing
  77. time.
  78. </p>
  79. <p>Profiling tools help you analyze your code&rsquo;s performance. Using a
  80. profiler such as <code>gcov</code> or <code>gprof</code>, you can find out some
  81. basic performance statistics, such as:
  82. </p>
  83. <ul>
  84. <li> how often each line of code executes
  85. </li><li> what lines of code are actually executed
  86. </li><li> how much computing time each section of code uses
  87. </li></ul>
  88. <p>Once you know these things about how your code works when compiled, you
  89. can look at each module to see which modules should be optimized.
  90. <code>gcov</code> helps you determine where to work on optimization.
  91. </p>
  92. <p>Software developers also use coverage testing in concert with
  93. testsuites, to make sure software is actually good enough for a release.
  94. Testsuites can verify that a program works as expected; a coverage
  95. program tests to see how much of the program is exercised by the
  96. testsuite. Developers can then determine what kinds of test cases need
  97. to be added to the testsuites to create both better testing and a better
  98. final product.
  99. </p>
  100. <p>You should compile your code without optimization if you plan to use
  101. <code>gcov</code> because the optimization, by combining some lines of code
  102. into one function, may not give you as much information as you need to
  103. look for &lsquo;hot spots&rsquo; where the code is using a great deal of computer
  104. time. Likewise, because <code>gcov</code> accumulates statistics by line (at
  105. the lowest resolution), it works best with a programming style that
  106. places only one statement on each line. If you use complicated macros
  107. that expand to loops or to other control structures, the statistics are
  108. less helpful&mdash;they only report on the line where the macro call
  109. appears. If your complex macros behave like functions, you can replace
  110. them with inline functions to solve this problem.
  111. </p>
  112. <p><code>gcov</code> creates a logfile called <samp><var>sourcefile</var>.gcov</samp> which
  113. indicates how many times each line of a source file <samp><var>sourcefile</var>.c</samp>
  114. has executed. You can use these logfiles along with <code>gprof</code> to aid
  115. in fine-tuning the performance of your programs. <code>gprof</code> gives
  116. timing information you can use along with the information you get from
  117. <code>gcov</code>.
  118. </p>
  119. <p><code>gcov</code> works only on code compiled with GCC. It is not
  120. compatible with any other profiling or test coverage mechanism.
  121. </p>
  122. <hr>
  123. <div class="header">
  124. <p>
  125. Next: <a href="Invoking-Gcov.html#Invoking-Gcov" accesskey="n" rel="next">Invoking Gcov</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>
  126. </div>
  127. </body>
  128. </html>