GCOV(1) GNU GCOV(1)
gcov - coverage testing tool
gcov [-v|--version] [-h|--help]
[-o|--object-directory directory|file] sourcefile
gcov is a test coverage program. Use it in concert with GCC to analyze
your programs to help create more efficient, faster running code and to
discover untested parts of your program. You can use gcov as a
profiling tool to help discover where your optimization efforts will
best affect your code. You can also use gcov along with the other
profiling tool, gprof, to assess which parts of your code use the
greatest amount of computing time.
Profiling tools help you analyze your codes performance. Using a
profiler such as gcov or gprof, you can find out some basic performance
statistics, such as:
how often each line of code executes
what lines of code are actually executed
how much computing time each section of code uses
Once you know these things about how your code works when compiled, you
can look at each module to see which modules should be optimized. gcov
helps you determine where to work on optimization.
Software developers also use coverage testing in concert with
testsuites, to make sure software is actually good enough for a
release. Testsuites can verify that a program works as expected; a
coverage program tests to see how much of the program is exercised by
the testsuite. Developers can then determine what kinds of test cases
need to be added to the testsuites to create both better testing and a
better final product.
You should compile your code without optimization if you plan to use
gcov because the optimization, by combining some lines of code into one
function, may not give you as much information as you need to look for
hot spots where the code is using a great deal of computer time.
Likewise, because gcov accumulates statistics by line (at the lowest
resolution), it works best with a programming style that places only
one statement on each line. If you use complicated macros that expand
to loops or to other control structures, the statistics are less
helpful---they only report on the line where the macro call appears.
If your complex macros behave like functions, you can replace them with
inline functions to solve this problem.
gcov creates a logfile called sourcefile.gcov which indicates how many
times each line of a source file sourcefile.c has executed. You can
use these logfiles along with gprof to aid in fine-tuning the
performance of your programs. gprof gives timing information you can
use along with the information you get from gcov.
gcov works only on code compiled with GCC. It is not compatible with
any other profiling or test coverage mechanism.
Display help about using gcov (on the standard output), and exit
without doing any further processing.
Display the gcov version number (on the standard output), and exit
without doing any further processing.
Write individual execution counts for every basic block. Normally
gcov outputs execution counts only for the main blocks of a line.
With this option you can determine if blocks within a single line
are not being executed.
Write branch frequencies to the output file, and write branch
summary info to the standard output. This option allows you to see
how often each branch in your program was taken. Unconditional
branches will not be shown, unless the -u option is given.
Write branch frequencies as the number of branches taken, rather
than the percentage of branches taken.
Do not create the gcov output file.
Create long file names for included source files. For example, if
the header file x.h contains code, and was included in the file
a.c, then running gcov on the file a.c will produce an output file
called a.c##x.h.gcov instead of x.h.gcov. This can be useful if
x.h is included in multiple source files. If you use the -p
option, both the including and included file names will be complete
Preserve complete path information in the names of generated .gcov
files. Without this option, just the filename component is used.
With this option, all directories are used, with / characters
translated to # characters, . directory components removed and ..
components renamed to ^. This is useful if sourcefiles are in
several different directories. It also affects the -l option.
Output summaries for each function in addition to the file level
Specify either the directory containing the gcov data files, or the
object path name. The .gcno, and .gcda data files are searched for
using this option. If a directory is specified, the data files are
in that directory and named after the source file name, without its
extension. If a file is specified here, the data files are named
after that file, without its extension. If this option is not
supplied, it defaults to the current directory.
When branch probabilities are given, include those of unconditional
branches. Unconditional branches are normally not interesting.
gcov should be run with the current directory the same as that when you
invoked the compiler. Otherwise it will not be able to locate the
source files. gcov produces files called mangledname.gcov in the
current directory. These contain the coverage information of the
source file they correspond to. One .gcov file is produced for each
source file containing code, which was compiled to produce the data
files. The mangledname part of the output file name is usually simply
the source file name, but can be something more complicated if the -l
or -p options are given. Refer to those options for details.
The .gcov files contain the : separated fields along with program
source code. The format is