What is gcov which comes with GCC ?

ABOUT gcov

Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with the GNU Compiler Collection (GCC) suite.[1]

The gcov utility gives information on how often a program executes segments of code.[2] It produces a copy of the source file, annotated with execution frequencies. The gcov utility does not produce any time-based data and works only on code compiled with the GCC suite. The manual claims it is not compatible with any other profiling or test coverage mechanism,[3] but it works with llvm-generated files, too.

A TYPICAL SHELL SESSION
[bash]
$ls
loop.c
$gcc -fprofile-arcs -ftest-coverage loop.c
$ls
a.out loop.c loop.gcno
$./a.out
^C
$ls
a.out loop.c loop.gcno
$gcov loo
loop.c loop.gcno
$gcov loop.c
loop.gcda:cannot open data file, assuming not executed
File ‘loop.c’
No executable lines
Removing ‘loop.c.gcov’

$cat loo
loop.c loop.gcno
$cat loop.c
main()
{
for (;;);
}

$cp /home/jeffrin/loop.c .
$cat loop.c
main()
{
printf("hello world");
}

$gcc -fprofile-arcs -ftest-coverage loop.c
loop.c: In function ‘main’:
loop.c:3:1: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
$./a.out
hello world$
$gcov loop.c
File ‘loop.c’
Lines executed:100.00% of 3
Creating ‘loop.c.gcov’

$cat loop.c.gcov
-: 0:Source:loop.c
-: 0:Graph:loop.gcno
-: 0:Data:loop.gcda
-: 0:Runs:1
-: 0:Programs:1
1: 1:main()
-: 2:{
1: 3:printf("hello world");
1: 4:}
-: 5:
$

[/bash]
LINK
https://en.wikipedia.org/wiki/Gcov

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s