• Home
  • Raw
  • Download

Lines Matching +full:clang +full:- +full:format +full:- +full:3

2 Source-based Code Coverage
11 This document explains how to use clang's source-based code coverage feature.
12 It's called "source-based" because it operates on AST and preprocessor
15 Clang ships two other code coverage implementations:
17 * :doc:`SanitizerCoverage` - A low-overhead tool meant for use alongside the
18 various sanitizers. It can provide up to edge-level coverage.
20 * gcov - A GCC-compatible coverage implementation which operates on DebugInfo.
22 From this point onwards "code coverage" will refer to the source-based kind.
35 The next few sections work through a complete, copy-'n-paste friendly example
38 .. code-block:: cpp
55 To compile code with coverage enabled, pass ``-fprofile-instr-generate
56 -fcoverage-mapping`` to the compiler:
58 .. code-block:: console
61 % clang++ -fprofile-instr-generate -fcoverage-mapping foo.cc -o foo
73 ``LLVM_PROFILE_FILE`` contains a path to a non-existent directory, the missing
83 on-line profile merging. The runtime takes care of selecting a raw profile
89 .. code-block:: console
98 coverage reports. This is done using the "merge" tool in ``llvm-profdata``, so
101 .. code-block:: console
103 # Step 3(a): Index the raw profile.
104 % llvm-profdata merge -sparse foo.profraw -o foo.profdata
107 generate a line-oriented report:
109 .. code-block:: console
111 # Step 3(b): Create a line-oriented coverage report.
112 % llvm-cov show ./foo -instr-profile=foo.profdata
116 .. code-block:: console
118 % llvm-cov show ./foo -instr-profile=foo.profdata | c++filt -n
120 This report includes a summary view as well as dedicated sub-views for
123 ``-show-line-counts-or-regions`` is enabled, ``llvm-cov`` displays sub-line
126 .. code-block:: none
131 22| 3| for (unsigned I = 0; I < 10; ++I) { BAR(I); }
134 ------------------
137 | 11| 3| for (unsigned I = 0; I < 10; ++I) { BAR(I); }
140 ------------------
143 | 11| 3| for (unsigned I = 0; I < 10; ++I) { BAR(I); }
146 ------------------
148 It's possible to generate a file-level summary of coverage statistics (instead
149 of a line-oriented report) with:
151 .. code-block:: console
153 # Step 3(c): Create a coverage summary.
154 % llvm-cov report ./foo -instr-profile=foo.profdata
156 -----------------------------------------------------------------------
157 /tmp/foo.cc 13 0 100.00% 3 100.00%
158 -----------------------------------------------------------------------
159 TOTAL 13 0 100.00% 3 100.00%
163 * The ``-sparse`` flag is optional but can result in dramatically smaller
172 * The ``llvm-profdata`` tool can be used to merge together multiple raw or
176 .. code-block:: console
178 % llvm-profdata merge -sparse foo1.profraw foo2.profdata -o foo3.profdata
180 Format compatibility guarantees
184 profile format. Raw profiles may be dependent on the specific compiler
189 These formats are not forwards-compatible: i.e, a tool which uses format
190 version X will not be able to understand format version (X+k).
192 * There is a third format in play: the format of the coverage mappings emitted
194 with these formats. These formats are not forwards-compatible.
208 * Forward-declare ``void __llvm_profile_initialize_file(void)`` and call it
216 * Forward-declare ``int __llvm_profile_write_file(void)`` and call it to write
217 out a profile. This function returns 0 when it succeeds, and a non-zero value
219 existing on-disk raw profile.
228 .. code-block:: cpp