Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--keep option is not working #286

kunhong opened this issue Nov 22, 2018 · 1 comment

--keep option is not working #286

kunhong opened this issue Nov 22, 2018 · 1 comment


Copy link

@kunhong kunhong commented Nov 22, 2018

This is my simple program to test coverage

#include <iostream>

class Test {
	Test() {
		std::cout << "Test Constructor" << std::endl;

	~Test() {
		std::cout << "Test Destructor" << std::endl;

	void foo(bool v) {
		if (v) {
			std::cout << "calling foo" << std::endl;

int main() {
	Test test;;;

    return 0;

compile & run

$ g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
$ ./program 

run gcovr

$ gcovr -k -v -r .
Filters for --root: (1)
- re.compile('/Users/hongkun/dev/git_projects/Temp/')
Filters for --filter: (1)
- DirectoryPrefixFilter(/Users/hongkun/dev/git_projects/Temp/)
Filters for --exclude: (0)
Filters for --gcov-filter: (1)
- AlwaysMatchFilter()
Filters for --gcov-exclude: (0)
Filters for --exclude-directories: (0)
Scanning directory . for gcda/gcno files...
Found 2 files (and will process 1)
Pool started with 1 threads
Processing file: /Users/hongkun/dev/git_projects/Temp/example.gcda
Running gcov: 'gcov /Users/hongkun/dev/git_projects/Temp/example.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /Users/hongkun/dev/git_projects/Temp' in '/var/folders/j8/p3thzgnx2_b51ctyv4sc0cf40000gn/T/tmpascthv56'
Finding source file corresponding to a gcov data file
  currdir      /Users/hongkun/dev/git_projects/Temp
  gcov_fname   /var/folders/j8/p3thzgnx2_b51ctyv4sc0cf40000gn/T/tmpascthv56/
               ['        -', '    0', 'Source', '/Applications/\n']
  source_fname /Users/hongkun/dev/git_projects/Temp/example.gcda
  root         /Users/hongkun/dev/git_projects/Temp
  fname        /Applications/
$ ls
example.cpp	example.gcda	example.gcno	program

gcovr with keep option is not working. i could not find example.cpp.gcov file in my source folder

It looks like gcovr will delete .gcov file. also it seems it writes it to /var folder


$ gcovr --version
gcovr 4.1

Copyright 2013-2018 the gcovr authors
Copyright 2013 Sandia Corporation
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
$ g++ --version
Configured with: --prefix=/Applications/ --with-gxx-include-dir=/Applications/
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/
$ gcov --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  Optimized build.
  Default target: x86_64-apple-darwin18.2.0
  Host CPU: broadwell
@kunhong kunhong changed the title -keep option is not working --keep option is not working Nov 22, 2018
Copy link

@latk latk commented Nov 22, 2018

Thank you for the excellent bug report! This is a known issue for gcovr 4.x and is a duplicate of #285.

TL;DR: when we implemented parallelization, gcovr started copying the .gcov files to a tempdir so that the next run of gcov in the same directory would not overwrite them. So what gcovr should perhaps do is copy the files back to their original location, or to skip any copying when parallelization is not enabled.

But it turns out that the original behaviour was broken all along! When a header file is included into multiple translation units, gcov will write a .gcov file for that header each time it processes the coverage data of the translation unit. The last one wins, so coverage data in headers will likely be incomplete in any files that are kept.

There are a couple of alternatives how this could be fixed, I'm not sure yet:

  • update the docs to say that --keep can only be used with --use-gcov-files, so that any existing files are not touched. Any .gcov files that are created via gcovr would still be deleted.
  • copy the .gcov files back into the build directory, but warn if there is a conflict.
  • implement a new output format so that gcovr can write .gcov reports, though with the properly merged coverage data.

Let me know if you have any thoughts on what approach would be best, or if you'd like to implement a fix. Unfortunately, I won't be able to do any meaningful work on gcovr before ~January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants