mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
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 <ganjing@xiaomi.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user