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)       3334072 bytes
        global stack      1507184 bytes:       2516 in use,   1504668 free
        local stack         49296 bytes:        276 in use,     49020 free
        trail stack         34758 bytes:        248 in use,     34510 free
        control stack       34874 bytes:        364 in use,     34510 free
        program space     1707960 bytes:    1263872 in use,    444088 free
        program space breakdown:
                 compiled code               575096 bytes
                 atom                        166528 bytes
                 predicate                   157248 bytes
                 try_node                    144288 bytes
                 sw_on_key                   105216 bytes
                 incore_info                  51096 bytes
                 atom table                   36864 bytes
                 interpreted code             13336 bytes
                 atom buffer                   2560 bytes
                 SP_malloc                     2288 bytes
                 FLI stack                     2048 bytes
                 miscellaneous                 1640 bytes
                 BDD hash table                1560 bytes
                 source info (B-tree)          1024 bytes
                 numstack                      1024 bytes
                 int_info                       880 bytes
                 file table                     400 bytes
                 source info (itable)           328 bytes
                 module                         320 bytes
                 source info (lheap)             80 bytes
                 foreign resource                32 bytes
                 all solutions                   16 bytes
         4323 atoms (151927 bytes) in use, 1044252 free
         No memory resource errors
     
            0.020 sec. for 7 global, 20 local, and 0 choice stack overflows
            0.060 sec. for 15 garbage collections which collected 5461007 bytes
            0.000 sec. for 0 atom garbage collections which collected 0 atoms (0 bytes)
            0.000 sec. for 4 defragmentations
            0.000 sec. for 7 dead clause reclamations
            0.000 sec. for 0 dead predicate reclamations
           39.410 sec. runtime
         ========
           39.490 sec. total runtime
          109.200 sec. elapsed time
   Note the use of indentation to indicate sub-areas. That is, memory contains the program space and the four stacks: global, local, choice, and trail.
The memory (total) figure shown as “in use” is the sum of the spaces for the program space and stacks. The “free” figures for the stacks 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 stacks. The program space is not considered to have its own free space. It always allocates new space from the general memory (total) free area.
If a memory resource error has occurred previously in the execution, the memory area for which memory could not be allocated is displayed.
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, Value)
are summarized below.  The keywords core and heap are
included to retain compatibility with other Prologs.  Times are given
in milliseconds and sizes are given in bytes.
     
runtime[since start of Prolog,since previous statistics]statistics/2 with this key or to statistics/0.
     total_runtime[since start of Prolog,since previous statistics]statistics/2 with this key or to statistics/0.
     walltime[since start of Prolog,since previous statistics]statistics/2 with this key or to statistics/0.
     global_stack[size used,free]local_stack[size used,free]trail[size used,free]choice[size used,free]memorycore[size used,0]programheap[size used,size free]garbage_collection[no. of GCs,bytes freed,time spent]stack_shifts[no. of global shifts,no. of local/choice shifts,time spent]atoms[no. of atoms,bytes used,atoms free]atom_garbage_collection[no. of AGCs,bytes freed,time spent]defragmentation[no. of defragmentations,time spent]memory_usedmemory_freeglobal_stack_usedglobal_stack_freelocal_stack_usedlocal_stack_freetrail_usedtrail_freechoice_usedchoice_freeatoms_usedatoms_nbusedatoms_nbfreess_globalss_localss_choicess_timegc_countgc_freedgc_timeagc_countagc_nbfreedagc_freedagc_timedefrag_countdefrag_timedpgc_countdpgc_timedcgc_countdcgc_timememory_culpritmemory_bucketsTo 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]).