Skip to content

Commit

Permalink
fs/procfs: refine file backtrace
Browse files Browse the repository at this point in the history
remove backtrace arrary in stack

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Jun 28, 2024
1 parent 365e9e9 commit 0da37b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 54 deletions.
21 changes: 0 additions & 21 deletions fs/inode/fs_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,27 +490,6 @@ int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
pos, priv, minfd, addref);
}

FAR char *file_dump_backtrace(FAR struct file *filep, FAR char *buffer,
size_t len)
{
#if CONFIG_FS_BACKTRACE > 0
FAR const char *format = "%0*p ";
int k;

buffer[0] = '\0';
for (k = 0; k < CONFIG_FS_BACKTRACE && filep->f_backtrace[k]; k++)
{
snprintf(buffer + k * FS_BACKTRACE_WIDTH,
len - k * FS_BACKTRACE_WIDTH,
format, FS_BACKTRACE_WIDTH - 1,
filep->f_backtrace[k]);
}
#else
buffer[0] = '\0';
#endif
return buffer;
}

/****************************************************************************
* Name: files_duplist
*
Expand Down
55 changes: 39 additions & 16 deletions fs/procfs/fs_procfsproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,38 @@ static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile,
return totalsize;
}

/****************************************************************************
* Name: procfs_format_backtrace
****************************************************************************/

static int procfs_format_backtrace(FAR char *buffer, size_t total,
FAR struct file *filep)
{
int offset = 0;

#if CONFIG_FS_BACKTRACE > 0
FAR const char *format = "%0*p ";
int width = sizeof(uintptr_t) * 2 + 3; /* 3: ' 0x' prefix */
int i;

for (i = 0; i < CONFIG_FS_BACKTRACE; i++)
{
if (filep->f_backtrace[i] == NULL || offset + width > total)
{
break;
}

offset += snprintf(buffer + offset, total,
format, width - 1,
filep->f_backtrace[i]);
}
#endif /* CONFIG_FS_BACKTRACE */

buffer[offset++] = '\n';

return offset;
}

/****************************************************************************
* Name: proc_groupfd
****************************************************************************/
Expand All @@ -1244,17 +1276,15 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
size_t buflen, off_t offset)
{
FAR struct task_group_s *group = tcb->group;
FAR struct file *filep;
char path[PATH_MAX];
size_t remaining;
size_t linesize;
size_t copysize;
size_t totalsize;
int count;
int i;

FAR struct file *filep;
char path[PATH_MAX];
char backtrace[FS_BACKTRACE_BUFFER_LEN];

DEBUGASSERT(group != NULL);

count = files_countlist(&group->tg_filelist);
Expand Down Expand Up @@ -1306,22 +1336,15 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
}

linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
"%-3d %-7d %-4x %-9ld %-14s %s\n",
"%-3d %-7d %-4x %-9ld %-14s ",
i, filep->f_oflags,
INODE_GET_TYPE(filep->f_inode),
(long)filep->f_pos, path,
file_dump_backtrace(filep,
backtrace,
sizeof(backtrace)
)
);
(long)filep->f_pos, path);
linesize += procfs_format_backtrace(procfile->line + linesize,
STATUS_LINELEN - linesize,
filep);
copysize = procfs_memcpy(procfile->line, linesize,
buffer, remaining, &offset);
if (linesize + 1 == STATUS_LINELEN)
{
procfile->line[STATUS_LINELEN - 2] = '\n';
linesize = STATUS_LINELEN;
}

totalsize += copysize;
buffer += copysize;
Expand Down
17 changes: 0 additions & 17 deletions include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@
#define CH_STAT_ATIME (1 << 3)
#define CH_STAT_MTIME (1 << 4)

#define FS_BACKTRACE_WIDTH (sizeof(uintptr_t) * 2 + 3) /* 3: ' 0x' prefix */
#define FS_BACKTRACE_BUFFER_LEN (CONFIG_FS_BACKTRACE * FS_BACKTRACE_WIDTH + 1)

/****************************************************************************
* Public Type Definitions
****************************************************************************/
Expand Down Expand Up @@ -953,20 +950,6 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
int file_allocate(FAR struct inode *inode, int oflags, off_t pos,
FAR void *priv, int minfd, bool addref);

/****************************************************************************
* Name: file_dump_backtrace
*
* Description:
* Dump the backtrace of the file open to given buffer.
*
* Returned Value:
* Returns the backtrace string, it could be empty.
*
****************************************************************************/

FAR char *file_dump_backtrace(FAR struct file *filep, FAR char *buffer,
size_t len);

/****************************************************************************
* Name: file_dup
*
Expand Down

0 comments on commit 0da37b5

Please sign in to comment.