Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HAL] Improve memory tracer #2596

Merged
merged 1 commit into from Sep 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions hal/common/mbed_alloc_wrappers.cpp
Expand Up @@ -46,15 +46,23 @@ typedef struct {
uint32_t pad;
} alloc_info_t;

static SingletonPtr<PlatformMutex> malloc_stats_mutex;
#ifdef MBED_MEM_TRACING_ENABLED
static SingletonPtr<PlatformMutex> mem_trace_mutex;
#endif
#ifdef MBED_HEAP_STATS_ENABLED
static SingletonPtr<PlatformMutex> malloc_stats_mutex;
static mbed_stats_heap_t heap_stats = {0, 0, 0, 0, 0};
#endif

void mbed_stats_heap_get(mbed_stats_heap_t *stats)
{
#ifdef MBED_HEAP_STATS_ENABLED
malloc_stats_mutex->lock();
memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t));
malloc_stats_mutex->unlock();
#else
memset(stats, 0, sizeof(mbed_stats_heap_t));
#endif
}

/******************************************************************************/
Expand Down Expand Up @@ -259,12 +267,12 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
free(ptr);
}
#else // #ifdef MBED_HEAP_STATS_ENABLED
mem_trace_mutex->lock();
new_ptr = $Super$$realloc(ptr, size);
mem_trace_mutex->unlock();
#endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mem_trace_mutex->lock();
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mem_trace_mutex->unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return new_ptr;
}
Expand Down