Execution profiling is a common aid for improving software performance. The SICStus Prolog compiler has the capability of instrumenting compiled code with counters, which are initially zero and incremented whenever the flow of control passes a given point in the compiled code. This way the number of calls, backtracks, choicepoints created, etc., can be counted for the instrumented predicates, and an estimate of the time spent in individual clauses and disjuncts can be calculated.
Gauge is a graphical user interface for inspecting execution profiles. It is available as a library module (see Gauge).
The original version of the profiling package was written by M.M. Gorlick and C.F. Kesselman at the Aerospace Corporation [Gorlick & Kesselman 87].
Only compiled code can be instrumented. To get an execution profile of a program, the compiler must first be told to produce instrumented code. This is done by issuing the query:
| ?- prolog_flag(compiling,_,profiledcode).
after which the program to be analyzed can be compiled as
usual. Any new compiled code will be instrumented while the
compiling Prolog flag has the value
The profiling data is generated by simply running the
program. The predicate
profile_data/4 (see below)
makes available a selection of the data as a Prolog term. The
profile_reset/1 zeroes the profiling
counters for a selection of the currently instrumented predicates.
The Selection argument determines the kind of profiling data to be collected. If uninstantiated, the predicate will backtrack over its possible values, which are:
The Resolution argument determines the level of resolution of the profiling data to be collected. If uninstantiated, the predicate will backtrack over its possible values, which are:
-Count, where Count is a sum of the corresponding counts per clause.
-Count, where Count includes counts for any disjunctions occurring inside that clause. Note, however, that the selections
backtracksdo not include counts for disjunctions.
-Count. This is the finest resolution level, counting individual clauses and disjuncts.
Above, PredName is a predicate spec, ClauseName is a
compound term PredName
InternalName is either
ClauseName—corresponding to a clause, or
to a disjunct.