files: add files_dumplist api, replace dumponexit implementation

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2024-06-25 11:28:11 +08:00 committed by Xiang Xiao
parent b0698daaa4
commit 5a31d52fd8
4 changed files with 79 additions and 18 deletions

View file

@ -1041,7 +1041,6 @@ config ARCH_STACKDUMP_MAX_LENGTH
config DUMP_ON_EXIT
bool "Dump all tasks state on exit"
default n
depends on DEBUG_SCHED_INFO
---help---
Dump all tasks state on exit()

View file

@ -27,14 +27,17 @@
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <execinfo.h>
#include <sched.h>
#include <errno.h>
#include <fcntl.h>
#include <debug.h>
#include <stdio.h>
#include <nuttx/fs/fs.h>
#include <nuttx/kmalloc.h>
#include <nuttx/cancelpt.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/mutex.h>
#include <nuttx/sched.h>
#include <nuttx/spawn.h>
@ -308,6 +311,67 @@ void files_initlist(FAR struct filelist *list)
list->fl_prefile = list->fl_prefiles;
}
/****************************************************************************
* Name: files_dumplist
*
* Description:
* Dump the list of files.
*
****************************************************************************/
void files_dumplist(FAR struct filelist *list)
{
int count = files_countlist(list);
int i;
syslog(LOG_INFO, "%-4s%-4s%-8s%-5s%-10s%-14s"
#if CONFIG_FS_BACKTRACE > 0
" BACKTRACE"
#endif
"\n",
"PID", "FD", "FLAGS", "TYPE", "POS", "PATH"
);
for (i = 0; i < count; i++)
{
FAR struct file *filep = files_fget(list, i);
char path[PATH_MAX];
#if CONFIG_FS_BACKTRACE > 0
char buf[BACKTRACE_BUFFER_SIZE(CONFIG_FS_BACKTRACE)];
#endif
/* Is there an inode associated with the file descriptor? */
if (filep == NULL || filep->f_inode == NULL)
{
continue;
}
if (file_ioctl(filep, FIOC_FILEPATH, path) < 0)
{
path[0] = '\0';
}
#if CONFIG_FS_BACKTRACE > 0
backtrace_format(buf, sizeof(buf), filep->f_backtrace,
CONFIG_FS_BACKTRACE);
#endif
syslog(LOG_INFO, "%-4d%-4d%-8d%-5x%-10ld%-14s"
#if CONFIG_FS_BACKTRACE > 0
" %s"
#endif
"\n", getpid(), i, filep->f_oflags,
INODE_GET_TYPE(filep->f_inode),
(long)filep->f_pos, path
#if CONFIG_FS_BACKTRACE > 0
, buf
#endif
);
}
}
/****************************************************************************
* Name: files_releaselist
*

View file

@ -864,6 +864,16 @@ int nx_umount2(FAR const char *target, unsigned int flags);
void files_initlist(FAR struct filelist *list);
/****************************************************************************
* Name: files_dumplist
*
* Description:
* Dump the list of files.
*
****************************************************************************/
void files_dumplist(FAR struct filelist *list);
/****************************************************************************
* Name: files_releaselist
*

View file

@ -52,26 +52,14 @@
static void dumphandler(FAR struct tcb_s *tcb, FAR void *arg)
{
FAR struct filelist *filelist;
int i;
int j;
sinfo(" TCB=%p name=%s\n", tcb, tcb->name);
sinfo(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
syslog(LOG_INFO, "tcb=%p name=%s, pid:%d, priority=%d state=%d "
"stack_alloc_ptr: %p, adj_stack_size: %zu\n",
tcb, tcb->name, tcb->pid, tcb->sched_priority, tcb->task_state,
tcb->stack_alloc_ptr, tcb->adj_stack_size);
filelist = &tcb->group->tg_filelist;
for (i = 0; i < filelist->fl_rows; i++)
{
for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
{
struct inode *inode = filelist->fl_files[i][j].f_inode;
if (inode)
{
sinfo(" fd=%d refcount=%d\n",
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j,
inode->i_crefs);
}
}
}
files_dumplist(filelist);
}
/****************************************************************************