summaryrefslogtreecommitdiff
path: root/clang/docs/SourceBasedCodeCoverage.rst
diff options
context:
space:
mode:
Diffstat (limited to 'clang/docs/SourceBasedCodeCoverage.rst')
-rw-r--r--clang/docs/SourceBasedCodeCoverage.rst45
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/docs/SourceBasedCodeCoverage.rst b/clang/docs/SourceBasedCodeCoverage.rst
index 90feb41b0a3f..587e47c04a68 100644
--- a/clang/docs/SourceBasedCodeCoverage.rst
+++ b/clang/docs/SourceBasedCodeCoverage.rst
@@ -64,6 +64,51 @@ To compile code with coverage enabled, pass ``-fprofile-instr-generate
Note that linking together code with and without coverage instrumentation is
supported. Uninstrumented code simply won't be accounted for in reports.
+Instrumenting only selected files or functions
+----------------------------------------------
+
+Sometimes it's useful to only instrument certain files or functions. For
+example in automated testing infrastructure, it may be desirable to only
+instrument files or functions that were modified by a patch to reduce the
+overhead of instrumenting a full system.
+
+This can be done using the ``-fprofile-list=file.list`` option. The option
+can be specified multiple times to pass multiple files:
+
+.. code-block:: console
+
+ $ echo "!fun:*test*" > fun.list
+ $ echo "src:code.cc" > src.list
+ % clang++ -O2 -fprofile-instr-generate -fcoverage-mapping -fprofile-list=fun.list -fprofile-list=code.list code.cc -o code
+
+The file uses :doc:`SanitizerSpecialCaseList` format. To filter individual
+functions or entire source files using ``fun:<name>`` or ``src:<file>``
+respectively. To exclude a function or a source file, use ``!fun:<name>`` or
+``!src:<file>`` respectively. The format also supports wildcard expansion. The
+compiler generated functions are assumed to be located in the main source file.
+It is also possible to restrict the filter to a particular instrumentation type
+by using a named section. For example:
+
+.. code-block:: none
+
+ # all functions whose name starts with foo will be instrumented.
+ fun:foo*
+
+ # except for foo1 which will be excluded from instrumentation.
+ !fun:foo1
+
+ # every function in path/to/foo.cc will be instrumented.
+ src:path/to/foo.cc
+
+ # bar will be instrumented only when using backend instrumentation.
+ # Recognized section names are clang, llvm and csllvm.
+ [llvm]
+ fun:bar
+
+When the file contains only excludes, all files and functions except for the
+excluded ones will be instrumented. Otherwise, only the files and functions
+specified will be instrumented.
+
Running the instrumented program
================================