)mem f
This commit is contained in:
parent
022d760c95
commit
4ecd336595
@ -51,17 +51,25 @@ void heap_PIFn(Value* v) {
|
||||
heap_PISizes[v->type]+= mm_size(v);
|
||||
}
|
||||
|
||||
void heap_printInfo(bool sizes, bool types) {
|
||||
static u64 heap_PIFreed[128];
|
||||
void heap_PIFreedFn(Value* v) {
|
||||
heap_PIFreed[v->mmInfo&127]++;
|
||||
}
|
||||
|
||||
void mm_forFreedHeap(V2v f);
|
||||
void heap_printInfo(bool sizes, bool types, bool freed) {
|
||||
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);
|
||||
for (i32 i = 2; i < 64; i++) {
|
||||
for (i32 j = 0; j < MM; j++) {
|
||||
i32 o = i-j;
|
||||
u64 count = mm_ctrs[o + j*64];
|
||||
if (count>0) printf("size %llu: "N64u"\n", (1ULL<<o)*(j?3:1), count);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (types) {
|
||||
@ -72,5 +80,16 @@ void heap_printInfo(bool sizes, bool types) {
|
||||
if (count>0) printf("type %d/%s: count "N64u", total size "N64u"\n", i, type_repr(i), count, heap_PISizes[i]);
|
||||
}
|
||||
}
|
||||
if (freed) {
|
||||
for (i32 i = 0; i < MM*64; i++) heap_PIFreed[i] = 0;
|
||||
mm_forFreedHeap(heap_PIFreedFn);
|
||||
for (i32 i = 2; i < 64; i++) {
|
||||
for (i32 j = 0; j < MM; j++) {
|
||||
i32 o = i-j;
|
||||
u64 count = heap_PIFreed[o + j*64];
|
||||
if (count>0) printf("freed size %llu: "N64u"\n", (1ULL<<o)*(j?3:1), count);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -22,4 +22,4 @@ void heapVerify(void);
|
||||
|
||||
#endif
|
||||
|
||||
void heap_printInfo(bool sizes, bool types);
|
||||
void heap_printInfo(bool sizes, bool types, bool freed);
|
||||
|
||||
@ -197,12 +197,14 @@ int main(int argc, char* argv[]) {
|
||||
} else if (isCmd(cmdS, &cmdE, "mem ")) {
|
||||
bool sizes = 0;
|
||||
bool types = 0;
|
||||
bool freed = 0;
|
||||
char c;
|
||||
while ((c=*(cmdE++)) != 0) {
|
||||
if (c=='t') types=1;
|
||||
if (c=='s') sizes=1;
|
||||
if (c=='f') freed=1;
|
||||
}
|
||||
heap_printInfo(sizes, types);
|
||||
heap_printInfo(sizes, types, freed);
|
||||
goto cont;
|
||||
} else if (isCmd(cmdS, &cmdE, "erase ")) {
|
||||
char* name = cmdE;
|
||||
|
||||
@ -35,6 +35,10 @@ void mm_forHeap(V2v f) {
|
||||
b1_forHeap(f);
|
||||
b3_forHeap(f);
|
||||
}
|
||||
void mm_forFreedHeap(V2v f) {
|
||||
b1_forFreedHeap(f);
|
||||
b3_forFreedHeap(f);
|
||||
}
|
||||
|
||||
u64 mm_heapUsed() {
|
||||
u64 r = 0;
|
||||
|
||||
@ -85,6 +85,17 @@ void BN(forHeap)(V2v f) {
|
||||
}
|
||||
}
|
||||
}
|
||||
void BN(forFreedHeap)(V2v f) {
|
||||
for (u64 i = 0; i < alSize; i++) {
|
||||
AllocInfo ci = al[i];
|
||||
Value* s = ci.p;
|
||||
Value* e = (Value*)(ci.sz + (u8*)ci.p);
|
||||
while (s!=e) {
|
||||
if (s->type==t_empty) f(s);
|
||||
s = (Value*)(BSZ(s->mmInfo&63) + (u8*)s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef MMAP
|
||||
#undef AllocInfo
|
||||
|
||||
Loading…
Reference in New Issue
Block a user