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

[incubator-nuttx-apps] branch master updated: apps/trace: add switch and dump instrumentation

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 18b5902  apps/trace: add switch and dump instrumentation
18b5902 is described below

commit 18b5902a3e956fab2042e45b7e3a83fcc0678158
Author: zhanghu6 <zh...@xiaomi.com>
AuthorDate: Fri Feb 18 17:13:25 2022 +0800

    apps/trace: add switch and dump instrumentation
    
    usage:
        trace switch switch [+|-]
                                 Configure switch trace filter
    
        trace print [+|-]
                                 Configure dump trace filter
    
    Signed-off-by: zhanghu6 <zh...@xiaomi.com>
---
 system/trace/trace.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 143 insertions(+), 1 deletion(-)

diff --git a/system/trace/trace.c b/system/trace/trace.c
index 843cdb4..03796a9 100644
--- a/system/trace/trace.c
+++ b/system/trace/trace.c
@@ -325,6 +325,19 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
             break;
 #endif
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+          case 'w':   /* Switch trace */
+            if (enable)
+              {
+                mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH;
+              }
+            else
+              {
+                mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH;
+              }
+            break;
+#endif
+
 #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
           case 's':   /* Syscall trace */
             if (enable)
@@ -362,6 +375,19 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
             break;
 #endif
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
+          case 'd':   /* Dump trace */
+            if (enable)
+              {
+                mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP;
+              }
+            else
+              {
+                mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP;
+              }
+            break;
+#endif
+
           default:
             fprintf(stderr,
                     "trace mode: invalid option '%s'\n", argv[index]);
@@ -441,6 +467,54 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
 }
 
 /****************************************************************************
+ * Name: trace_cmd_switch
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+static int trace_cmd_switch(int index, int argc, FAR char **argv,
+                            int notectlfd)
+{
+  bool enable;
+  struct note_filter_mode_s mode;
+
+  /* Usage: trace switch [+|-] */
+
+  /* Get current filter setting */
+
+  ioctl(notectlfd, NOTECTL_GETMODE, (unsigned long)&mode);
+
+  /* Parse the setting parameters */
+
+  if (argv[index][0] == '-' || argv[index][0] == '+')
+    {
+      enable = (argv[index][0] == '+');
+      if (enable ==
+          ((mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) != 0))
+        {
+          /* Already set */
+
+          return false;
+        }
+
+      if (enable)
+        {
+          mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH;
+        }
+      else
+        {
+          mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH;
+        }
+
+      ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode);
+
+      index++;
+    }
+
+  return index;
+}
+#endif
+
+/****************************************************************************
  * Name: trace_cmd_syscall
  ****************************************************************************/
 
@@ -643,6 +717,54 @@ static int trace_cmd_irq(int index, int argc, FAR char **argv, int notectlfd)
 #endif
 
 /****************************************************************************
+ * Name: trace_cmd_print
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
+static int trace_cmd_print(int index, int argc, FAR char **argv,
+                           int notectlfd)
+{
+  bool enable;
+  struct note_filter_mode_s mode;
+
+  /* Usage: trace print [+|-] */
+
+  /* Get current filter setting */
+
+  ioctl(notectlfd, NOTECTL_GETMODE, (unsigned long)&mode);
+
+  /* Parse the setting parameters */
+
+  if (argv[index][0] == '-' || argv[index][0] == '+')
+    {
+      enable = (argv[index][0] == '+');
+      if (enable ==
+          ((mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) != 0))
+        {
+          /* Already set */
+
+          return false;
+        }
+
+      if (enable)
+        {
+          mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP;
+        }
+      else
+        {
+          mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP;
+        }
+
+      ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode);
+
+      index++;
+    }
+
+  return index;
+}
+#endif
+
+/****************************************************************************
  * Name: show_usage
  ****************************************************************************/
 
@@ -663,8 +785,12 @@ static void show_usage(void)
           "  dump [-c][<filename>]           :"
                                 " Output the trace result\n"
 #endif
-          "  mode [{+|-}{o|s|a|i}...]        :"
+          "  mode [{+|-}{o|w|s|a|i|d}...]        :"
                                 " Set task trace options\n"
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+          "  switch [+|-] :"
+                                " Configure switch trace filter\n"
+#endif
 #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
           "  syscall [{+|-}<syscallname>...] :"
                                 " Configure syscall trace filter\n"
@@ -673,6 +799,10 @@ static void show_usage(void)
           "  irq [{+|-}<irqnum>...]          :"
                                 " Configure IRQ trace filter\n"
 #endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
+          "  print [+|-] :"
+                                " Configure dump trace filter\n"
+#endif
          );
 }
 
@@ -734,6 +864,12 @@ int main(int argc, FAR char *argv[])
         {
           i = trace_cmd_mode(i + 1, argc, argv, notectlfd);
         }
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+      else if (strcmp(argv[i], "switch") == 0)
+        {
+          i = trace_cmd_switch(i + 1, argc, argv, notectlfd);
+        }
+#endif
 #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
       else if (strcmp(argv[i], "syscall") == 0)
         {
@@ -746,6 +882,12 @@ int main(int argc, FAR char *argv[])
           i = trace_cmd_irq(i + 1, argc, argv, notectlfd);
         }
 #endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
+      else if (strcmp(argv[i], "print") == 0)
+        {
+          i = trace_cmd_print(i + 1, argc, argv, notectlfd);
+        }
+#endif
       else
         {
           show_usage();