Skip to content
Jan Wielemaker edited this page Sep 25, 2025 · 2 revisions

The SWI-Prolog execution profiler

Profiler
The SWI-Prolog execution profiler


The execution profiler may be used to find bottlenecks in your code. It is typically invoked using

?- profile(my_goal).

On completion of my_goal, this shows a window with two sub windows. The left pane shows all predicates that have been executed by my_goal sorted by the cumulative time spent in them. Clicking a predicate shows the details in the right pane. The details show the callers and callees and how time is distributed among them. Predicates are shown as links and may be clicked to examine the source code.

The profiler may also be triggered from the thread view. This allows collecting data from a running thread for a while and showing this data.

The predicate profile/2 provides additional options. Notably the option time(wall) may be used to sample wall time rather than CPU time. This may be used to investigate time spent in I/O. The option ports(true) can be used to get accurate port counts. On some cases of mutual recursion this can use a lot of resources, which is why the default is ports(classic). Classic mode gets the Call ports correct, but may give wrong counts on the other ports.

Clone this wiki locally