Displaying Statistics

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

[cpu time used by Prolog, cpu time since last call to statistics/[0,2]]
[cpu time used by the operating system, cpu time used by the system since the last call to statistics/[0,2]]
[wall clock time since 00:00 GMT 1/1/1970, wall clock time since the last call to statistics/[0,2]]
[total virtual memory in use, total virtual memory free]
[total global stack memory, total local stack memory]
[program space, 0]
[global stack in use, global stack free]
[local stack in use, local stack free]
[size of trail, 0]
[number of GCs, freed bytes, time spent]
[number of global stack area shifts, number of local stack area shifts, time spent shifting]
[number of atoms, atom space in use, atom space free]
[number of AGCs, freed bytes, time spent]
(same as memory)
(same as program)

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| _]),
        statistics(runtime, [T1|_]),
        T is T1 - T0,
        format('p/0 took ~3d sec.~n', [T]).