## 4.38 Obtaining Runtime Statistics

statistics(+Key, -Value)
  Unify system statistics determined by Key with Value. The possible keys are given in the table 6. This predicate supports additional keys for compatibility reasons. These keys are described in table 7.

  Native keys (times as float in seconds)
  agc | Number of atom garbage collections performed
  agc_gained | Number of atoms removed
  agc_time | Time spent in atom garbage collections
  process_cputime | (User) CPU time since Prolog was started in seconds
  cputime | (User) CPU time since thread was started in seconds
  inferences | Total number of passes via the call and redo ports since Prolog was started
  heapused | Bytes of heap in use by Prolog (0 if not maintained)
  heap_gc | Number of heap garbage collections performed. Only provided if SWI-Prolog is configured with Boehm-GC. See also garbage_collect_heap/0.
  c_stack | System (C-) stack limit. 0 if not known.
  stack | Total memory in use for stacks in all threads
  local | Allocated size of the local stack in bytes
  localused | Number of bytes in use on the local stack
  locallimit | Size to which the local stack is allowed to grow
  local_shifts | Number of local-stack expansions
  global | Allocated size of the global stack in bytes
  globalused | Number of bytes in use on the global stack
  globallimit | Size to which the global stack is allowed to grow
  global_shifts | Number of global-stack expansions
  trail | Allocated size of the trail stack in bytes
  trailused | Number of bytes in use on the trail stack
  traillimit | Size to which the trail stack is allowed to grow
  trail_shifts | Number of trail-stack expansions
  shift_time | Time spent in stack-shifts
  atoms | Total number of defined atoms
  functors | Total number of defined name/arity pairs
  clauses | Total number of clauses in the program
  modules | Total number of defined modules
  codes | Total size of (virtual) executable code in words
  threads | MT-version: number of active threads
  threads_created | MT-version: number of created threads
  thread_cputime | MT-version: seconds CPU time used by finished threads. Supported on Windows-NT and later, Linux and possibly a few more. Verify it gives plausible results before using.

  Table 6 : Keys for statistics/2. Space is expressed in bytes. Time is expressed in seconds, represented as a floating point number.

  Compatibility keys (times in milliseconds)
  runtime | [ CPU time, CPU time since last ] (milliseconds, excluding time spent in garbage collection)
  system_time | [ System CPU time, System CPU time since last ] (milliseconds)
  real_time | [ Wall time, Wall time since last ] (integer seconds. See get_time/1)
  walltime | [ Wall time since start, Wall time since last] (milliseconds, SICStus compatibility)
  memory | [ Total unshared data, free memory ] (Uses getrusage() if available, otherwise incomplete own statistics.)
  stacks | [ global use, local use ]
  program | [ heap, 0 ]
  global_stack | [ global use, global free ]
  local_stack | [ local use, local free ]
  trail | [ trail use, trail free ]
  garbage_collection | [ number of GC, bytes gained, time spent, bytes left ] The last column is a SWI-Prolog extension. It contains the sum of the memory left after each collection, which can be divided by the count to find the average working set size after GC. Use `[Count, Gained, Time|_]` for compatiblity.
  stack_shifts | [ global shifts, local shifts, time spent ]
  atoms | [ number, memory use, 0 ]
  atom_garbage_collection | [ number of AGC, bytes gained, time spent ]
  core | Same as memory

  Table 7 : Compatibility keys for statistics/2. Time is expressed in milliseconds.

statistics
  Display a table of system statistics on the current output stream.
time(:Goal)
  Execute Goal just like call/1 and print time used, number of logical inferences and the average number of lips (logical inferences per second). Note that SWI-Prolog counts the actual executed number of inferences rather than the number of passes through the call and redo ports of the theoretical 4-port model. If Goal is non-deterministic, print statistics for each solution, where the reported values are relative to the previous answer.