pkarashchenko commented on a change in pull request #5855:
URL: https://github.com/apache/incubator-nuttx/pull/5855#discussion_r835789639



##########
File path: mm/mm_heap/mm.h
##########
@@ -93,17 +93,24 @@
 #ifdef CONFIG_DEBUG_MM
 #  define MM_MIN_SHIFT       (MM_MIN_SHIFT_ + 2)
 #  define MM_BACKTRACE_DEPTH 8
-#  define MM_ADD_BACKTRACE(ptr) \
+#  define MM_ADD_BACKTRACE(heap, ptr) \
      do \
        { \
          FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \
          tmp->pid = getpid(); \
-         memset(tmp->backtrace, 0, sizeof(tmp->backtrace)); \
-         backtrace(tmp->backtrace, MM_BACKTRACE_DEPTH); \
+         if (heap->mm_procfs.backtrace) \

Review comment:
       ```suggestion
            if ((heap)->mm_procfs.backtrace) \
   ```

##########
File path: mm/mm_heap/mm_malloc.c
##########
@@ -243,7 +244,13 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t 
size)
 #ifdef CONFIG_DEBUG_MM
   else
     {
+      struct mallinfo minfo;
+
       mwarn("WARNING: Allocation failed, size %zu\n", alignsize);
+      mm_mallinfo(heap, &minfo);
+      mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n",
+             minfo.arena, minfo.uordblks, minfo.fordblks,
+             minfo.mxordblk, minfo.aordblks, minfo.ordblks);

Review comment:
       ```suggestion
         mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n",
               minfo.arena, minfo.uordblks, minfo.fordblks,
               minfo.mxordblk, minfo.aordblks, minfo.ordblks);
   ```

##########
File path: fs/procfs/fs_procfsmeminfo.c
##########
@@ -459,6 +460,27 @@ static ssize_t memdump_write(FAR struct file *filep, FAR 
const char *buffer,
   procfile = filep->f_priv;
   DEBUGASSERT(procfile);
 
+#ifdef CONFIG_DEBUG_MM
+  if (strcmp(buffer, "on") == 0)
+    {
+      for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next)
+        {
+          entry->backtrace = true;
+        }
+
+      return buflen;
+    }
+  else if (strcmp(buffer, "off") == 0)
+    {
+      for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next)
+        {
+          entry->backtrace = false;
+        }
+
+      return buflen;
+    }
+#endif

Review comment:
       Maybe we can follow the logic below?
   ```
     switch (buffer[0])
       {
         case 'u':
           pid = (pid_t)-1;
           break;
   
         case 'f':
           pid = (pid_t)-2;
           break;
   #ifdef CONFIG_DEBUG_MM
         case 'o':
           for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next)
             {
               entry->backtrace = (buffer[1] == 'n');
             }
           break;
   
         default:
           pid = atoi(buffer);
   #endif
       }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to