Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcov not showing any coverage data

Tags:

linux

gcov

I am trying to use gcov on Linux(Ubuntu) to see frequency of execution for each line of source.

I have added following flags to my gcc compiler and linker flags,

CCFLAGS =  -fprofile-arcs -ftest-coverage
LDFLAGS = -fprofile-arcs -lgcov

but after compiling and running the program, i see no *.gcda file created. As a result of which when i run

gcov  --object-directory <path to the *.gcno/*.gcda files> myfile.cpp 

Shows error:

myfile.gcda:cannot open data file, assuming not executed
File '../../../../../code/myfile.cpp'
Lines executed:0.00% of 2625

Am i missing something. How to fix this?

like image 595
goldenmean Avatar asked Oct 05 '22 14:10

goldenmean


1 Answers

You can use __gcov_flush() method inside your code. You will need to invoke this from registered signal handler.

See:

https://www.osadl.org/fileadmin/dam/interface/docbook/howtos/coverage.pdf

Using this, you can keep your service running and issue "kill" whenever you need to dump coverage data.

Hope that helps....

like image 53
Icarus3 Avatar answered Oct 09 '22 02:10

Icarus3