Further updates to support call_counters
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@581 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
94e9529128
commit
708437b794
38
C/absmi.c
38
C/absmi.c
@ -298,7 +298,9 @@ absmi(int inp)
|
||||
restore_absmi_regs(old_regs);
|
||||
#endif
|
||||
if (!growheap(FALSE)) {
|
||||
saveregs();
|
||||
Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve space in growheap");
|
||||
setregs();
|
||||
FAIL();
|
||||
}
|
||||
goto reset_absmi;
|
||||
@ -324,7 +326,9 @@ absmi(int inp)
|
||||
restore_absmi_regs(old_regs);
|
||||
#endif
|
||||
if(!growtrail (sizeof(CELL) * 16 * 1024L)) {
|
||||
saveregs();
|
||||
Error(SYSTEM_ERROR,TermNil,"YAP failed to reserve %ld bytes in growtrail",sizeof(CELL) * 16 * 1024L);
|
||||
setregs();
|
||||
FAIL();
|
||||
}
|
||||
goto reset_absmi;
|
||||
@ -529,14 +533,21 @@ absmi(int inp)
|
||||
|
||||
/* count_enter_me Label,NArgs */
|
||||
Op(count_call, l);
|
||||
LOCK(((PredEntry *)(PREG->u.l.l))->StatisticsForPred.lock);
|
||||
((PredEntry *)(PREG->u.l.l))->StatisticsForPred.NOfEntries++;
|
||||
UNLOCK(((PredEntry *)(PREG->u.l.l))->StatisticsForPred.lock);
|
||||
ReductionsCounter--;
|
||||
if (ReductionsCounter == 0 && ReductionsCounterOn) {
|
||||
saveregs();
|
||||
Error(CALL_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PredEntriesCounter--;
|
||||
if (PredEntriesCounter == 0 && PredEntriesCounterOn) {
|
||||
saveregs();
|
||||
Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PREG = NEXTOP(PREG, l);
|
||||
@ -545,14 +556,21 @@ absmi(int inp)
|
||||
|
||||
/* count_retry Label,NArgs */
|
||||
Op(count_retry, l);
|
||||
LOCK(((PredEntry *)(PREG->u.l.l))->StatisticsForPred.lock);
|
||||
((PredEntry *)(PREG->u.l.l))->StatisticsForPred.NOfRetries++;
|
||||
UNLOCK(((PredEntry *)(PREG->u.l.l))->StatisticsForPred.lock);
|
||||
RetriesCounter--;
|
||||
if (RetriesCounter == 0 && RetriesCounterOn) {
|
||||
saveregs();
|
||||
Error(RETRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
JMPNext();
|
||||
setregs();
|
||||
}
|
||||
PredEntriesCounter--;
|
||||
if (PredEntriesCounter == 0 && PredEntriesCounterOn) {
|
||||
saveregs();
|
||||
Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PREG = NEXTOP(PREG, l);
|
||||
@ -564,14 +582,21 @@ absmi(int inp)
|
||||
CACHE_Y(B);
|
||||
/* After retry, cut should be pointing at the parent
|
||||
* choicepoint for the current B */
|
||||
LOCK(((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.lock);
|
||||
((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.NOfRetries++;
|
||||
UNLOCK(((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.lock);
|
||||
RetriesCounter--;
|
||||
if (RetriesCounter == 0 && RetriesCounterOn) {
|
||||
saveregs();
|
||||
Error(RETRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PredEntriesCounter--;
|
||||
if (PredEntriesCounter == 0 && PredEntriesCounterOn) {
|
||||
saveregs();
|
||||
Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
restore_yaam_regs(PREG->u.ld.d);
|
||||
@ -616,14 +641,21 @@ absmi(int inp)
|
||||
ENDCACHE_Y();
|
||||
RetriesCounter--;
|
||||
if (RetriesCounter == 0) {
|
||||
saveregs();
|
||||
Error(RETRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PredEntriesCounter--;
|
||||
if (PredEntriesCounter == 0) {
|
||||
saveregs();
|
||||
Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
LOCK(((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.lock);
|
||||
((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.NOfRetries++;
|
||||
UNLOCK(((PredEntry *)(PREG->u.ld.p))->StatisticsForPred.lock);
|
||||
PREG = NEXTOP(PREG, ld);
|
||||
GONext();
|
||||
ENDOp();
|
||||
@ -1179,15 +1211,18 @@ absmi(int inp)
|
||||
BOp(count_retry_and_mark, ld);
|
||||
RetriesCounter--;
|
||||
if (RetriesCounter == 0) {
|
||||
saveregs();
|
||||
Error(RETRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
PredEntriesCounter--;
|
||||
if (PredEntriesCounter == 0) {
|
||||
saveregs();
|
||||
Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,"");
|
||||
setregs();
|
||||
JMPNext();
|
||||
}
|
||||
goto actual_retry_and_mark;
|
||||
/* enter a retry dynamic */
|
||||
ENDBOp();
|
||||
|
||||
@ -1200,7 +1235,6 @@ absmi(int inp)
|
||||
|
||||
/* retry_and_mark Label,NArgs */
|
||||
BOp(retry_and_mark, ld);
|
||||
actual_retry_and_mark:
|
||||
#ifdef YAPOR
|
||||
CUT_wait_leftmost();
|
||||
#endif /* YAPOR */
|
||||
|
30
docs/yap.tex
30
docs/yap.tex
@ -155,7 +155,7 @@ Built In Predicates
|
||||
* OS:: Access to Operating System Functionality
|
||||
* Term Modification:: Updating Prolog Terms
|
||||
* Profiling:: Profiling Prolog Execution
|
||||
* Calls Execution Limits:: Limiting the Maximum Number of Reductions
|
||||
* Call Counting:: Limiting the Maximum Number of Reductions
|
||||
* Arrays:: Supporting Global and Local Arrays
|
||||
* Preds:: Information on Predicates
|
||||
* Misc:: Miscellaneous Predicates
|
||||
@ -2035,7 +2035,7 @@ Builtins, Debugging, Syntax, Top
|
||||
* OS:: Access to Operating System Functionality
|
||||
* Term Modification:: Updating Prolog Terms
|
||||
* Profiling:: Profiling Prolog Execution
|
||||
* Calls Execution Limits:: Limiting the Maximum Number of Reductions
|
||||
* Call Counting:: Limiting the Maximum Number of Reductions
|
||||
* Arrays:: Supporting Global and Local Arrays
|
||||
* Preds:: Information on Predicates
|
||||
* Misc:: Miscellaneous Predicates
|
||||
@ -5744,6 +5744,10 @@ retries.
|
||||
These counters can be used to find out how many calls a certain
|
||||
goal takes to execute. They can also be used as timers.
|
||||
|
||||
The code for the call counters piggybacks on the profiling
|
||||
code. Therefore, activating the call counters also activates the call
|
||||
counters.
|
||||
|
||||
These are the predicates that access and manipulate the call counters:
|
||||
|
||||
@table @code
|
||||
@ -5778,7 +5782,29 @@ counter @code{retries} reaches 0;
|
||||
reaches 0.
|
||||
@end itemize
|
||||
|
||||
Next, we show a simple example of how to use call counters:
|
||||
@example
|
||||
G(X,Y,Z,I,J) :-
|
||||
array_element(X,I,E1),
|
||||
array_element(Y,J,E2),
|
||||
array_element(Z,I,E3),
|
||||
E1 is E2+E3.
|
||||
@end example
|
||||
?- yap_flag(call_counting,on), [-user]. l :- l. end_of_file. yap_flag(call_counting,off).
|
||||
|
||||
yes
|
||||
|
||||
yes
|
||||
?- catch((call_count(10000,_,_),l),call_counter,format("limit_exceeded.~n",[])).
|
||||
|
||||
limit_exceeded.
|
||||
|
||||
yes
|
||||
@end table
|
||||
Notice that we first compile the looping predicate @code{l/0} with
|
||||
@code{call_counting} @code{on}. Next, we @code{catch/3} to handle an
|
||||
exception when @code{l/0} performs more than 10000 reductions.
|
||||
|
||||
|
||||
@node Arrays, Preds, Profiling , Top
|
||||
@section Arrays
|
||||
|
Reference in New Issue
Block a user