Statistics relating to memory usage, run time, and garbage collection,
including information about which areas of memory have overflowed and
how much time has been spent expanding them, can be displayed by
calling statistics/0
.
The output from statistics/0
looks like this:
memory (total) 377000 bytes: 350636 in use, 26364 free program space 219572 bytes atom space (2804 atoms) 61024 in use, 43104 free global space 65532 bytes: 9088 in use, 56444 free global stack 6984 bytes trail 16 bytes system 2088 bytes local stack 65532 bytes: 356 in use, 65176 free local stack 332 bytes system 24 bytes 0.000 sec. for 0 global and 0 local space shifts 0.000 sec. for 0 garbage collections which collected 0 bytes 0.000 sec. for 0 atom garbage collections which collected 0 bytes 0.233 sec. runtime
Note the use of indentation to indicate sub-areas. That is, memory contains the program space, global space, and local stack, and the global space contains the global stack and trail.
The memory (total) figure shown as "in use" is the sum of the spaces for the program, global and local areas. The "free" figures for the global and local areas are for free space within those areas. However, this free space is considered used as far as the memory (total) area is concerned, because it has been allocated to the global and local areas. The program space is not considered to have its own free space. It always allocates new space from the general memory (total) free area.
Individual statistics can be obtained by statistics/2
, which
accepts a keyword and returns a list of statistics related to that
keyword.
The keys and values for statistics(
Keyword,
List)
are summarized below. The keywords core
and heap
are
included to retain compatibility with DEC-10 Prolog. Times are given
in milliseconds and sizes are given in bytes.
Keyword List
statistics/[0,2]
]
statistics/[0,2]
]
statistics/[0,2]
]
For the keywords program
and trail
, the second element of
the returned list is always 0. This is for backward compatibility
only, 0 being the most appropriate value in the Quintus Prolog system for the
quantities that would be returned here in DEC-10 Prolog and previous
releases of Quintus Prolog .
To see an example of the use of each of these keywords, type
| ?- statistics(K, L).
and then repeatedly type ;
to backtrack through all the possible
keywords. As an additional example, to report information on the runtime of
a predicate p/0, add the following to your program:
:- statistics(runtime, [T0| _]), p, statistics(runtime, [T1|_]), T is T1 - T0, format('p/0 took ~3d sec.~n', [T]).