diff --git a/C/cdmgr.c b/C/cdmgr.c index f76bd8551..4e0ab65ba 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -5416,27 +5416,55 @@ Yap_dump_code_area_for_profiler(void) { #endif /* LOW_PROF */ static UInt -index_ssz(StaticIndex *x) +tree_index_ssz(StaticIndex *x) { UInt sz = x->ClSize; x = x->ChildIndex; while (x != NULL) { - sz += index_ssz(x); + sz += tree_index_ssz(x); x = x->SiblingIndex; } return sz; } +static UInt +index_ssz(StaticIndex *x, PredEntry *pe) +{ + UInt sz = 0; + yamop *ep = ExpandClausesFirst; + if (pe->PredFlags & MegaClausePredFlag) { + MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause); + if (mcl->ClFlags & ExoMask) { + struct index_t *i = ((struct index_t **)(pe->cs.p_code.FirstClause))[0]; + sz = 0; + + while (i) { + sz = i->size+sz; + } + return sz; + } + } + /* expand clause blocks */ + while (ep) { + if (ep->u.sssllp.p == pe) + sz += (UInt)NEXTOP((yamop *)NULL,sssllp)+ep->u.sssllp.s1*sizeof(yamop *); + ep = ep->u.sssllp.snext; + } + /* main indexing tree */ + sz += tree_index_ssz(x); + return sz; +} + static Int static_statistics(PredEntry *pe) { CACHE_REGS - UInt sz = 0, cls = 0, isz = 0; + UInt sz = sizeof(PredEntry), cls = 0, isz = 0; StaticClause *cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause); if (pe->cs.p_code.NOfClauses > 1 && pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause) { - isz = index_ssz(ClauseCodeToStaticIndex(pe->cs.p_code.TrueCodeOfPred)); + isz = index_ssz(ClauseCodeToStaticIndex(pe->cs.p_code.TrueCodeOfPred), pe); } if (pe->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause); diff --git a/C/dbase.c b/C/dbase.c index a90db27ce..3f4f05d41 100755 --- a/C/dbase.c +++ b/C/dbase.c @@ -3749,7 +3749,7 @@ index_sz(LogUpdIndex *x) static Int lu_statistics(PredEntry *pe USES_REGS) { - UInt sz = 0, cls = 0, isz = 0; + UInt sz = sizeof(PredEntry), cls = 0, isz = 0; /* count number of clauses and size */ LogUpdClause *x; @@ -3765,10 +3765,16 @@ lu_statistics(PredEntry *pe USES_REGS) x = x->ClNext; } } + isz = 0; if (pe->PredFlags & IndexedPredFlag) { - isz = index_sz(ClauseCodeToLogUpdIndex(pe->cs.p_code.TrueCodeOfPred)); - } else { - isz = 0; + /* expand clause blocks */ + yamop *ep = ExpandClausesFirst; + while (ep) { + if (ep->u.sssllp.p == pe) + isz += (UInt)NEXTOP((yamop *)NULL,sssllp)+ep->u.sssllp.s1*sizeof(yamop *); + ep = ep->u.sssllp.snext; + } + isz += index_sz(ClauseCodeToLogUpdIndex(pe->cs.p_code.TrueCodeOfPred)); } return Yap_unify(ARG2,MkIntegerTerm(cls)) && diff --git a/C/exo.c b/C/exo.c index e7405b3a5..c9721f568 100644 --- a/C/exo.c +++ b/C/exo.c @@ -230,6 +230,7 @@ fill_hash(UInt bmap, struct index_t *it, UInt bnds[]) static struct index_t * add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count, UInt bnds[]) { + CACHE_REGS UInt ncls = ap->cs.p_code.NOfClauses, j; CELL *base = NULL; struct index_t *i; @@ -265,6 +266,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count, UInt bnds[] } bzero(base, 3*sizeof(CELL)*ncls); } + i->size = sizeof(CELL)*(ncls+i->hsize)+sz+sizeof(struct index_t); i->key = (CELL **)base; i->links = (CELL *)(base+i->hsize); i->ncollisions = i->nentries = i->ntrys = 0; @@ -309,6 +311,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count, UInt bnds[] ptr = NEXTOP(ptr, p); ptr->opc = Yap_opcode(_Ystop); ptr->u.l.l = i->code; + Yap_inform_profiler_of_clause((char *)(i->code), (char *)NEXTOP(ptr,l), ap, GPROF_INDEX); return i; }