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


The following commit(s) were added to refs/heads/master by this push:
     new 70791af8e2 procmeminfo:support memdump can show specific task
70791af8e2 is described below

commit 70791af8e21c03211712538a60b806957d9e88b2
Author: anjiahao <[email protected]>
AuthorDate: Thu Nov 10 20:32:34 2022 +0800

    procmeminfo:support memdump can show specific task
    
    Signed-off-by: anjiahao <[email protected]>
---
 fs/procfs/fs_procfsmeminfo.c | 31 +++++++++++++++++++++++++++++++
 include/nuttx/sched.h        |  3 ++-
 mm/mm_heap/mm.h              |  5 ++++-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c
index fa847657cb..fbdca5d294 100644
--- a/fs/procfs/fs_procfsmeminfo.c
+++ b/fs/procfs/fs_procfsmeminfo.c
@@ -40,6 +40,7 @@
 #include <nuttx/kmalloc.h>
 #include <nuttx/pgalloc.h>
 #include <nuttx/progmem.h>
+#include <nuttx/sched.h>
 #include <nuttx/mm/mm.h>
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/procfs.h>
@@ -452,6 +453,10 @@ static ssize_t memdump_write(FAR struct file *filep, FAR 
const char *buffer,
   FAR struct procfs_meminfo_entry_s *entry;
   FAR struct meminfo_file_s *procfile;
   pid_t pid = INVALID_PROCESS_ID;
+#if CONFIG_MM_BACKTRACE > 0
+  FAR struct tcb_s *tcb;
+  FAR char *p;
+#endif
 
   DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0);
 
@@ -479,6 +484,32 @@ static ssize_t memdump_write(FAR struct file *filep, FAR 
const char *buffer,
 
       return buflen;
     }
+  else if ((p = strstr(buffer, "on")) != NULL)
+    {
+      *p = '\0';
+      pid = atoi(buffer);
+      tcb = nxsched_get_tcb(pid);
+      if (tcb == NULL)
+        {
+          return -EINVAL;
+        }
+
+      tcb->flags |= TCB_FLAG_HEAP_DUMP;
+      return buflen;
+    }
+  else if ((p = strstr(buffer, "off")) != NULL)
+    {
+      *p = '\0';
+      pid = atoi(buffer);
+      tcb = nxsched_get_tcb(pid);
+      if (tcb == NULL)
+        {
+          return -EINVAL;
+        }
+
+      tcb->flags &= ~TCB_FLAG_HEAP_DUMP;
+      return buflen;
+    }
 #endif
 
   switch (buffer[0])
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index c9f2455451..e84c15a773 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -102,7 +102,8 @@
 #define TCB_FLAG_EXIT_PROCESSING   (1 << 11)                     /* Bit 10: 
Exitting */
 #define TCB_FLAG_FREE_STACK        (1 << 12)                     /* Bit 12: 
Free stack after exit */
 #define TCB_FLAG_HEAP_CHECK        (1 << 13)                     /* Bit 13: 
Heap check */
-                                                                 /* Bits 
14-15: Available */
+#define TCB_FLAG_HEAP_DUMP         (1 << 14)                     /* Bit 14: 
Heap dump */
+                                                                 /* Bits 15: 
Available */
 
 /* Values for struct task_group tg_flags */
 
diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index dc444d94be..a8afdea8f3 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -28,6 +28,7 @@
 #include <nuttx/config.h>
 
 #include <nuttx/mutex.h>
+#include <nuttx/sched.h>
 #include <nuttx/fs/procfs.h>
 #include <nuttx/lib/math32.h>
 
@@ -82,8 +83,10 @@
        { \
          FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \
          kasan_unpoison(tmp, SIZEOF_MM_ALLOCNODE); \
+         FAR strcut tcb_s *tcb; \
          tmp->pid = gettid(); \
-         if ((heap)->mm_procfs.backtrace) \
+         tcb = nxsched_get_tcb(tmp->pid); \
+         if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & 
TCB_FLAG_HEAP_DUMP)) \
            { \
              memset(tmp->backtrace, 0, sizeof(tmp->backtrace)); \
              backtrace(tmp->backtrace, CONFIG_MM_BACKTRACE); \

Reply via email to