llvm-cov.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. * :ref:`export <llvm-cov-export>`
  21. .. program:: llvm-cov gcov
  22. .. _llvm-cov-gcov:
  23. GCOV COMMAND
  24. ------------
  25. SYNOPSIS
  26. ^^^^^^^^
  27. :program:`llvm-cov gcov` [*options*] *SOURCEFILE*
  28. DESCRIPTION
  29. ^^^^^^^^^^^
  30. The :program:`llvm-cov gcov` tool reads code coverage data files and displays
  31. the coverage information for a specified source file. It is compatible with the
  32. ``gcov`` tool from version 4.2 of ``GCC`` and may also be compatible with some
  33. later versions of ``gcov``.
  34. To use :program:`llvm-cov gcov`, you must first build an instrumented version
  35. of your application that collects coverage data as it runs. Compile with the
  36. ``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
  37. instrumentation. (Alternatively, you can use the ``--coverage`` option, which
  38. includes both of those other options.) You should compile with debugging
  39. information (``-g``) and without optimization (``-O0``); otherwise, the
  40. coverage data cannot be accurately mapped back to the source code.
  41. At the time you compile the instrumented code, a ``.gcno`` data file will be
  42. generated for each object file. These ``.gcno`` files contain half of the
  43. coverage data. The other half of the data comes from ``.gcda`` files that are
  44. generated when you run the instrumented program, with a separate ``.gcda``
  45. file for each object file. Each time you run the program, the execution counts
  46. are summed into any existing ``.gcda`` files, so be sure to remove any old
  47. files if you do not want their contents to be included.
  48. By default, the ``.gcda`` files are written into the same directory as the
  49. object files, but you can override that by setting the ``GCOV_PREFIX`` and
  50. ``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
  51. variable specifies a number of directory components to be removed from the
  52. start of the absolute path to the object file directory. After stripping those
  53. directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
  54. environment variables allow you to run the instrumented program on a machine
  55. where the original object file directories are not accessible, but you will
  56. then need to copy the ``.gcda`` files back to the object file directories
  57. where :program:`llvm-cov gcov` expects to find them.
  58. Once you have generated the coverage data files, run :program:`llvm-cov gcov`
  59. for each main source file where you want to examine the coverage results. This
  60. should be run from the same directory where you previously ran the
  61. compiler. The results for the specified source file are written to a file named
  62. by appending a ``.gcov`` suffix. A separate output file is also created for
  63. each file included by the main source file, also with a ``.gcov`` suffix added.
  64. The basic content of an ``.gcov`` output file is a copy of the source file with
  65. an execution count and line number prepended to every line. The execution
  66. count is shown as ``-`` if a line does not contain any executable code. If
  67. a line contains code but that code was never executed, the count is displayed
  68. as ``#####``.
  69. OPTIONS
  70. ^^^^^^^
  71. .. option:: -a, --all-blocks
  72. Display all basic blocks. If there are multiple blocks for a single line of
  73. source code, this option causes llvm-cov to show the count for each block
  74. instead of just one count for the entire line.
  75. .. option:: -b, --branch-probabilities
  76. Display conditional branch probabilities and a summary of branch information.
  77. .. option:: -c, --branch-counts
  78. Display branch counts instead of probabilities (requires -b).
  79. .. option:: -f, --function-summaries
  80. Show a summary of coverage for each function instead of just one summary for
  81. an entire source file.
  82. .. option:: --help
  83. Display available options (--help-hidden for more).
  84. .. option:: -l, --long-file-names
  85. For coverage output of files included from the main source file, add the
  86. main file name followed by ``##`` as a prefix to the output file names. This
  87. can be combined with the --preserve-paths option to use complete paths for
  88. both the main file and the included file.
  89. .. option:: -n, --no-output
  90. Do not output any ``.gcov`` files. Summary information is still
  91. displayed.
  92. .. option:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
  93. Find objects in DIR or based on FILE's path. If you specify a particular
  94. object file, the coverage data files are expected to have the same base name
  95. with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
  96. files are expected in that directory with the same base name as the source
  97. file.
  98. .. option:: -p, --preserve-paths
  99. Preserve path components when naming the coverage output files. In addition
  100. to the source file name, include the directories from the path to that
  101. file. The directories are separate by ``#`` characters, with ``.`` directories
  102. removed and ``..`` directories replaced by ``^`` characters. When used with
  103. the --long-file-names option, this applies to both the main file name and the
  104. included file name.
  105. .. option:: -u, --unconditional-branches
  106. Include unconditional branches in the output for the --branch-probabilities
  107. option.
  108. .. option:: -version
  109. Display the version of llvm-cov.
  110. EXIT STATUS
  111. ^^^^^^^^^^^
  112. :program:`llvm-cov gcov` returns 1 if it cannot read input files. Otherwise,
  113. it exits with zero.
  114. .. program:: llvm-cov show
  115. .. _llvm-cov-show:
  116. SHOW COMMAND
  117. ------------
  118. SYNOPSIS
  119. ^^^^^^^^
  120. :program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
  121. DESCRIPTION
  122. ^^^^^^^^^^^
  123. The :program:`llvm-cov show` command shows line by line coverage of the
  124. binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
  125. filtered to only show the coverage for the files listed in *SOURCES*.
  126. To use :program:`llvm-cov show`, you need a program that is compiled with
  127. instrumentation to emit profile and coverage data. To build such a program with
  128. ``clang`` use the ``-fprofile-instr-generate`` and ``-fcoverage-mapping``
  129. flags. If linking with the ``clang`` driver, pass ``-fprofile-instr-generate``
  130. to the link stage to make sure the necessary runtime libraries are linked in.
  131. The coverage information is stored in the built executable or library itself,
  132. and this is what you should pass to :program:`llvm-cov show` as a *BIN*
  133. argument. The profile data is generated by running this instrumented program
  134. normally. When the program exits it will write out a raw profile file,
  135. typically called ``default.profraw``, which can be converted to a format that
  136. is suitable for the *PROFILE* argument using the :program:`llvm-profdata merge`
  137. tool.
  138. OPTIONS
  139. ^^^^^^^
  140. .. option:: -show-line-counts
  141. Show the execution counts for each line. Defaults to true, unless another
  142. ``-show`` option is used.
  143. .. option:: -show-expansions
  144. Expand inclusions, such as preprocessor macros or textual inclusions, inline
  145. in the display of the source file. Defaults to false.
  146. .. option:: -show-instantiations
  147. For source regions that are instantiated multiple times, such as templates in
  148. ``C++``, show each instantiation separately as well as the combined summary.
  149. Defaults to true.
  150. .. option:: -show-regions
  151. Show the execution counts for each region by displaying a caret that points to
  152. the character where the region starts. Defaults to false.
  153. .. option:: -show-line-counts-or-regions
  154. Show the execution counts for each line if there is only one region on the
  155. line, but show the individual regions if there are multiple on the line.
  156. Defaults to false.
  157. .. option:: -use-color
  158. Enable or disable color output. By default this is autodetected.
  159. .. option:: -arch=[*NAMES*]
  160. Specify a list of architectures such that the Nth entry in the list
  161. corresponds to the Nth specified binary. If the covered object is a universal
  162. binary, this specifies the architecture to use. It is an error to specify an
  163. architecture that is not included in the universal binary or to use an
  164. architecture that does not match a non-universal binary.
  165. .. option:: -name=<NAME>
  166. Show code coverage only for functions with the given name.
  167. .. option:: -name-whitelist=<FILE>
  168. Show code coverage only for functions listed in the given file. Each line in
  169. the file should start with `whitelist_fun:`, immediately followed by the name
  170. of the function to accept. This name can be a wildcard expression.
  171. .. option:: -name-regex=<PATTERN>
  172. Show code coverage only for functions that match the given regular expression.
  173. .. option:: -ignore-filename-regex=<PATTERN>
  174. Skip source code files with file paths that match the given regular expression.
  175. .. option:: -format=<FORMAT>
  176. Use the specified output format. The supported formats are: "text", "html".
  177. .. option:: -tab-size=<TABSIZE>
  178. Replace tabs with <TABSIZE> spaces when preparing reports. Currently, this is
  179. only supported for the html format.
  180. .. option:: -output-dir=PATH
  181. Specify a directory to write coverage reports into. If the directory does not
  182. exist, it is created. When used in function view mode (i.e when -name or
  183. -name-regex are used to select specific functions), the report is written to
  184. PATH/functions.EXTENSION. When used in file view mode, a report for each file
  185. is written to PATH/REL_PATH_TO_FILE.EXTENSION.
  186. .. option:: -Xdemangler=<TOOL>|<TOOL-OPTION>
  187. Specify a symbol demangler. This can be used to make reports more
  188. human-readable. This option can be specified multiple times to supply
  189. arguments to the demangler (e.g `-Xdemangler c++filt -Xdemangler -n` for C++).
  190. The demangler is expected to read a newline-separated list of symbols from
  191. stdin and write a newline-separated list of the same length to stdout.
  192. .. option:: -num-threads=N, -j=N
  193. Use N threads to write file reports (only applicable when -output-dir is
  194. specified). When N=0, llvm-cov auto-detects an appropriate number of threads to
  195. use. This is the default.
  196. .. option:: -line-coverage-gt=<N>
  197. Show code coverage only for functions with line coverage greater than the
  198. given threshold.
  199. .. option:: -line-coverage-lt=<N>
  200. Show code coverage only for functions with line coverage less than the given
  201. threshold.
  202. .. option:: -region-coverage-gt=<N>
  203. Show code coverage only for functions with region coverage greater than the
  204. given threshold.
  205. .. option:: -region-coverage-lt=<N>
  206. Show code coverage only for functions with region coverage less than the given
  207. threshold.
  208. .. option:: -path-equivalence=<from>,<to>
  209. Map the paths in the coverage data to local source file paths. This allows you
  210. to generate the coverage data on one machine, and then use llvm-cov on a
  211. different machine where you have the same files on a different path.
  212. .. program:: llvm-cov report
  213. .. _llvm-cov-report:
  214. REPORT COMMAND
  215. --------------
  216. SYNOPSIS
  217. ^^^^^^^^
  218. :program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
  219. DESCRIPTION
  220. ^^^^^^^^^^^
  221. The :program:`llvm-cov report` command displays a summary of the coverage of
  222. the binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
  223. filtered to only show the coverage for the files listed in *SOURCES*.
  224. If no source files are provided, a summary line is printed for each file in the
  225. coverage data. If any files are provided, summaries can be shown for each
  226. function in the listed files if the ``-show-functions`` option is enabled.
  227. For information on compiling programs for coverage and generating profile data,
  228. see :ref:`llvm-cov-show`.
  229. OPTIONS
  230. ^^^^^^^
  231. .. option:: -use-color[=VALUE]
  232. Enable or disable color output. By default this is autodetected.
  233. .. option:: -arch=<name>
  234. If the covered binary is a universal binary, select the architecture to use.
  235. It is an error to specify an architecture that is not included in the
  236. universal binary or to use an architecture that does not match a
  237. non-universal binary.
  238. .. option:: -show-functions
  239. Show coverage summaries for each function. Defaults to false.
  240. .. option:: -show-instantiation-summary
  241. Show statistics for all function instantiations. Defaults to false.
  242. .. option:: -ignore-filename-regex=<PATTERN>
  243. Skip source code files with file paths that match the given regular expression.
  244. .. program:: llvm-cov export
  245. .. _llvm-cov-export:
  246. EXPORT COMMAND
  247. --------------
  248. SYNOPSIS
  249. ^^^^^^^^
  250. :program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
  251. DESCRIPTION
  252. ^^^^^^^^^^^
  253. The :program:`llvm-cov export` command exports regions, functions, expansions,
  254. and summaries of the coverage of the binaries *BIN*,... using the profile data
  255. *PROFILE* as JSON. It can optionally be filtered to only export the coverage
  256. for the files listed in *SOURCES*.
  257. For information on compiling programs for coverage and generating profile data,
  258. see :ref:`llvm-cov-show`.
  259. OPTIONS
  260. ^^^^^^^
  261. .. option:: -arch=<name>
  262. If the covered binary is a universal binary, select the architecture to use.
  263. It is an error to specify an architecture that is not included in the
  264. universal binary or to use an architecture that does not match a
  265. non-universal binary.
  266. .. option:: -summary-only
  267. Export only summary information for each file in the coverage data. This mode
  268. will not export coverage information for smaller units such as individual
  269. functions or regions. The result will be the same as produced by :program:
  270. `llvm-cov report` command, but presented in JSON format rather than text.
  271. .. option:: -ignore-filename-regex=<PATTERN>
  272. Skip source code files with file paths that match the given regular expression.