llvm-cov.rst 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. llvm-cov - emit coverage information
  2. ====================================
  3. SYNOPSIS
  4. --------
  5. :program:`llvm-cov` *command* [*args...*]
  6. DESCRIPTION
  7. -----------
  8. The :program:`llvm-cov` tool shows code coverage information for
  9. programs that are instrumented to emit profile data. It can be used to
  10. work with ``gcov``\-style coverage or with ``clang``\'s instrumentation
  11. based profiling.
  12. If the program is invoked with a base name of ``gcov``, it will behave as if
  13. the :program:`llvm-cov gcov` command were called. Otherwise, a command should
  14. be provided.
  15. COMMANDS
  16. --------
  17. * :ref:`gcov <llvm-cov-gcov>`
  18. * :ref:`show <llvm-cov-show>`
  19. * :ref:`report <llvm-cov-report>`
  20. .. program:: llvm-cov gcov
  21. .. _llvm-cov-gcov:
  22. GCOV COMMAND
  23. ------------
  24. SYNOPSIS
  25. ^^^^^^^^
  26. :program:`llvm-cov gcov` [*options*] *SOURCEFILE*
  27. DESCRIPTION
  28. ^^^^^^^^^^^
  29. The :program:`llvm-cov gcov` tool reads code coverage data files and displays
  30. the coverage information for a specified source file. It is compatible with the
  31. ``gcov`` tool from version 4.2 of ``GCC`` and may also be compatible with some
  32. later versions of ``gcov``.
  33. To use :program:`llvm-cov gcov`, you must first build an instrumented version
  34. of your application that collects coverage data as it runs. Compile with the
  35. ``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
  36. instrumentation. (Alternatively, you can use the ``--coverage`` option, which
  37. includes both of those other options.) You should compile with debugging
  38. information (``-g``) and without optimization (``-O0``); otherwise, the
  39. coverage data cannot be accurately mapped back to the source code.
  40. At the time you compile the instrumented code, a ``.gcno`` data file will be
  41. generated for each object file. These ``.gcno`` files contain half of the
  42. coverage data. The other half of the data comes from ``.gcda`` files that are
  43. generated when you run the instrumented program, with a separate ``.gcda``
  44. file for each object file. Each time you run the program, the execution counts
  45. are summed into any existing ``.gcda`` files, so be sure to remove any old
  46. files if you do not want their contents to be included.
  47. By default, the ``.gcda`` files are written into the same directory as the
  48. object files, but you can override that by setting the ``GCOV_PREFIX`` and
  49. ``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
  50. variable specifies a number of directory components to be removed from the
  51. start of the absolute path to the object file directory. After stripping those
  52. directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
  53. environment variables allow you to run the instrumented program on a machine
  54. where the original object file directories are not accessible, but you will
  55. then need to copy the ``.gcda`` files back to the object file directories
  56. where :program:`llvm-cov gcov` expects to find them.
  57. Once you have generated the coverage data files, run :program:`llvm-cov gcov`
  58. for each main source file where you want to examine the coverage results. This
  59. should be run from the same directory where you previously ran the
  60. compiler. The results for the specified source file are written to a file named
  61. by appending a ``.gcov`` suffix. A separate output file is also created for
  62. each file included by the main source file, also with a ``.gcov`` suffix added.
  63. The basic content of an ``.gcov`` output file is a copy of the source file with
  64. an execution count and line number prepended to every line. The execution
  65. count is shown as ``-`` if a line does not contain any executable code. If
  66. a line contains code but that code was never executed, the count is displayed
  67. as ``#####``.
  68. OPTIONS
  69. ^^^^^^^
  70. .. option:: -a, --all-blocks
  71. Display all basic blocks. If there are multiple blocks for a single line of
  72. source code, this option causes llvm-cov to show the count for each block
  73. instead of just one count for the entire line.
  74. .. option:: -b, --branch-probabilities
  75. Display conditional branch probabilities and a summary of branch information.
  76. .. option:: -c, --branch-counts
  77. Display branch counts instead of probabilities (requires -b).
  78. .. option:: -f, --function-summaries
  79. Show a summary of coverage for each function instead of just one summary for
  80. an entire source file.
  81. .. option:: --help
  82. Display available options (--help-hidden for more).
  83. .. option:: -l, --long-file-names
  84. For coverage output of files included from the main source file, add the
  85. main file name followed by ``##`` as a prefix to the output file names. This
  86. can be combined with the --preserve-paths option to use complete paths for
  87. both the main file and the included file.
  88. .. option:: -n, --no-output
  89. Do not output any ``.gcov`` files. Summary information is still
  90. displayed.
  91. .. option:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
  92. Find objects in DIR or based on FILE's path. If you specify a particular
  93. object file, the coverage data files are expected to have the same base name
  94. with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
  95. files are expected in that directory with the same base name as the source
  96. file.
  97. .. option:: -p, --preserve-paths
  98. Preserve path components when naming the coverage output files. In addition
  99. to the source file name, include the directories from the path to that
  100. file. The directories are separate by ``#`` characters, with ``.`` directories
  101. removed and ``..`` directories replaced by ``^`` characters. When used with
  102. the --long-file-names option, this applies to both the main file name and the
  103. included file name.
  104. .. option:: -u, --unconditional-branches
  105. Include unconditional branches in the output for the --branch-probabilities
  106. option.
  107. .. option:: -version
  108. Display the version of llvm-cov.
  109. EXIT STATUS
  110. ^^^^^^^^^^^
  111. :program:`llvm-cov gcov` returns 1 if it cannot read input files. Otherwise,
  112. it exits with zero.
  113. .. program:: llvm-cov show
  114. .. _llvm-cov-show:
  115. SHOW COMMAND
  116. ------------
  117. SYNOPSIS
  118. ^^^^^^^^
  119. :program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
  120. DESCRIPTION
  121. ^^^^^^^^^^^
  122. The :program:`llvm-cov show` command shows line by line coverage of a binary
  123. *BIN* using the profile data *PROFILE*. It can optionally be filtered to only
  124. show the coverage for the files listed in *SOURCES*.
  125. To use :program:`llvm-cov show`, you need a program that is compiled with
  126. instrumentation to emit profile and coverage data. To build such a program with
  127. ``clang`` use the ``-fprofile-instr-generate`` and ``-fcoverage-mapping``
  128. flags. If linking with the ``clang`` driver, pass ``-fprofile-instr-generate``
  129. to the link stage to make sure the necessary runtime libraries are linked in.
  130. The coverage information is stored in the built executable or library itself,
  131. and this is what you should pass to :program:`llvm-cov show` as the *BIN*
  132. argument. The profile data is generated by running this instrumented program
  133. normally. When the program exits it will write out a raw profile file,
  134. typically called ``default.profraw``, which can be converted to a format that
  135. is suitable for the *PROFILE* argument using the :program:`llvm-profdata merge`
  136. tool.
  137. OPTIONS
  138. ^^^^^^^
  139. .. option:: -show-line-counts
  140. Show the execution counts for each line. This is enabled by default, unless
  141. another ``-show`` option is used.
  142. .. option:: -show-expansions
  143. Expand inclusions, such as preprocessor macros or textual inclusions, inline
  144. in the display of the source file.
  145. .. option:: -show-instantiations
  146. For source regions that are instantiated multiple times, such as templates in
  147. ``C++``, show each instantiation separately as well as the combined summary.
  148. .. option:: -show-regions
  149. Show the execution counts for each region by displaying a caret that points to
  150. the character where the region starts.
  151. .. option:: -show-line-counts-or-regions
  152. Show the execution counts for each line if there is only one region on the
  153. line, but show the individual regions if there are multiple on the line.
  154. .. option:: -use-color[=VALUE]
  155. Enable or disable color output. By default this is autodetected.
  156. .. option:: -arch=<name>
  157. If the covered binary is a universal binary, select the architecture to use.
  158. It is an error to specify an architecture that is not included in the
  159. universal binary or to use an architecture that does not match a
  160. non-universal binary.
  161. .. option:: -name=<NAME>
  162. Show code coverage only for functions with the given name.
  163. .. option:: -name-regex=<PATTERN>
  164. Show code coverage only for functions that match the given regular expression.
  165. .. option:: -line-coverage-gt=<N>
  166. Show code coverage only for functions with line coverage greater than the
  167. given threshold.
  168. .. option:: -line-coverage-lt=<N>
  169. Show code coverage only for functions with line coverage less than the given
  170. threshold.
  171. .. option:: -region-coverage-gt=<N>
  172. Show code coverage only for functions with region coverage greater than the
  173. given threshold.
  174. .. option:: -region-coverage-lt=<N>
  175. Show code coverage only for functions with region coverage less than the given
  176. threshold.
  177. .. program:: llvm-cov report
  178. .. _llvm-cov-report:
  179. REPORT COMMAND
  180. --------------
  181. SYNOPSIS
  182. ^^^^^^^^
  183. :program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
  184. DESCRIPTION
  185. ^^^^^^^^^^^
  186. The :program:`llvm-cov report` command displays a summary of the coverage of a
  187. binary *BIN* using the profile data *PROFILE*. It can optionally be filtered to
  188. only show the coverage for the files listed in *SOURCES*.
  189. If no source files are provided, a summary line is printed for each file in the
  190. coverage data. If any files are provided, summaries are shown for each function
  191. in the listed files instead.
  192. For information on compiling programs for coverage and generating profile data,
  193. see :ref:`llvm-cov-show`.
  194. OPTIONS
  195. ^^^^^^^
  196. .. option:: -use-color[=VALUE]
  197. Enable or disable color output. By default this is autodetected.
  198. .. option:: -arch=<name>
  199. If the covered binary is a universal binary, select the architecture to use.
  200. It is an error to specify an architecture that is not included in the
  201. universal binary or to use an architecture that does not match a
  202. non-universal binary.