您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

145 行
6.4KB

  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>Gcov Intro (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Gcov Intro (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Gcov Intro (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="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.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="Gcov-Intro"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Introduction-to-gcov"></a>
  68. <h3 class="section">10.1 Introduction to <code>gcov</code></h3>
  69. <p><code>gcov</code> is a test coverage program. Use it in concert with GCC
  70. to analyze your programs to help create more efficient, faster running
  71. code and to discover untested parts of your program. You can use
  72. <code>gcov</code> as a profiling tool to help discover where your
  73. optimization efforts will best affect your code. You can also use
  74. <code>gcov</code> along with the other profiling tool, <code>gprof</code>, to
  75. assess which parts of your code use the greatest amount of computing
  76. time.
  77. </p>
  78. <p>Profiling tools help you analyze your code&rsquo;s performance. Using a
  79. profiler such as <code>gcov</code> or <code>gprof</code>, you can find out some
  80. basic performance statistics, such as:
  81. </p>
  82. <ul>
  83. <li> how often each line of code executes
  84. </li><li> what lines of code are actually executed
  85. </li><li> how much computing time each section of code uses
  86. </li></ul>
  87. <p>Once you know these things about how your code works when compiled, you
  88. can look at each module to see which modules should be optimized.
  89. <code>gcov</code> helps you determine where to work on optimization.
  90. </p>
  91. <p>Software developers also use coverage testing in concert with
  92. testsuites, to make sure software is actually good enough for a release.
  93. Testsuites can verify that a program works as expected; a coverage
  94. program tests to see how much of the program is exercised by the
  95. testsuite. Developers can then determine what kinds of test cases need
  96. to be added to the testsuites to create both better testing and a better
  97. final product.
  98. </p>
  99. <p>You should compile your code without optimization if you plan to use
  100. <code>gcov</code> because the optimization, by combining some lines of code
  101. into one function, may not give you as much information as you need to
  102. look for &lsquo;hot spots&rsquo; where the code is using a great deal of computer
  103. time. Likewise, because <code>gcov</code> accumulates statistics by line (at
  104. the lowest resolution), it works best with a programming style that
  105. places only one statement on each line. If you use complicated macros
  106. that expand to loops or to other control structures, the statistics are
  107. less helpful&mdash;they only report on the line where the macro call
  108. appears. If your complex macros behave like functions, you can replace
  109. them with inline functions to solve this problem.
  110. </p>
  111. <p><code>gcov</code> creates a logfile called <samp><var>sourcefile</var>.gcov</samp> which
  112. indicates how many times each line of a source file <samp><var>sourcefile</var>.c</samp>
  113. has executed. You can use these logfiles along with <code>gprof</code> to aid
  114. in fine-tuning the performance of your programs. <code>gprof</code> gives
  115. timing information you can use along with the information you get from
  116. <code>gcov</code>.
  117. </p>
  118. <p><code>gcov</code> works only on code compiled with GCC. It is not
  119. compatible with any other profiling or test coverage mechanism.
  120. </p>
  121. <hr>
  122. <div class="header">
  123. <p>
  124. 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>
  125. </div>
  126. </body>
  127. </html>