How to write the trace information into a file?

170 views
Skip to first unread message

Hailin Chen

unread,
Jun 24, 2014, 11:53:53 PM6/24/14
to swi-p...@googlegroups.com
Hi,

Anyone knows if there is a way of writing the trace information (the information displayed after invoke the trace command for a query) into a file? 

If I am using JPL in java program for prolog query, and also need to include the proof searching path, is that possible to have the trace information saved in a file that is reusable? 

Many thanks, 
Best, 

Hailin 

Kilian Evang

unread,
Jun 25, 2014, 3:26:18 AM6/25/14
to swi-p...@googlegroups.com
Hi Hailin,
one way might be to define prolog_trace_interception/4. [1] Then you can
collect trace information in a programmatic way.

Cheers,
Kilian

[1]
http://www.swi-prolog.org/pldoc/doc_for?object=prolog_trace_interception/4

Alan Baljeu

unread,
Jun 25, 2014, 11:04:37 AM6/25/14
to Kilian Evang, swi-p...@googlegroups.com
One thing I found useful:

leash(none), trace, tell('trace_file.txt'), my_program(5), told.

If I typed that right, it puts the entire execution of the program to a file that I can then study.



--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.

Alan Baljeu

unread,
Jun 25, 2014, 5:41:57 PM6/25/14
to Hailin Chen, swi-p...@googlegroups.com
(Do try to include the group in replies.  I can't always answer these questions.)

My mistake; tell and told redirect standard output to a file.  Trace is using standard error.  We need to find the means to redirect that.  Something like this, perhaps.

current_error(Stream) :-
    stream_property(Stream, alias(user_error)), !. % force det.

set_error(Stream) :-
    set_stream(Stream, alias(user_error)).

%Now, you can do this:

:- meta_predicate
    redirect_error(0, +).

redirect_error(Goal, File) :-
    current_error(OldErr),
    setup_call_cleanup(
        open(File, write, Err),
        setup_call_cleanup(
        set_error(Err),
        once(Goal),
        set_error(OldErr)),
        close(Err)).


:- meta_predicate trace_log(0).
trace_log(Method) :-

once(leash(-all))
, setup_call_cleanup((trace)
   , redirect_error(Method, 'trace.log')
   , (flush, notrace))
.


On Wed, Jun 25, 2014 at 2:42 PM, Hailin Chen <hailinc...@gmail.com> wrote:
***Not sure if you got my previous email ... If you did, please ignore this one. ***

Alan, 

I tried this in the command line: ?- leash(-all), trace, tell('trace_file.txt'), female(hope), told.

I made several modifications to work with a database (family.pl): 

father_of(joe,paul).
father_of(joe,mary).
father_of(joe,hope).
mother_of(jane,paul).
mother_of(jane,mary).
mother_of(jane,hope).

male(paul).
male(joe).
male(ralph).
male(X) :- father_of(X,Y).

female(mary).
female(jane).
female(hope).

son_of(X,Y) :- father_of(Y,X),male(X).
son_of(X,Y) :- mother_of(Y,X),male(X).

daughter_of(X,Y) :- father_of(Y,X),female(X).
daughter_of(X,Y) :- mother_of(Y,X),female(X).

sibling_of(X,Y) :- !,father_of(Z,X),father_of(Z,Y),X\=Y.
sibling_of(X,Y) :- !,mother_of(Z,X),mother_of(Z,Y),X\=Y.

After running this program, I got the trace_file.txt, but empty :(  And not found 'none' such argument for leash().

I am pretty new to prolog, please bear me if I am asking non-sense. 

Any comment? 

Thank you, 
Hailin


--
You received this message because you are subscribed to a topic in the Google Groups "SWI-Prolog" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swi-prolog/YHwXESVIJAs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swi-prolog+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages