trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
272 stars 13 forks source link

Statistics for space usage, is it available? #618

Open Jean-Luc-Picard-2021 opened 5 days ago

Jean-Luc-Picard-2021 commented 5 days ago

I found a way to measure space usage in SWI-Prolog:

/* SWI-Prolog */
space(G) :-
   garbage_collect, trim_stacks,
   statistics(stack, A),
   G,
   garbage_collect, trim_stacks,
   statistics(stack, B),
   C is B-A,
   write('% Memory '), write(C), write(' bytes'), nl.

?- between(1,5,N), K is N*10000, once(
space(findall(X,between(1,K,X),L))), fail; true.
% Memory 229376 bytes
% Memory 491520 bytes
% Memory 1015808 bytes
% Memory 1015808 bytes
% Memory 2064384 bytes
true.

Can this be ported to Trealla Prolog? I don't find the corresponding statistics key:

/* Trealla Prolog */
?- statistics(stack, X).
   false.
Jean-Luc-Picard-2021 commented 5 days ago

I cannot list what is available, this here doesn't work:

?- statistics(K, V).
   throw(error(instantiation_error,atom)).

SICStus Prolog has memory_used:

| ?- statistics(memory_used, X).
X = 16291536 ? 

https://sicstus.sics.se/sicstus/docs/latest/html/sicstus.html/ref_002dmgc_002dove_002dsta.html

infradig commented 4 days ago

'frames', 'choices', 'trails' & 'slots'. there is no memory stat.