Skip to content

Commit 7c89013

Browse files
committed
Add heap memory allocated benchmarking
1 parent 1955fe7 commit 7c89013

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/drivers/keyboard/scancode_handler.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ static const unsigned char KEYBOARD_ASCII_MAPH_OTHERS[] = {
193193
KEYBOARD_SC_RPF0_keypad_minus, '-',
194194
KEYBOARD_SC_RPF0_keypad_mul, '*',
195195
KEYBOARD_SC_RPF0_keypad_plus, '+',
196-
KEYBOARD_SC_PE0_RPF0_keypad_enter, '\n'
196+
KEYBOARD_SC_PE0_RPF0_keypad_enter, '\n',
197+
KEYBOARD_SC_RPF0_backspace, '\b'
197198
};
198199

199200
static unsigned char KEYBOARD_ASCII_MAPPING[256];

src/usr/include/stdlib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int min(int, int);
1818
int max(int, int);
1919
int abs(int a);
2020

21+
int benchmark_get_heap_usage();
2122
void* malloc(size_t size);
2223
void free(void* ptr);
2324

src/usr/lib/stdlib.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ extern char _heap_start[]; // defined in linker.ld
148148
static int heap_head_offset = 0;
149149
static const int heap_stack_safety_gap = 1024; // keep 1 kb free between stack and heap
150150

151+
// benchmarking
152+
static int benchmark_heap_inuse = 0;
153+
154+
int benchmark_get_heap_usage() {
155+
return benchmark_heap_inuse;
156+
}
157+
151158
void* malloc(size_t size) {
152159
void* loc = _heap_start + heap_head_offset;
153160
void* max_loc = get_current_esp()-heap_stack_safety_gap-size;
@@ -157,6 +164,7 @@ void* malloc(size_t size) {
157164
return NULL;
158165
}
159166
heap_head_offset += size;
167+
benchmark_heap_inuse += size;
160168
return loc;
161169
}
162170

src/usr/local/src/logo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ void start_logo() {
407407
void cleanup_graphics() {
408408
std::graphics::closegraph();
409409
std::cout << "logo graphics closed" << std::endl;
410+
std::cout << "heap memory at exit " <<
411+
(std::benchmark_get_heap_usage()/1024) << "KB" << std::endl;
410412
}
411413

412414
int show_usage() {

0 commit comments

Comments
 (0)