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