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.) 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:: -m, --demangled-names 107 108 Demangle function names. 109 110.. option:: -f, --function-summaries 111 112 Show a summary of coverage for each function instead of just one summary for 113 an entire source file. 114 115.. option:: --help 116 117 Display available options (--help-hidden for more). 118 119.. option:: -l, --long-file-names 120 121 For coverage output of files included from the main source file, add the 122 main file name followed by ``##`` as a prefix to the output file names. This 123 can be combined with the --preserve-paths option to use complete paths for 124 both the main file and the included file. 125 126.. option:: -n, --no-output 127 128 Do not output any ``.gcov`` files. Summary information is still 129 displayed. 130 131.. option:: -o <DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE> 132 133 Find objects in DIR or based on FILE's path. If you specify a particular 134 object file, the coverage data files are expected to have the same base name 135 with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the 136 files are expected in that directory with the same base name as the source 137 file. 138 139.. option:: -p, --preserve-paths 140 141 Preserve path components when naming the coverage output files. In addition 142 to the source file name, include the directories from the path to that 143 file. The directories are separate by ``#`` characters, with ``.`` directories 144 removed and ``..`` directories replaced by ``^`` characters. When used with 145 the --long-file-names option, this applies to both the main file name and the 146 included file name. 147 148.. option:: -r 149 150 Only dump files with relative paths or absolute paths with the prefix specified 151 by ``-s``. 152 153.. option:: -s <string> 154 155 Source prefix to elide. 156 157.. option:: -t, --stdout 158 159 Print to stdout instead of producing ``.gcov`` files. 160 161.. option:: -u, --unconditional-branches 162 163 Include unconditional branches in the output for the --branch-probabilities 164 option. 165 166.. option:: -version 167 168 Display the version of llvm-cov. 169 170.. option:: -x, --hash-filenames 171 172 Use md5 hash of file name when naming the coverage output files. The source 173 file name will be suffixed by ``##`` followed by MD5 hash calculated for it. 174 175EXIT STATUS 176^^^^^^^^^^^ 177 178:program:`llvm-cov gcov` returns 1 if it cannot read input files. Otherwise, 179it exits with zero. 180 181.. program:: llvm-cov show 182 183.. _llvm-cov-show: 184 185SHOW COMMAND 186------------ 187 188SYNOPSIS 189^^^^^^^^ 190 191:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*] 192 193DESCRIPTION 194^^^^^^^^^^^ 195 196The :program:`llvm-cov show` command shows line by line coverage of the 197binaries *BIN*,... using the profile data *PROFILE*. It can optionally be 198filtered to only show the coverage for the files listed in *SOURCES*. 199 200*BIN* may be an executable, object file, dynamic library, or archive (thin or 201otherwise). 202 203To use :program:`llvm-cov show`, you need a program that is compiled with 204instrumentation to emit profile and coverage data. To build such a program with 205``clang`` use the ``-fprofile-instr-generate`` and ``-fcoverage-mapping`` 206flags. If linking with the ``clang`` driver, pass ``-fprofile-instr-generate`` 207to the link stage to make sure the necessary runtime libraries are linked in. 208 209The coverage information is stored in the built executable or library itself, 210and this is what you should pass to :program:`llvm-cov show` as a *BIN* 211argument. The profile data is generated by running this instrumented program 212normally. When the program exits it will write out a raw profile file, 213typically called ``default.profraw``, which can be converted to a format that 214is suitable for the *PROFILE* argument using the :program:`llvm-profdata merge` 215tool. 216 217OPTIONS 218^^^^^^^ 219 220.. option:: -show-branches=<VIEW> 221 222 Show coverage for branch conditions in terms of either count or percentage. 223 The supported views are: "count", "percent". 224 225.. option:: -show-line-counts 226 227 Show the execution counts for each line. Defaults to true, unless another 228 ``-show`` option is used. 229 230.. option:: -show-expansions 231 232 Expand inclusions, such as preprocessor macros or textual inclusions, inline 233 in the display of the source file. Defaults to false. 234 235.. option:: -show-instantiations 236 237 For source regions that are instantiated multiple times, such as templates in 238 ``C++``, show each instantiation separately as well as the combined summary. 239 Defaults to true. 240 241.. option:: -show-regions 242 243 Show the execution counts for each region by displaying a caret that points to 244 the character where the region starts. Defaults to false. 245 246.. option:: -show-line-counts-or-regions 247 248 Show the execution counts for each line if there is only one region on the 249 line, but show the individual regions if there are multiple on the line. 250 Defaults to false. 251 252.. option:: -use-color 253 254 Enable or disable color output. By default this is autodetected. 255 256.. option:: -arch=[*NAMES*] 257 258 Specify a list of architectures such that the Nth entry in the list 259 corresponds to the Nth specified binary. If the covered object is a universal 260 binary, this specifies the architecture to use. It is an error to specify an 261 architecture that is not included in the universal binary or to use an 262 architecture that does not match a non-universal binary. 263 264.. option:: -name=<NAME> 265 266 Show code coverage only for functions with the given name. 267 268.. option:: -name-allowlist=<FILE> 269 270 Show code coverage only for functions listed in the given file. Each line in 271 the file should start with `allowlist_fun:`, immediately followed by the name 272 of the function to accept. This name can be a wildcard expression. 273 274.. option:: -name-whitelist=<FILE> 275 276 Show code coverage only for functions listed in the given file. Each line in 277 the file should start with `whitelist_fun:`, immediately followed by the name 278 of the function to accept. This name can be a wildcard expression. This option 279 will be deprecated for `-name-allowlist=<FILE>` in future releases. 280 281.. option:: -name-regex=<PATTERN> 282 283 Show code coverage only for functions that match the given regular expression. 284 285.. option:: -ignore-filename-regex=<PATTERN> 286 287 Skip source code files with file paths that match the given regular expression. 288 289.. option:: -format=<FORMAT> 290 291 Use the specified output format. The supported formats are: "text", "html". 292 293.. option:: -tab-size=<TABSIZE> 294 295 Replace tabs with <TABSIZE> spaces when preparing reports. Currently, this is 296 only supported for the html format. 297 298.. option:: -output-dir=PATH 299 300 Specify a directory to write coverage reports into. If the directory does not 301 exist, it is created. When used in function view mode (i.e when -name or 302 -name-regex are used to select specific functions), the report is written to 303 PATH/functions.EXTENSION. When used in file view mode, a report for each file 304 is written to PATH/REL_PATH_TO_FILE.EXTENSION. 305 306.. option:: -Xdemangler=<TOOL>|<TOOL-OPTION> 307 308 Specify a symbol demangler. This can be used to make reports more 309 human-readable. This option can be specified multiple times to supply 310 arguments to the demangler (e.g `-Xdemangler c++filt -Xdemangler -n` for C++). 311 The demangler is expected to read a newline-separated list of symbols from 312 stdin and write a newline-separated list of the same length to stdout. 313 314.. option:: -num-threads=N, -j=N 315 316 Use N threads to write file reports (only applicable when -output-dir is 317 specified). When N=0, llvm-cov auto-detects an appropriate number of threads to 318 use. This is the default. 319 320.. option:: -compilation-dir=<dir> 321 322 Directory used as a base for relative coverage mapping paths. Only applicable 323 when binaries have been compiled with one of `-fcoverage-prefix-map` 324 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`. 325 326.. option:: -line-coverage-gt=<N> 327 328 Show code coverage only for functions with line coverage greater than the 329 given threshold. 330 331.. option:: -line-coverage-lt=<N> 332 333 Show code coverage only for functions with line coverage less than the given 334 threshold. 335 336.. option:: -region-coverage-gt=<N> 337 338 Show code coverage only for functions with region coverage greater than the 339 given threshold. 340 341.. option:: -region-coverage-lt=<N> 342 343 Show code coverage only for functions with region coverage less than the given 344 threshold. 345 346.. option:: -path-equivalence=<from>,<to> 347 348 Map the paths in the coverage data to local source file paths. This allows you 349 to generate the coverage data on one machine, and then use llvm-cov on a 350 different machine where you have the same files on a different path. 351 352.. option:: -coverage-watermark=<high>,<low> 353 354 Set high and low watermarks for coverage in html format output. This allows you 355 to set the high and low watermark of coverage as desired, green when 356 coverage >= high, red when coverage < low, and yellow otherwise. Both high and 357 low should be between 0-100 and high > low. 358 359.. program:: llvm-cov report 360 361.. _llvm-cov-report: 362 363REPORT COMMAND 364-------------- 365 366SYNOPSIS 367^^^^^^^^ 368 369:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*] 370 371DESCRIPTION 372^^^^^^^^^^^ 373 374The :program:`llvm-cov report` command displays a summary of the coverage of 375the binaries *BIN*,... using the profile data *PROFILE*. It can optionally be 376filtered to only show the coverage for the files listed in *SOURCES*. 377 378*BIN* may be an executable, object file, dynamic library, or archive (thin or 379otherwise). 380 381If no source files are provided, a summary line is printed for each file in the 382coverage data. If any files are provided, summaries can be shown for each 383function in the listed files if the ``-show-functions`` option is enabled. 384 385For information on compiling programs for coverage and generating profile data, 386see :ref:`llvm-cov-show`. 387 388OPTIONS 389^^^^^^^ 390 391.. option:: -use-color[=VALUE] 392 393 Enable or disable color output. By default this is autodetected. 394 395.. option:: -arch=<name> 396 397 If the covered binary is a universal binary, select the architecture to use. 398 It is an error to specify an architecture that is not included in the 399 universal binary or to use an architecture that does not match a 400 non-universal binary. 401 402.. option:: -show-region-summary 403 404 Show statistics for all regions. Defaults to true. 405 406.. option:: -show-branch-summary 407 408 Show statistics for all branch conditions. Defaults to true. 409 410.. option:: -show-functions 411 412 Show coverage summaries for each function. Defaults to false. 413 414.. option:: -show-instantiation-summary 415 416 Show statistics for all function instantiations. Defaults to false. 417 418.. option:: -ignore-filename-regex=<PATTERN> 419 420 Skip source code files with file paths that match the given regular expression. 421 422.. option:: -compilation-dir=<dir> 423 424 Directory used as a base for relative coverage mapping paths. Only applicable 425 when binaries have been compiled with one of `-fcoverage-prefix-map` 426 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`. 427 428.. program:: llvm-cov export 429 430.. _llvm-cov-export: 431 432EXPORT COMMAND 433-------------- 434 435SYNOPSIS 436^^^^^^^^ 437 438:program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*] 439 440DESCRIPTION 441^^^^^^^^^^^ 442 443The :program:`llvm-cov export` command exports coverage data of the binaries 444*BIN*,... using the profile data *PROFILE* in either JSON or lcov trace file 445format. 446 447When exporting JSON, the regions, functions, branches, expansions, and 448summaries of the coverage data will be exported. When exporting an lcov trace 449file, the line-based coverage, branch coverage, and summaries will be exported. 450 451The exported data can optionally be filtered to only export the coverage 452for the files listed in *SOURCES*. 453 454For information on compiling programs for coverage and generating profile data, 455see :ref:`llvm-cov-show`. 456 457OPTIONS 458^^^^^^^ 459 460.. option:: -arch=<name> 461 462 If the covered binary is a universal binary, select the architecture to use. 463 It is an error to specify an architecture that is not included in the 464 universal binary or to use an architecture that does not match a 465 non-universal binary. 466 467.. option:: -format=<FORMAT> 468 469 Use the specified output format. The supported formats are: "text" (JSON), 470 "lcov". 471 472.. option:: -summary-only 473 474 Export only summary information for each file in the coverage data. This mode 475 will not export coverage information for smaller units such as individual 476 functions or regions. The result will contain the same information as produced 477 by the :program:`llvm-cov report` command, but presented in JSON or lcov 478 format rather than text. 479 480.. option:: -ignore-filename-regex=<PATTERN> 481 482 Skip source code files with file paths that match the given regular expression. 483 484 .. option:: -skip-expansions 485 486 Skip exporting macro expansion coverage data. 487 488 .. option:: -skip-functions 489 490 Skip exporting per-function coverage data. 491 492 .. option:: -num-threads=N, -j=N 493 494 Use N threads to export coverage data. When N=0, llvm-cov auto-detects an 495 appropriate number of threads to use. This is the default. 496 497.. option:: -compilation-dir=<dir> 498 499 Directory used as a base for relative coverage mapping paths. Only applicable 500 when binaries have been compiled with one of `-fcoverage-prefix-map` 501 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`. 502