Skip to content

Commit

Permalink
fixup! sys: add malloc_monitor, deprecate malloc_tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
mguetschow committed Mar 25, 2024
1 parent a8f68e6 commit 4f2a3c9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions sys/malloc_monitor/malloc_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void malloc_monitor_add(void *ptr, size_t size, uinttxtptr_t pc, char *func_pref
if (ptr == NULL) {
return;
}
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("%salloc(%" PRIuSIZE ") @ 0x%" PRIxTXTPTR " returned %p\n",
func_prefix, size, pc, ptr);
#endif
assert(!irq_is_in());
mutex_lock(&_lock);
for (uint8_t i=0; i<CONFIG_MODULE_SYS_MALLOC_MONITOR_SIZE; i++) {
Expand All @@ -64,10 +68,6 @@ void malloc_monitor_add(void *ptr, size_t size, uinttxtptr_t pc, char *func_pref
malloc_monitor.high_watermark = malloc_monitor.current;
}
mutex_unlock(&_lock);
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("%salloc(%" PRIuSIZE ") @ 0x%" PRIxTXTPTR " returned %p\n",
func_prefix, size, pc, ptr);
#endif
return;
}
}
Expand All @@ -83,16 +83,16 @@ void malloc_monitor_rm(void *ptr, uinttxtptr_t pc)
if (ptr == NULL) {
return;
}
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("malloc_monitor: free(%p) @ 0x%" PRIxTXTPTR " \n", ptr, pc);
#endif
assert(!irq_is_in());
mutex_lock(&_lock);
for (uint8_t i=0; i<CONFIG_MODULE_SYS_MALLOC_MONITOR_SIZE; i++) {
if (malloc_monitor.addr[i] == ptr) {
malloc_monitor.addr[i] = NULL;
malloc_monitor.current -= malloc_monitor.size[i];
mutex_unlock(&_lock);
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("malloc_monitor: free(%p) @ 0x%" PRIxTXTPTR " \n", ptr, pc);
#endif
return;
}
}
Expand All @@ -113,6 +113,10 @@ void malloc_monitor_mv(void *ptr_old, void *ptr_new, size_t size_new, uinttxtptr
if (ptr_new == NULL) {
return;
}
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("malloc_monitor: realloc(%p, %" PRIuSIZE ") @0x%" PRIxTXTPTR " returned %p\n",
ptr_old, size_new, pc, ptr_new);
#endif
assert(!irq_is_in());
mutex_lock(&_lock);
for (uint8_t i=0; i<CONFIG_MODULE_SYS_MALLOC_MONITOR_SIZE; i++) {
Expand All @@ -130,10 +134,6 @@ void malloc_monitor_mv(void *ptr_old, void *ptr_new, size_t size_new, uinttxtptr
malloc_monitor.current -= size_old - size_new;
}
mutex_unlock(&_lock);
#if CONFIG_MODULE_SYS_MALLOC_MONITOR_VERBOSE
printf("malloc_monitor: realloc(%p, %" PRIuSIZE ") @0x%" PRIxTXTPTR " returned %p\n",
ptr_old, size_new, pc, ptr_new);
#endif
return;
}
}
Expand Down

0 comments on commit 4f2a3c9

Please sign in to comment.