Gcov Notes
`
//test.cpp
#include
using namespace std;
int used() { std::cout << "Used" << std::endl; return 0; }
int unused()
{
std::cout << "Unused" << std::endl;
return 0;
}
int main(int C,char *[]) { used(); //unused(); used();
return 0; }
`
For a given file gcov can give code use coverage. For example , lets start compiling this code.
g++ --coverage test.cpp -c g++ --coverage test.o
you will notice a file called test.gcno is created.
next run the executable
a.out; used used
Another file is now created test.gcda
run gcov now against the source file
gcov test.cpp -m
File 'test.cpp' Lines executed:70.00% of 10 Creating 'test.cpp.gcov'
This suggest that only 70% of the code is used.
opening the create file test.cpp.gcov
-: 0:Source:test.cpp
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 1:#include <iostream>
-: 2:
-: 3:
-: 4:using namespace std;
-: 5:
2: 6:int test()
-: 7:{
2: 8: std::cout << "Used" << std::endl;
2: 9: return 0;
-: 10:}
-: 11:
#####: 12:int unused()
-: 13:{
#####: 14: std::cout << "Unused" << std::endl;
#####: 15: return 0;
-: 16:}
-: 17:
1: 18:int main(int C,char *[])
-: 19:{
1: 20: test();
-: 21:// unused();
1: 22: test();
-: 23:
1: 24:return 0;
-: 25:}
shows which functions are called etc, which are not.