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. Execution profiling is either globally on or globally off for all compiled code. This is reflected by the profiling Prolog flag. When the flag is on, the information gathered depends on the execution mode:

compiled code

Execution profiling counts the number of calls per caller-callee pair, the number of instructions executed, and the number of choicepoint accesses per predicate. Calls that succeed nondeterminately are detected. Compiled codes runs 2-10 times slower with execution profiling than without.

interpreted code

Execution profiling counts the number of calls per caller-callee pair if the source_info Prolog flag was on when the code was loaded; otherwise, the number of calls per predicate. Calls that succeed nondeterminately are detected.

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) and the SICStus Prolog IDE (see SICStus Prolog IDE) which both can visualize the profiling information.

profile_reset   since release 4.2,development

Resets all profiling data. See mpg-ref-profile_reset.

profile_data(-Data)   since release 4.2,development

Data is the profiling data accumulated so far. See mpg-ref-profile_data.

print_profile   since release 4.2,development
print_profile(+Data)   since release 4.2,development

The profiling data Data is displayed in a format similar to gprof(1). Data defaults to the profiling data accumulated so far. See mpg-ref-print_profile.



Send feedback on this subject.