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. 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. Software developers also use coverage testing in concert with testsuites, to make sure software is actually good enough for a release.
|Published (Last):||26 March 2009|
|PDF File Size:||2.21 Mb|
|ePub File Size:||7.78 Mb|
|Price:||Free* [*Free Regsitration Required]|
Description[ edit ] gcov produces a test coverage analysis of a specially instrumented program. The options -fprofile-arcs -ftest-coverage should be used to compile the program for coverage analysis first option to record branch statistics and second to save line execution count ; -fprofile-arcs should also be used to link the program.
It takes source files as command-line arguments and produces an annotated source listing. Each line of source code is prefixed with the number of times it has been executed; lines that have not been executed are prefixed with " ". This annotated source file can be used with gprof , another profiling tool, to extract timing information about the program. This creates an instrumented executable which contains additional instructions that record the number of times each line of the program is executed.
The option -ftest-coverage adds instructions for counting the number of times individual lines are executed, while -fprofile-arcs incorporates instrumentation code for each branch of the program. The executable must then be run to create the coverage data. This data can be analyzed using the gcov command and the name of a source file: gcov cov. Command line options[ edit ] Gcov command line utility supports following options while generating annotated files from profile data:   -h --help : Display help about using gcov on the standard output , and exit without doing any further processing.
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. 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.
For example, if the header file x. This can be useful if x. Without this option, just the filename component is used. This is useful if sourcefiles are in several different directories.
Absolute paths are usually system header files and coverage of any inline functions therein is normally uninteresting. 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. 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. Unconditional branches are normally not interesting. Coverage summaries[ edit ] Lcov is a graphical front-end for gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. Lcov supports statement, function, and branch coverage measurement.
Gcovr provides a utility for managing the use of gcov and generating summarized code coverage results. This command is inspired by the Python coverage. The XML reports generated by gcovr can be used by Jenkins to provide graphical code coverage summaries. Gcovr supports statement and branch coverage measurement  SCov is a utility that processes the intermediate text format generated by gcov using gcov -i to generate reports on code coverage.
These reports can be a simple text report, or HTML pages with more detailed reports .
LCOV - the LTP GCOV extension
Description[ edit ] gcov produces a test coverage analysis of a specially instrumented program. The options -fprofile-arcs -ftest-coverage should be used to compile the program for coverage analysis first option to record branch statistics and second to save line execution count ; -fprofile-arcs should also be used to link the program. It takes source files as command-line arguments and produces an annotated source listing. Each line of source code is prefixed with the number of times it has been executed; lines that have not been executed are prefixed with " ". This annotated source file can be used with gprof , another profiling tool, to extract timing information about the program.
What is coverage?
Compilation command for the test code : gcc --coverage lib. This will generate the following files lib. To generate the coverage report, run the following command gcov -abcfu lib. Each function is preceded with a line showing the number of times the function is called, number of times it returns and the percentage of function blocks that were executed. Each line of executable code contains the number of times the line was executed and the actual source code line number. Any line that was not executed will have in place of the execution count. It generates html files and integrates well with web based CI systems.