llvm-cov.rst 15 KB

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