From 4edf35f11a9e20bd5df3cb47283715f0ff38b751 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 15 Jan 2021 01:14:37 -0800 Subject: 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 --- clang/docs/SourceBasedCodeCoverage.rst | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'clang/docs/SourceBasedCodeCoverage.rst') 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:`` or ``src:`` +respectively. To exclude a function or a source file, use ``!fun:`` or +``!src:`` 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 ================================ -- cgit v1.2.3