malloc: Add call counters for malloc, free, realloc

Add counters to track the number of calls to malloc(), free(), and
realloc(). These are displayed by the 'malloc info' command and
accessible via malloc_get_info().

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-11-28 09:28:21 -07:00
parent cfbee94582
commit d8b19014d7
5 changed files with 41 additions and 6 deletions

View File

@@ -21,8 +21,11 @@ static int do_malloc_info(struct cmd_tbl *cmdtp, int flag, int argc,
if (ret)
return CMD_RET_FAILURE;
printf("total bytes = %s\n", format_size(buf, info.total_bytes));
printf("in use bytes = %s\n", format_size(buf, info.in_use_bytes));
printf("total bytes = %s\n", format_size(buf, info.total_bytes));
printf("in use bytes = %s\n", format_size(buf, info.in_use_bytes));
printf("malloc count = %lu\n", info.malloc_count);
printf("free count = %lu\n", info.free_count);
printf("realloc count = %lu\n", info.realloc_count);
return 0;
}