You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/02/23 18:19:18 UTC

[incubator-nuttx-apps] branch master updated (67c05f1 -> 283b1a4)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.


    from 67c05f1  mlearning: cmsis: libcmsisdsp: simplify config naming
     new 372621e  nshlib/ps: support display heap info for every task by cmd ps
     new 283b1a4  nshlib/cmd_memdump: support new command: memdump

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nshlib/Kconfig        |  6 +++++
 nshlib/nsh.h          | 33 +++++++++++++++++++++++
 nshlib/nsh_command.c  |  6 +++++
 nshlib/nsh_fsutils.c  | 59 ++++++++++++++++++++++++++++++++++++++++
 nshlib/nsh_mmcmds.c   | 25 +++++++++++++++--
 nshlib/nsh_proccmds.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 202 insertions(+), 2 deletions(-)

[incubator-nuttx-apps] 02/02: nshlib/cmd_memdump: support new command: memdump

Posted by xi...@apache.org.
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/incubator-nuttx-apps.git

commit 283b1a4dfccc4723728ea613dc42e58ddc10fed2
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jan 20 21:12:14 2022 +0800

    nshlib/cmd_memdump: support new command: memdump
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 nshlib/nsh.h         | 33 +++++++++++++++++++++++++++++
 nshlib/nsh_command.c |  6 ++++++
 nshlib/nsh_fsutils.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 nshlib/nsh_mmcmds.c  | 25 ++++++++++++++++++++--
 4 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 16234af..5efdc89 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -565,9 +565,15 @@
 #  define CONFIG_NSH_DISABLE_FREE 1
 #endif
 
+#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_MEMDUMP)
+#  undef  CONFIG_NSH_DISABLE_MEMDUMP
+#  define CONFIG_NSH_DISABLE_MEMDUMP 1
+#endif
+
 /* Suppress unused file utilities */
 
 #define NSH_HAVE_CATFILE          1
+#define NSH_HAVE_WRITEFILE        1
 #define NSH_HAVE_READFILE         1
 #define NSH_HAVE_FOREACH_DIRENTRY 1
 #define NSH_HAVE_TRIMDIR          1
@@ -940,6 +946,9 @@ void nsh_usbtrace(void);
 #ifndef CONFIG_NSH_DISABLE_FREE
   int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
 #endif
+#ifndef CONFIG_NSH_DISABLE_MEMDUMP
+  int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+#endif
 #ifndef CONFIG_NSH_DISABLE_TIME
   int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
 #endif
@@ -1295,6 +1304,30 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 #endif
 
 /****************************************************************************
+ * Name: nsh_writefile
+ *
+ * Description:
+ *   Dump the contents of a file to the current NSH terminal.
+ *
+ * Input Paratemets:
+ *   vtbl     - session vtbl
+ *   cmd      - NSH command name to use in error reporting
+ *   buffer   - The pointer of writting buffer
+ *   len      - The length of writting buffer
+ *   filepath - The full path to the file to be dumped
+ *
+ * Returned Value:
+ *   Zero (OK) on success; -1 (ERROR) on failure.
+ *
+ ****************************************************************************/
+
+#ifdef NSH_HAVE_WRITEFILE
+int nsh_writefile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
+                  FAR const char *buffer, size_t len,
+                  FAR const char *filepath);
+#endif
+
+/****************************************************************************
  * Name: nsh_foreach_direntry
  *
  * Description:
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index ddee35f..e5e2fed 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -216,6 +216,12 @@ static const struct cmdmap_s g_cmdmap[] =
   { "free",     cmd_free,     1, 1, NULL },
 #endif
 
+#ifdef CONFIG_DEBUG_MM
+# ifndef CONFIG_NSH_DISABLE_MEMDUMP
+  { "memdump",  cmd_memdump,  1, 3, "[pid/used/free]" },
+# endif
+#endif
+
 #ifdef CONFIG_NET_UDP
 # ifndef CONFIG_NSH_DISABLE_GET
   { "get",      cmd_get,      4, 7,
diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c
index 98fc334..65dc811 100644
--- a/nshlib/nsh_fsutils.c
+++ b/nshlib/nsh_fsutils.c
@@ -287,6 +287,65 @@ int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 #endif
 
 /****************************************************************************
+ * Name: nsh_writefile
+ *
+ * Description:
+ *   Dump the contents of a file to the current NSH terminal.
+ *
+ * Input Paratemets:
+ *   vtbl     - session vtbl
+ *   cmd      - NSH command name to use in error reporting
+ *   buffer   - The pointer of writting buffer
+ *   len      - The length of writting buffer
+ *   filepath - The full path to the file to be dumped
+ *
+ * Returned Value:
+ *   Zero (OK) on success; -1 (ERROR) on failure.
+ *
+ ****************************************************************************/
+
+#ifdef NSH_HAVE_WRITEFILE
+int nsh_writefile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
+                  FAR const char *buffer, size_t len,
+                  FAR const char *filepath)
+{
+  int fd;
+  int ret;
+
+  /* Open the file for reading */
+
+  fd = open(filepath, O_WRONLY);
+  if (fd < 0)
+    {
+#if defined(CONFIG_NSH_PROC_MOUNTPOINT)
+      if (strncmp(filepath, CONFIG_NSH_PROC_MOUNTPOINT,
+                  strlen(CONFIG_NSH_PROC_MOUNTPOINT)) == 0)
+        {
+          nsh_error(vtbl,
+                    "nsh: %s: Could not open %s (is procfs mounted?): %d\n",
+                    cmd, filepath, NSH_ERRNO);
+        }
+      else
+#endif
+        {
+          nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
+        }
+
+      return ERROR;
+    }
+
+  ret = write(fd, buffer, len);
+  if (ret < 0)
+    {
+      nsh_error(vtbl, g_fmtcmdfailed, cmd, "write", NSH_ERRNO);
+    }
+
+  close(fd);
+  return ret > 0 ? OK : ERROR;
+}
+#endif
+
+/****************************************************************************
  * Name: nsh_foreach_direntry
  *
  * Description:
diff --git a/nshlib/nsh_mmcmds.c b/nshlib/nsh_mmcmds.c
index 898e127..2d8a1ac 100644
--- a/nshlib/nsh_mmcmds.c
+++ b/nshlib/nsh_mmcmds.c
@@ -27,12 +27,12 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
-#if !defined(CONFIG_NSH_DISABLE_FREE) && defined(NSH_HAVE_CATFILE)
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+#if !defined(CONFIG_NSH_DISABLE_FREE) && defined(NSH_HAVE_CATFILE)
+
 /****************************************************************************
  * Name: cmd_free
  ****************************************************************************/
@@ -43,3 +43,24 @@ int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
 }
 
 #endif /* !CONFIG_NSH_DISABLE_FREE && NSH_HAVE_CATFILE */
+
+#if !defined(CONFIG_NSH_DISABLE_MEMDUMP) && defined(NSH_HAVE_WRITEFILE)
+
+/****************************************************************************
+ * Name: cmd_memdump
+ ****************************************************************************/
+
+int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+  FAR const char *arg = "used";
+
+  if (argc > 1)
+    {
+      arg = argv[1];
+    }
+
+  return nsh_writefile(vtbl, argv[0], arg, strlen(arg),
+                       CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
+}
+
+#endif /* !CONFIG_NSH_DISABLE_MEMDUMP && NSH_HAVE_WRITEFILE */

[incubator-nuttx-apps] 01/02: nshlib/ps: support display heap info for every task by cmd ps

Posted by xi...@apache.org.
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/incubator-nuttx-apps.git

commit 372621ed065ddb23a86d215df8af65e0e0f271e7
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Sat Jan 22 20:24:32 2022 +0800

    nshlib/ps: support display heap info for every task by cmd ps
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 nshlib/Kconfig        |  6 +++++
 nshlib/nsh_proccmds.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index fbdb78a..bf4cb6e 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -475,6 +475,12 @@ config NSH_DISABLE_PS
 	default y if DEFAULT_SMALL || !FS_PROCFS || FS_PROCFS_EXCLUDE_PROCESS
 	default n if !DEFAULT_SMALL && FS_PROCFS && !FS_PROCFS_EXCLUDE_PROCESS
 
+config NSH_DISABLE_PSHEAPUSAGE
+	bool "Disable ps heap usage"
+	depends on DEBUG_MM && !NSH_DISABLE_PS
+	default y if DEFAULT_SMALL
+	default n if !DEFAULT_SMALL
+
 config NSH_DISABLE_PSSTACKUSAGE
 	bool "Disable ps stack usage"
 	depends on STACK_COLORATION && !NSH_DISABLE_PS
diff --git a/nshlib/nsh_proccmds.c b/nshlib/nsh_proccmds.c
index 003d591..195bb4b 100644
--- a/nshlib/nsh_proccmds.c
+++ b/nshlib/nsh_proccmds.c
@@ -92,6 +92,10 @@ static const char g_priority[]  = "Priority:";
 static const char g_scheduler[] = "Scheduler:";
 static const char g_sigmask[]   = "SigMask:";
 
+#if defined(CONFIG_DEBUG_MM) && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE)
+static const char g_heapsize[]  = "AllocSize:";
+#endif /* CONFIG_DEBUG _MM && !CONFIG_NSH_DISABLE_PSHEAPUSAGE */
+
 #if !defined(CONFIG_NSH_DISABLE_PSSTACKUSAGE)
 static const char g_stacksize[] = "StackSize:";
 #ifdef CONFIG_STACK_COLORATION
@@ -228,6 +232,9 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
   FAR char *nextline;
   int ret;
   int i;
+#if defined(CONFIG_DEBUG_MM) && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE)
+  uint32_t heap_size;
+#endif
 #if !defined(CONFIG_NSH_DISABLE_PSSTACKUSAGE)
   uint32_t stack_size;
 #ifdef CONFIG_STACK_COLORATION
@@ -333,6 +340,70 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
              status.td_flags, status.td_state, status.td_event);
   nsh_output(vtbl, "%-8s ", status.td_sigmask);
 
+#if defined(CONFIG_DEBUG_MM) && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE)
+  /* Get the Heap AllocSize */
+
+  heap_size = 0;
+  filepath  = NULL;
+
+  ret = asprintf(&filepath, "%s/%s/heap", dirpath, entryp->d_name);
+  if (ret < 0 || filepath == NULL)
+    {
+      nsh_error(vtbl, g_fmtcmdfailed, "ps", "asprintf", NSH_ERRNO);
+      vtbl->iobuffer[0] = '\0';
+    }
+  else
+    {
+      ret = nsh_readfile(vtbl, "ps", filepath, vtbl->iobuffer,
+                         IOBUFFERSIZE);
+      free(filepath);
+
+      if (ret >= 0)
+        {
+          nextline = vtbl->iobuffer;
+          do
+            {
+              /* Find the beginning of the next line and NUL-terminate the
+               * current line.
+               */
+
+              line = nextline;
+              for (nextline++;
+                  *nextline != '\n' && *nextline != '\0';
+                  nextline++);
+
+              if (*nextline == '\n')
+                {
+                  *nextline++ = '\0';
+                }
+              else
+                {
+                  nextline = NULL;
+                }
+
+              /* Parse the current line
+               *
+               *   Format:
+               *
+               *            111111111122222222223
+               *   123456789012345678901234567890
+               *   AllocSize:  xxxx
+               *   AllocBlks:  xxxx
+               */
+
+              if (strncmp(line, g_heapsize, strlen(g_heapsize)) == 0)
+                {
+                  heap_size = (uint32_t)atoi(&line[12]);
+                  break;
+                }
+            }
+          while (nextline != NULL);
+        }
+    }
+
+  nsh_output(vtbl, "%08u ", (unsigned int)heap_size);
+#endif
+
 #if !defined(CONFIG_NSH_DISABLE_PSSTACKUSAGE)
   /* Get the StackSize and StackUsed */
 
@@ -516,6 +587,10 @@ int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
              "PRI", "POLICY", "TYPE", "NPX", "STATE", "EVENT");
   nsh_output(vtbl, "%-8s ", "SIGMASK");
 
+#if defined(CONFIG_DEBUG_MM) && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE)
+  nsh_output(vtbl, "%8s ", "HEAP");
+#endif
+
 #if !defined(CONFIG_NSH_DISABLE_PSSTACKUSAGE)
   nsh_output(vtbl, "%6s ", "STACK");
 #ifdef CONFIG_STACK_COLORATION