This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit af3d5e2212dc916df31d3581af7b8d403a06f955 Author: ganjing <[email protected]> AuthorDate: Mon Jan 26 14:26:37 2026 +0800 fs/procfs: Add mallinfo and memdump callback to procfs_meminfo_entry_s so the implementation can do the customized action through hook Signed-off-by: ganjing <[email protected]> --- fs/procfs/fs_procfsmeminfo.c | 37 +++++++++++++++++++++++++------------ include/nuttx/fs/procfs.h | 6 ++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c index 7e5b4a80047..dcf2277c0d7 100644 --- a/fs/procfs/fs_procfsmeminfo.c +++ b/fs/procfs/fs_procfsmeminfo.c @@ -98,18 +98,18 @@ static void meminfo_progmem(FAR struct progmem_info_s *progmem); /* File system methods */ static int meminfo_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); + int oflags, mode_t mode); static int meminfo_close(FAR struct file *filep); #ifndef CONFIG_FS_PROCFS_EXCLUDE_MEMDUMP static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); + size_t buflen); static ssize_t memdump_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); #endif static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); + size_t buflen); static int meminfo_dup(FAR const struct file *oldp, - FAR struct file *newp); + FAR struct file *newp); static int meminfo_stat(FAR const char *relpath, FAR struct stat *buf); /**************************************************************************** @@ -230,7 +230,7 @@ static void meminfo_progmem(FAR struct progmem_info_s *progmem) ****************************************************************************/ static int meminfo_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) + int oflags, mode_t mode) { FAR struct meminfo_file_s *procfile; @@ -320,7 +320,15 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer, /* Show heap information */ - info = mm_mallinfo(entry->heap); + if (entry->mallinfo) + { + info = entry->mallinfo(entry->heap); + } + else + { + info = mm_mallinfo(entry->heap); + } + linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN, "%11lu%11lu%11lu%11lu%11lu" "%7lu%7lu %s\n", @@ -633,7 +641,14 @@ dump: for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next) { - mm_memdump(entry->heap, &dump); + if (entry->memdump) + { + entry->memdump(entry->heap, &dump); + } + else + { + mm_memdump(entry->heap, &dump); + } } return buflen; @@ -713,13 +728,11 @@ static int meminfo_stat(FAR const char *relpath, FAR struct stat *buf) void procfs_register_meminfo(FAR struct procfs_meminfo_entry_s *entry) { - if (NULL == entry->name) + if (entry->name != NULL) { - return; + entry->next = g_procfs_meminfo; + g_procfs_meminfo = entry; } - - entry->next = g_procfs_meminfo; - g_procfs_meminfo = entry; } /**************************************************************************** diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index bdffda4bb05..35ebca03334 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -130,12 +130,18 @@ struct procfs_dir_priv_s /* An entry for procfs_register_meminfo */ +struct mallinfo; struct mm_heap_s; +struct mm_memdump_s; + struct procfs_meminfo_entry_s { FAR const char *name; FAR struct mm_heap_s *heap; FAR struct procfs_meminfo_entry_s *next; + struct mallinfo (*mallinfo)(FAR struct mm_heap_s *); + void (*memdump)(FAR struct mm_heap_s *, + FAR const struct mm_memdump_s *); #if CONFIG_MM_BACKTRACE >= 0 /* This is dynamic control flag whether to turn on backtrace in the heap,
