[FL-1326] Move heap4 allocator to furi core and add allocation tracing capability (#529)

* Move heap memory allocator to furi core
* Newlibc: add malloc guards
* Furi: add cmsis thread id getter
* Core: add tracing capability to heap allocator. Add heap tracing support to furi thread. Add heap trace support to app-loader.
This commit is contained in:
あく
2021-06-23 17:48:44 +03:00
committed by GitHub
parent 6ec9c6cc49
commit 359bbdfe69
10 changed files with 600 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
#include "thread.h"
#include "memmgr.h"
#include "memmgr_heap.h"
#include "check.h"
#include <m-string.h>
@@ -16,6 +17,9 @@ struct FuriThread {
osThreadAttr_t attr;
osThreadId_t id;
bool heap_trace_enabled;
size_t heap_size;
};
void furi_thread_set_state(FuriThread* thread, FuriThreadState state) {
@@ -33,8 +37,17 @@ void furi_thread_body(void* context) {
furi_assert(thread->state == FuriThreadStateStarting);
furi_thread_set_state(thread, FuriThreadStateRunning);
if(thread->heap_trace_enabled == true) {
memmgr_heap_enable_thread_trace(thread->id);
}
thread->ret = thread->callback(thread->context);
if(thread->heap_trace_enabled == true) {
thread->heap_size = memmgr_heap_get_thread_memory(thread->id);
memmgr_heap_disable_thread_trace(thread->id);
}
furi_assert(thread->state == FuriThreadStateRunning);
furi_thread_set_state(thread, FuriThreadStateStopped);
@@ -125,3 +138,27 @@ osStatus_t furi_thread_join(FuriThread* thread) {
furi_assert(thread);
return osThreadJoin(thread->id);
}
osThreadId_t furi_thread_get_thread_id(FuriThread* thread) {
return thread->id;
}
void furi_thread_enable_heap_trace(FuriThread* thread) {
furi_assert(thread);
furi_assert(thread->state == FuriThreadStateStopped);
furi_assert(thread->heap_trace_enabled == false);
thread->heap_trace_enabled = true;
}
void furi_thread_disable_heap_trace(FuriThread* thread) {
furi_assert(thread);
furi_assert(thread->state == FuriThreadStateStopped);
furi_assert(thread->heap_trace_enabled == true);
thread->heap_trace_enabled = false;
}
size_t furi_thread_get_heap_size(FuriThread* thread) {
furi_assert(thread);
furi_assert(thread->heap_trace_enabled == true);
return thread->heap_size;
}