Add a debug function to dump heap usage
This commit is contained in:
parent
d54c882c63
commit
29defdf54d
@ -328,4 +328,36 @@ Result<void*> kcalloc(usize nmemb, usize size)
|
|||||||
usize realsize = nmemb * size;
|
usize realsize = nmemb * size;
|
||||||
void* ptr = TRY(kmalloc(realsize));
|
void* ptr = TRY(kmalloc(realsize));
|
||||||
return memset(ptr, 0, realsize);
|
return memset(ptr, 0, realsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_heap_usage()
|
||||||
|
{
|
||||||
|
Serial::println("-- Dumping usage stats for kernel heap:");
|
||||||
|
if (!heap_start)
|
||||||
|
{
|
||||||
|
Serial::println("- Heap is not currently being used");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
usize alloc_total = 0;
|
||||||
|
usize alloc_used = 0;
|
||||||
|
HeapBlock* block = heap_start;
|
||||||
|
while (block)
|
||||||
|
{
|
||||||
|
if (is_block_free(block))
|
||||||
|
{
|
||||||
|
Serial::printf("- Available block, of size %zu\n", block->full_size);
|
||||||
|
alloc_total += block->full_size + sizeof(HeapBlock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial::printf("- Used block, of size %zu, of which %zu bytes are being used\n", block->full_size,
|
||||||
|
block->req_size);
|
||||||
|
alloc_total += block->full_size + sizeof(HeapBlock);
|
||||||
|
alloc_used += block->req_size;
|
||||||
|
}
|
||||||
|
block = block->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial::printf("-- Total memory allocated for heap: %zu bytes\n", alloc_total);
|
||||||
|
Serial::printf("-- Heap memory in use by the kernel: %zu bytes\n", alloc_used);
|
||||||
}
|
}
|
@ -17,4 +17,6 @@ template <typename T> Result<void> destroy(T* item)
|
|||||||
{
|
{
|
||||||
item->~T();
|
item->~T();
|
||||||
return kfree(item);
|
return kfree(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dump_heap_usage();
|
Loading…
Reference in New Issue
Block a user