profile_call(_,Call) :- !, call(Call).
profile_call(ID,Call) :- assert(profiled_call(ID,Call)),
% (enter(ID,_C) -> (print('### Already profiling id: '), print(ID), print(calls(_C,Call)),nl) ; true),
(retract(calls(ID,Nr)) -> (N1 is Nr+1, assert(calls(ID,N1))) ; assert(calls(ID,1))),
%print(enter(ID,Call)),nl,
statistics(runtime,[EnterTime,_]),
asserta(enter(ID,EnterTime)),
call(Call),
(true ; (statistics(runtime,[RedoTime,_]),asserta(enter(ID,RedoTime))),fail),
statistics(runtime,[ExitTime,_]),
add_time(ID,ExitTime).
profile_call(ID,_Call) :- % print(fail(ID)),nl,
statistics(runtime,[FailTime,_]),
(retract(enter(ID,EnterTime))
-> Delta is FailTime-EnterTime
; (Delta=0, print(err_fail(ID)),nl)
), assert(fail_time(ID,Delta)),
fail.