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 profiledcode
.
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
predicate profile_reset/1
zeroes the profiling
counters for a selection of the currently instrumented predicates.
profile_data(
:Spec,
?Selection,
?Resolution,
-Data)
development
Data is profiling data collected from the predicates covered by the generalized predicate spec Spec.
The Selection argument determines the kind of profiling data to be collected. If uninstantiated, the predicate will backtrack over its possible values, which are:
calls
backtracks
choice_points
shallow_fails
deep_fails
execution_time
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:
predicate
Module:PredName-
Count
,
where Count is a sum of the corresponding counts per clause.
clause
Module:ClauseName-
Count
, where Count includes
counts for any disjunctions occurring inside that clause.
Note, however, that the selections calls
and backtracks
do
not include counts for disjunctions.
all
Module:InternalName-
Count
. This is the finest
resolution level, counting individual clauses and disjuncts.
Above, PredName is a predicate spec, ClauseName is a
compound term PredName
/
ClauseNumber, and
InternalName is either
ClauseName--corresponding to a
clause, or
(
ClauseName-
DisjNo)/
Arity/
AltNo--corresponding
to a disjunct.
profile_reset(
:Spec)
development
Zeroes all counters for predicates covered by the generalized predicate spec Spec.