9.2 Execution Profiling

Execution profiling is a common aid for improving software performance. As of release 4.2, execution profiling is available for compiled as well as interpreted code. Execution profiling requires no recompilation with instrumentation. The source_info Prolog flag plays no role. Execution profiling is either globally on or globally off for all compiled code. This is reflected by the profiling Prolog flag. When enabled, execution profiling counts the number of calls per caller-callee pair, and also detects calls that succeed nondeterminately. In addition, for compiled code, the number of instructions executed and choicepoints accessed per predicate are counted. While execution profiling is enabled, profiling data is accumulated by simply running the program. Compiled codes runs 2-10 times slower with execution profiling than without. A typical query pattern is:

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

The predicate profile_data/1 makes the accumulated data available as a Prolog term. The predicate print_profile/0 prints the execution profile in a format similar to gprof(1). It can also be given an argument which should be of the same type as the output of profile_data/1. The predicate profile_reset/0 clears all profiling data. For the details, see the respective reference page. See also the Gauge graphical user interface for inspecting execution profiles (see lib-gauge).

profile_reset development
Resets all profiling data.
profile_data(-Data) development
Data is the profiling data accumulated so far.
print_profile development
print_profile(+Data) development
The profiling data Data is displayed in a format similar to gprof(1). Data defaults to the profiling data accumulated so far.

Send feedback on this subject.