Did you know ... | Search Documentation: |
Trace Mode vs. Trace Point |
A slight detour is useful to describe some related predicates that
can be confusing: To only trace a single or select set of predicates,
the
trace/1 or trace/2
predicates can be used to set a trace point. Even though they use
the same base predicate name trace
, these predicates ignore
the leash/1 and visible/1
global settings and don't pause when they trace a port. They really are
a different feature that also happens to do tracing.
A trace point is set on a particular predicate and traces the ports of that predicate whether or not you are in trace/0 trace mode. Each trace point can trace different ports if the trace/2 variant is used.
?- trace(is_a/2). % is_a/2: [all] true. ?- noun(X, rock), adjective(X, color, red). T Call: is_a(_25702, rock) T Exit: is_a(rock1, rock) X = rock1 ; T Redo: is_a(rock1, rock) T Exit: is_a(rock2, rock) false.
Notice that trace mode did not have to be turned on using trace/0 and that this only traced out the ports hit while executing is_a/2 and that the program was not ever paused.
In fact, if trace mode is turned on while using a trace point, things get very confusing because the trace point infrastructure itself will be traced!
?- trace(is_a/2). % is_a/2: [all] true. ?- trace. true. [trace] ?- noun(X, rock), adjective(X, color, red). Call: (11) noun(_29318, rock) ? creep Call: (12) is_a(_29318, rock) ? creep Call: (13) print_message(debug, frame(user:is_a(_29318, rock), trace(call))) ? creep Call: (18) push_msg(frame(user:is_a(_29318, rock), trace(call))) ? creep Call: (21) exception(undefined_global_variable, '$inprint_message', _30046) ? creep Fail: (21) exception(undefined_global_variable, '$inprint_message', _30090) ? creep Exit: (18) push_msg(frame(user:is_a(_29318, rock), trace(call))) ? creep Call: (19) prolog:message(frame(user:is_a(_29318, rock), trace(call)), _30140, _30142) ? creep Fail: (19) prolog:message(frame(user:is_a(_29318, rock), trace(call)), _30140, _30142) ? creep Call: (19) message_property(debug, stream(_30192)) ? creep Fail: (19) message_property(debug, stream(_30192)) ? creep Call: (20) message_property(debug, prefix(_30200)) ? creep Fail: (20) message_property(debug, prefix(_30200)) ? creep T Call: is_a(_29318, rock) Call: (17) pop_msg ? creep Exit: (17) pop_msg ? creep ...Lots more after this...
So, trace points are a confusingly named and separate feature from trace mode.