GCOV(1) | GNU | GCOV(1) |
NAME
gcov - coverage testing toolSYNOPSIS
gcov [ -v|--version] [-h|--help][-a|--all-blocks]
[-b|--branch-probabilities]
[-c|--branch-counts]
[-d|--display-progress]
[-f|--function-summaries]
[-i|--intermediate-format]
[-l|--long-file-names]
[-m|--demangled-names]
[-n|--no-output]
[-o|--object-directory directory|file]
[-p|--preserve-paths]
[-r|--relative-only]
[-s|--source-prefix directory]
[-u|--unconditional-branches]
files
DESCRIPTION
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.- *
- how often each line of code executes
- *
- what lines of code are actually executed
- *
- how much computing time each section of code uses
OPTIONS
- -h
- --help
- Display help about using gcov (on the standard output), and exit without doing any further processing.
- -v
- --version
- Display the gcov version number (on the standard output), and exit without doing any further processing.
- -a
- --all-blocks
- 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.
- -b
- --branch-probabilities
- 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.
- -c
- --branch-counts
- Write branch frequencies as the number of branches taken, rather than the percentage of branches taken.
- -n
- --no-output
- Do not create the gcov output file.
- -l
- --long-file-names
- 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 and you want to see the individual contributions. If you use the -p option, both the including and included file names will be complete path names.
- -p
- --preserve-paths
- 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 unremoveable .. components renamed to ^. This is useful if sourcefiles are in several different directories.
- -r
- --relative-only
- Only output information about source files with a relative pathname (after source prefix elision). Absolute paths are usually system header files and coverage of any inline functions therein is normally uninteresting.
- -f
- --function-summaries
- Output summaries for each function in addition to the file level summary.
- -o directory|file
- --object-directory directory
- --object-file file
- 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 input file name, without its extension. If a file is specified here, the data files are named after that file, without its extension.
- -s directory
- --source-prefix directory
- A prefix for source file names to remove when generating the output coverage files. This option is useful when building in a separate directory, and the pathname to the source directory is not wanted when determining the output file names. Note that this prefix detection is applied before determining whether the source file is absolute.
- -u
- --unconditional-branches
- When branch probabilities are given, include those of unconditional branches. Unconditional branches are normally not interesting.
- -d
- --display-progress
- Display the progress on the standard output.
- -i
- --intermediate-format
-
Output gcov file in an easy-to-parse intermediate text format that can be used by lcov or other tools. The output is a single .gcov file per .gcda file. No source code is required.
file:<source_file_name>
function:<line_number>,<execution_count>,<function_name>
lcount:<line number>,<execution_count>
branch:<line_number>,<branch_coverage_type>
Where the <branch_coverage_type> is
notexec (Branch not executed)
taken (Branch executed and taken)
nottaken (Branch executed, but not taken)
There can be multiple <file> entries in an intermediate gcov
file. All entries following a <file> pertain to that source file
until the next <file> entry.
file:array.cc
function:11,1,_Z3sumRKSt6vectorIPiSaIS0_EE
function:22,1,main
lcount:11,1
lcount:12,1
lcount:14,1
branch:14,taken
lcount:26,1
branch:28,nottaken
- -m
- --demangled-names
- Display demangled function names in output. The default is to show mangled function names.
<execution_count>:<line_number>:<source line text>
-:0:<tag>:<value>
<tag> <information>
$ gcc -fprofile-arcs -ftest-coverage tmp.c
$ a.out
$ gcov tmp.c
90.00% of 10 source lines executed in file tmp.c
Creating tmp.c.gcov.
-: 0:Source:tmp.c
-: 0:Graph:tmp.gcno
-: 0:Data:tmp.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:
-: 3:int main (void)
1: 4:{
1: 5: int i, total;
-: 6:
1: 7: total = 0;
-: 8:
11: 9: for (i = 0; i < 10; i++)
10: 10: total += i;
-: 11:
1: 12: if (total != 45)
#####: 13: printf ("Failure\n");
-: 14: else
1: 15: printf ("Success\n");
1: 16: return 0;
-: 17:}
-: 0:Source:tmp.c
-: 0:Graph:tmp.gcno
-: 0:Data:tmp.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:
-: 3:int main (void)
1: 4:{
1: 4-block 0
1: 5: int i, total;
-: 6:
1: 7: total = 0;
-: 8:
11: 9: for (i = 0; i < 10; i++)
11: 9-block 0
10: 10: total += i;
10: 10-block 0
-: 11:
1: 12: if (total != 45)
1: 12-block 0
#####: 13: printf ("Failure\n");
$$$$$: 13-block 0
-: 14: else
1: 15: printf ("Success\n");
1: 15-block 0
1: 16: return 0;
1: 16-block 0
-: 17:}
$ gcov -b tmp.c
90.00% of 10 source lines executed in file tmp.c
80.00% of 5 branches executed in file tmp.c
80.00% of 5 branches taken at least once in file tmp.c
50.00% of 2 calls executed in file tmp.c
Creating tmp.c.gcov.
-: 0:Source:tmp.c
-: 0:Graph:tmp.gcno
-: 0:Data:tmp.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:
-: 3:int main (void)
function main called 1 returned 1 blocks executed 75%
1: 4:{
1: 5: int i, total;
-: 6:
1: 7: total = 0;
-: 8:
11: 9: for (i = 0; i < 10; i++)
branch 0 taken 91% (fallthrough)
branch 1 taken 9%
10: 10: total += i;
-: 11:
1: 12: if (total != 45)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 13: printf ("Failure\n");
call 0 never executed
-: 14: else
1: 15: printf ("Success\n");
call 0 called 1 returned 100%
1: 16: return 0;
-: 17:}
if (a != b)
c = 1;
else
c = 0;
100: 12:if (a != b)
100: 13: c = 1;
100: 14:else
100: 15: c = 0;
SEE ALSO
gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for gcc.COPYRIGHT
Copyright (c) 1996-2015 Free Software Foundation, Inc.A GNU Manual
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.
2015-07-16 | gcc-5.2.0 |