mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #2596 from neilt6/neilt6-memory-tracer-patch
[HAL] Improve memory tracerpull/2661/head
commit
b2ce50a8d3
|
|
@ -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
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
@ -260,12 +268,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue