SWI-Prolog offers a statistical program profiler similar to Unix prof(1) for C and some other languages. A profiler is used as an aid to find performance pigs in programs. It provides information on the time spent in the various Prolog predicates.
The profiler is based on the assumption that if we monitor the
functions on the execution stack on time intervals not correlated to the
program's execution the number of times we find a procedure on the
environment stack is a measure of the time spent in this procedure. It
is implemented by calling a procedure each time slice Prolog is active.
This procedure scans the local stack and either just counts the
procedure on top of this stack (plain
profiling) or all
procedures on the stack (cumulative
profiling). To get
accurate results each procedure one is interested in should have a
reasonable number of counts. Typically a minute runtime will suffice to
get a rough overview of the most expensive procedures.
off
, plain
or cumulative
. plain
implies the time used by children of a predicate is not added to the
time of the predicate. For status cumulative
the time of
children is added (except for recursive calls). Cumulative profiling
implies the stack is scanned up to the top on each time slice to find
all active predicates. This implies the overhead grows with the number
of active frames on the stack. Cumulative profiling starts debugging
mode to disable tail recursion optimisation, which would otherwise
remove the necessary parent environments. Switching status from
plain
to cumulative
resets the profiler.
Switching to and from status off
does not reset the
collected statistics, thus allowing to suspend profiling for certain
parts of the program.
off
and clears all collected
statistics.
cumulative
) or on top of
the stack (plain
). Promilage is an integer
between 0 and 1000.