9.3 Coverage Analysis

Coverage analysis is the gathering of information about which points in the code, or coverage sites, were executed, and how many times, during a particular run if the program. It is available as of release 4.2, for compiled as well as interpred code, provided that such code was loaded with the source_info Prolog flag switched on. In fact, it uses the same underlying support as execution profiling: while the program is running with execution profiling switched on, the data accumulated can be used for both purposes. Roughly, coverage sites correspond to points in the code at which the debugger would stop in trace mode, plus one site at entry to every clause. A typical query pattern is:

     | ?- [Load some code.]
     | ?- prolog_flag(profiling,_,on).
     | ?- [Run some queries.]
     | ?- prolog_flag(profiling,_,off).
     | ?- print_coverage.

The predicate coverage_data/1 makes the accumulated data available as a Prolog term. The predicate print_coverage/0 prints the execution coverage in a hierarchical format. It can also be given an argument which should be of the same type as the output of coverage_data/1. The Emacs interface has commands for code coverage highlighting of source code buffers (see Usage). For the details, see the respective reference page.

profile_reset development
Resets all profiling and coverage data.
coverage_data(-Data) development
Data is the coverage data accumulated so far.
print_coverage development
print_coverage(+Data) development
The coverage data Data is displayed in a hierarchical format. Data defaults to the profiling data accumulated so far.

Send feedback on this subject.