SayoriOS 0.3.3

memmeter.c
1 #include "common.h"
2 #include "mem/vmm.h"
3 #include "io/ports.h"
4
5 void memmeter(void (*function)()) {
6 size_t mem_before = system_heap.used_memory;
7 size_t mem_before_cnt = system_heap.allocated_count;
8
9 function();
10
11 size_t mem_after = system_heap.used_memory;
12 size_t mem_after_cnt = system_heap.allocated_count;
13
14 int delta = (int)mem_after - (int)mem_before;
15
16 qemu_warn("Memory delta: %d bytes (%d objects)",
17 delta, mem_after_cnt - mem_before_cnt);
18
19 if(delta > 0) {
20 qemu_err("Memory leak!");
21 } else if(delta == 0) {
22 qemu_ok("No memory leak! :)");
23 }
24 }
common.h
Основные определения ядра