gcov

Table of Contents

1 How to run

Compile your program with two flags

gcc -fprofile-arcs -ftest-coverage a.c

This will produce a.gcda (arcs) and a.gcno (coverage).

Then run the program by

./a.out

run gcov in the same directory:

gcov a.c

This will produce the coverage, and create a a.c.gcov file.

2 Different options

When invoking gcov, you can control the output format:

  • gcov -b a.c: output branching information

3 .gcov file format

ExeCount : linum : line

# in the ExeCount means no execution.

4 Gprof

Compile and link with the -pg option. When running the program, a gmon.out will be produced. It will overwrite if the file exists. Running the gprof is like:

gprof options exe-file profile-data-file

exe-file defaults to a.out, profile-data-file defaults to gmon.out.

As I tried, this is not friendly for C++ programs. The output is full of STL namespace.

5 Some experience

  • The coverage information will accumulate: run a second time, it will possibly increase.
  • branches executed is the for the head of branch.
  • branches taken at least once is for the ordinary branch coverage

Author: Hebi Li

Created: 2017-06-14 Wed 22:42

Validate