)gc, )mem

This commit is contained in:
dzaima 2021-12-01 17:09:19 +02:00
parent c8b15987b5
commit 3c09781d1a
3 changed files with 50 additions and 0 deletions

View File

@ -42,3 +42,35 @@ void heapVerify() {
}
#endif
static u64 heap_PICounts[t_COUNT];
static u64 heap_PISizes[t_COUNT];
void heap_PIFn(Value* v) {
heap_PICounts[v->type]++;
heap_PISizes[v->type]+= mm_size(v);
}
void heap_printInfo(bool sizes, bool types) {
u64 total = mm_heapAlloc;
u64 used = mm_heapUsed();
printf("RAM allocated: "N64u"\n", total);
printf("heap in use: "N64u"\n", used);
#if MM!=0
if (sizes) {
i32 count = sizeof(mm_ctrs)/8;
for (i32 i = 0; i < count; i++) {
u64 count = mm_ctrs[i];
if (count>0) printf("size %llu: "N64u"\n", i>64? 1ULL<<(i*3) : 1ULL<<i, count);
}
}
if (types) {
for (i32 i = 0; i < t_COUNT; i++) heap_PICounts[i] = heap_PISizes[i] = 0;
mm_forHeap(heap_PIFn);
for (i32 i = 0; i < t_COUNT; i++) {
u64 count = heap_PICounts[i];
if (count>0) printf("type %d/%s: count "N64u", total size "N64u"\n", i, type_repr(i), count, heap_PISizes[i]);
}
}
#endif
}

View File

@ -21,3 +21,5 @@ static bool heapVerify_visitP(void* x) {
void heapVerify(void);
#endif
void heap_printInfo(bool sizes, bool types);

View File

@ -30,6 +30,7 @@ static B gsc_exec_inline(B src, B path, B args) {
static bool isCmd(char* s, char** e, const char* cmd) {
while (*cmd) {
if (*cmd==' ' && *s==0) { *e = s; return true; }
if (*s!=*cmd || *s==0) return false;
s++; cmd++;
}
@ -191,6 +192,21 @@ int main(int argc, char* argv[]) {
code = fromUTF8l(repE);
time = am;
output = false;
} else if (isCmd(cmdS, &cmdE, "mem ")) {
bool sizes = 0;
bool types = 0;
char c;
while ((c=*(cmdE++)) != 0) {
if (c=='t') types=1;
if (c=='s') sizes=1;
}
heap_printInfo(sizes, types);
goto cont;
} else if (isCmd(cmdS, &cmdE, "gc ")) {
if (gc_depth!=0) printf("Cannot GC currently\n");
else if (ENABLE_GC) gc_forceGC();
else printf("Macro ENABLE_GC was false at compile-time, cannot GC\n");
goto cont;
} else {
printf("Unknown REPL command\n");
goto cont;