malloc: Add 'malloc' command with 'info' subcommand

Add a command to display malloc heap statistics, showing total heap
size and memory currently in use.

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 08:54:29 -07:00
parent bd0f9a753c
commit cfbee94582
7 changed files with 121 additions and 0 deletions

45
doc/usage/cmd/malloc.rst Normal file
View File

@@ -0,0 +1,45 @@
.. SPDX-License-Identifier: GPL-2.0+:
.. index::
single: malloc (command)
malloc command
==============
Synopsis
--------
::
malloc info
Description
-----------
The malloc command shows information about the malloc heap.
info
Shows memory-allocation statistics, including the total heap size and the
amount currently in use.
The total heap size is set by ``CONFIG_SYS_MALLOC_LEN``.
Example
-------
::
=> malloc info
total bytes = 96 MiB
in use bytes = 700.9 KiB
Configuration
-------------
The malloc command is enabled by CONFIG_CMD_MALLOC which depends on
CONFIG_MALLOC_DEBUG.
Return value
------------
The return value $? is 0 (true) on success, 1 (false) on failure.

View File

@@ -97,6 +97,7 @@ Shell commands
cmd/loadx
cmd/loady
cmd/luks
cmd/malloc
cmd/meminfo
cmd/mbr
cmd/md