Next:Invokinggcov, Up:gcov—a Test Coverage Program [Contents][Index]
gcov ¶gcov is a test coverage program. Use it in concert with GCCto analyze your programs to help create more efficient, faster runningcode and to discover untested parts of your program. You can usegcov as a profiling tool to help discover where youroptimization efforts will best affect your code. You can also usegcov along with the other profiling tool,gprof, toassess which parts of your code use the greatest amount of computingtime.
Profiling tools help you analyze your code’s performance. Using aprofiler such asgcov orgprof, you can find out somebasic performance statistics, such as:
Once you know these things about how your code works when compiled, youcan 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 withtestsuites, to make sure software is actually good enough for a release.Testsuites can verify that a program works as expected; a coverageprogram tests to see how much of the program is exercised by thetestsuite. Developers can then determine what kinds of test cases needto be added to the testsuites to create both better testing and a betterfinal product.
You should compile your code without optimization if you plan to usegcov because the optimization, by combining some lines of codeinto one function, may not give you as much information as you need tolook for ‘hot spots’ where the code is using a great deal of computertime. Likewise, becausegcov accumulates statistics by line (atthe lowest resolution), it works best with a programming style thatplaces only one statement on each line. If you use complicated macrosthat expand to loops or to other control structures, the statistics areless helpful—they only report on the line where the macro callappears. If your complex macros behave like functions, you can replacethem with inline functions to solve this problem.
gcov creates a logfile calledsourcefile.gcov whichindicates how many times each line of a source filesourcefile.chas executed. You can use these logfiles along withgprof to aidin fine-tuning the performance of your programs.gprof givestiming information you can use along with the information you get fromgcov.
gcov works only on code compiled with GCC. It is notcompatible with any other profiling or test coverage mechanism.
Next:Invokinggcov, Up:gcov—a Test Coverage Program [Contents][Index]