This commit is contained in:
Vitor Santos Costa
2018-09-14 17:43:36 +01:00
parent f8d0703983
commit 46a32fbd83
5 changed files with 34 additions and 11 deletions

View File

@@ -42,6 +42,12 @@ static char SccsId[] = "%W% %G%";
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
@@ -383,6 +389,16 @@ void Yap_InitHeap(void *heap_addr) {
HeapMax = 0;
}
// get an approximation to total memory data-base size.
size_t Yap_HeapUsed(void)
{
#if HAVE_MALLINFO
struct mallinfo mi = mallinfo();
return mi.uordblks - (LOCAL_TrailTop-LOCAL_GlobalBase);
#endif
return Yap_ClauseSpace+Yap_IndexSpace_Tree+Yap_LUClauseSpace+Yap_LUIndexSpace_CP;
}
static void InitExStacks(int wid, int Trail, int Stack) {
CACHE_REGS
UInt pm, sa;

View File

@@ -112,6 +112,7 @@ static char SccsId[] = "%W% %G%";
#include "Yatom.h"
#include "YapHeap.h"
#include "YapEval.h"
#include "alloc.h"
@@ -174,7 +175,7 @@ eval0(Int fi) {
/// - heapused
/// Heap (data-base) space used, in bytes.
///
RINT(HeapUsed);
RINT(Yap_HeapUsed());
case op_localsp:
/// - local
/// Local stack in use, in bytes

View File

@@ -836,6 +836,7 @@ static void ReadHash(FILE *stream) {
UInt sz = read_UInt(stream);
UInt nrefs = read_UInt(stream);
LogUpdClause *ncl = (LogUpdClause *)Yap_AlwaysAllocCodeSpace(sz);
Yap_LUClauseSpace += sz;
if (!ncl) {
QLYR_ERROR(OUT_OF_CODE_SPACE);
}
@@ -874,6 +875,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses,
nrefs = cl->ClRefCount;
} else {
cl = (LogUpdClause *)Yap_AlwaysAllocCodeSpace(size);
Yap_LUClauseSpace += size;
}
read_bytes(stream, cl, size);
cl->ClFlags &= ~InUseMask;
@@ -887,6 +889,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses,
char *base = (void *)read_UInt(stream);
UInt mask = read_UInt(stream);
UInt size = read_UInt(stream);
Yap_ClauseSpace += size;
MegaClause *cl = (MegaClause *)Yap_AlwaysAllocCodeSpace(size);
if (nclauses) {
@@ -918,6 +921,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses,
char *base = (void *)read_UInt(stream);
UInt size = read_UInt(stream);
DynamicClause *cl = (DynamicClause *)Yap_AlwaysAllocCodeSpace(size);
Yap_LUClauseSpace += size;
LOCAL_HDiff = (char *)cl - base;
read_bytes(stream, cl, size);
@@ -948,6 +952,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses,
char *base = (void *)read_UInt(stream);
UInt size = read_UInt(stream);
StaticClause *cl = (StaticClause *)Yap_AlwaysAllocCodeSpace(size);
Yap_ClauseSpace += size;
LOCAL_HDiff = (char *)cl - base;
read_bytes(stream, cl, size);