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