mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 09:38:37 +08:00
procfs: Add procfs_register_meminfo
This allows subsystems to register their mallinfo-like functions to be shown in /proc/meminfo.
This commit is contained in:
committed by
David Sidrane
parent
f56ff40101
commit
f305cefe82
@@ -122,6 +122,8 @@ const struct procfs_operations meminfo_operations =
|
|||||||
meminfo_stat /* stat */
|
meminfo_stat /* stat */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FAR struct procfs_meminfo_entry_s *g_procfs_meminfo = NULL;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -291,6 +293,33 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
|
|
||||||
/* Followed by information about the memory resources */
|
/* Followed by information about the memory resources */
|
||||||
|
|
||||||
|
FAR const struct procfs_meminfo_entry_s *entry;
|
||||||
|
|
||||||
|
for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next)
|
||||||
|
{
|
||||||
|
if (totalsize < buflen)
|
||||||
|
{
|
||||||
|
struct mallinfo minfo;
|
||||||
|
|
||||||
|
buffer += copysize;
|
||||||
|
buflen -= copysize;
|
||||||
|
|
||||||
|
/* Show heap information */
|
||||||
|
|
||||||
|
entry->mallinfo(entry->user_data, &minfo);
|
||||||
|
linesize = snprintf(procfile->line, MEMINFO_LINELEN,
|
||||||
|
"%4s: %11lu%11lu%11lu%11lu\n",
|
||||||
|
entry->name,
|
||||||
|
(unsigned long)minfo.arena,
|
||||||
|
(unsigned long)minfo.uordblks,
|
||||||
|
(unsigned long)minfo.fordblks,
|
||||||
|
(unsigned long)minfo.mxordblk);
|
||||||
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
||||||
|
buflen, &offset);
|
||||||
|
totalsize += copysize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_MM_KERNEL_HEAP
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||||
if (totalsize < buflen)
|
if (totalsize < buflen)
|
||||||
{
|
{
|
||||||
@@ -462,4 +491,21 @@ static int meminfo_stat(FAR const char *relpath, FAR struct stat *buf)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: procfs_register_meminfo
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Add a new meminfo entry to the procfs file system.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* entry - Describes the entry to be registered.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void procfs_register_meminfo(FAR struct procfs_meminfo_entry_s *entry)
|
||||||
|
{
|
||||||
|
entry->next = g_procfs_meminfo;
|
||||||
|
g_procfs_meminfo = entry;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_FS_PROCFS_EXCLUDE_MEMINFO */
|
#endif /* !CONFIG_FS_PROCFS_EXCLUDE_MEMINFO */
|
||||||
|
|||||||
@@ -140,6 +140,17 @@ struct procfs_dir_priv_s
|
|||||||
FAR const struct procfs_entry_s *procfsentry; /* Pointer to procfs handler entry */
|
FAR const struct procfs_entry_s *procfsentry; /* Pointer to procfs handler entry */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* An entry for procfs_register_meminfo */
|
||||||
|
|
||||||
|
struct procfs_meminfo_entry_s
|
||||||
|
{
|
||||||
|
FAR const char *name;
|
||||||
|
CODE void (*mallinfo)(FAR void *user_data, FAR struct mallinfo *);
|
||||||
|
FAR void *user_data;
|
||||||
|
|
||||||
|
struct procfs_meminfo_entry_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -220,6 +231,19 @@ size_t procfs_memcpy(FAR const char *src, size_t srclen,
|
|||||||
int procfs_register(FAR const struct procfs_entry_s *entry);
|
int procfs_register(FAR const struct procfs_entry_s *entry);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: procfs_register_meminfo
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Add a new meminfo entry to the procfs file system.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* entry - Describes the entry to be registered.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void procfs_register_meminfo(FAR struct procfs_meminfo_entry_s *entry);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user