diff options
| author | Petr Hosek <phosek@google.com> | 2021-01-15 01:14:37 -0800 |
|---|---|---|
| committer | Petr Hosek <phosek@google.com> | 2021-01-26 11:11:39 -0800 |
| commit | 4edf35f11a9e20bd5df3cb47283715f0ff38b751 (patch) | |
| tree | d8fd7bbd93f7ea0cf187fd995468b85518183918 /clang/docs/SourceBasedCodeCoverage.rst | |
| parent | 32cc5564e2707c6036230ef3929c0d783ccea04c (diff) | |
Support for instrumenting only selected files or functions
This change implements support for applying profile instrumentation
only to selected files or functions. The implementation uses the
sanitizer special case list format to select which files and functions
to instrument, and relies on the new noprofile IR attribute to exclude
functions from instrumentation.
Differential Revision: https://reviews.llvm.org/D94820
Diffstat (limited to 'clang/docs/SourceBasedCodeCoverage.rst')
| -rw-r--r-- | clang/docs/SourceBasedCodeCoverage.rst | 45 |
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 ================================ |
