I recently started using lcov to visualize my code coverage. It\'s a great tool.
One thing I\'m noticing is that it generates code coverage reports for all the file
lcov supports a command line argument --remove to do exactly what you are asking for.
A possible approach is to constrain which files are compiled with the coverage flags (-fprofile-arcs -ftest-coverage). If you don't want to engineer your make file system to be selective about which files are built with test instrumentation, the following trick might work for you:
This should result in only the targeted areas emitting gcov artifacts, which are blindly consumed by the lcov scripts.
I used the --no-external
flag together with the --directory
flag to exclude unwanted files.
The definition of external from the man:
External source files are files which are not located in one of the directories specified by --directory or --base-directory.
So my command looked like this:
$ lcov --directory src -c -o report.info --no-external
Capturing coverage data from src
Found gcov version: 4.2.1
Scanning src for .gcda files ...
Found 4 data files in src
Processing src/C####.gcda
ignoring data for external file /usr/include/c++/4.2.1/bits/allocator.h