]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add a command to clear the thread CPU history data
authorPaul Jakma <paul@quagga.net>
Sat, 9 Jan 2010 16:15:00 +0000 (16:15 +0000)
committerPaul Jakma <paul@quagga.net>
Wed, 8 Dec 2010 16:53:09 +0000 (16:53 +0000)
* (general) this can be useful when investigating thread latency problems,
  when you don't want to have to restart a daemon between tests.
* thread.c: (cpu_record_(hash_)clear) wipe the stored thread cpu history
  data, according to the filter, similar to the vty print code.
  (clear_thread_cpu_cmd) new command to clear data.
* thread.h: export new command
* command.c: install it

lib/command.c
lib/thread.c
lib/thread.h

index 478125f20a76e552f9071596862d9860461a8afb..5a13f39c38516375fe92c6d211d4f23da15f1d96 100644 (file)
@@ -3650,6 +3650,8 @@ cmd_init (int terminal)
       install_element (VIEW_NODE, &show_thread_cpu_cmd);
       install_element (ENABLE_NODE, &show_thread_cpu_cmd);
       install_element (RESTRICTED_NODE, &show_thread_cpu_cmd);
+      
+      install_element (ENABLE_NODE, &clear_thread_cpu_cmd);
       install_element (VIEW_NODE, &show_work_queues_cmd);
       install_element (ENABLE_NODE, &show_work_queues_cmd);
     }
index fb6fe375df9180eb896d0d8a3da993e3f7a313ab..fd841c2153998ef386a4e0c4ceb952fdcf1f69e4 100644 (file)
@@ -382,6 +382,89 @@ DEFUN(show_thread_cpu,
   cpu_record_print(vty, filter);
   return CMD_SUCCESS;
 }
+
+static void
+cpu_record_hash_clear (struct hash_backet *bucket, 
+                     void *args)
+{
+  thread_type *filter = args;
+  struct cpu_thread_history *a = bucket->data;
+  
+  a = bucket->data;
+  if ( !(a->types & *filter) )
+       return;
+  
+  hash_release (cpu_record, bucket->data);
+}
+
+static void
+cpu_record_clear (thread_type filter)
+{
+  thread_type *tmp = &filter;
+  hash_iterate (cpu_record,
+               (void (*) (struct hash_backet*,void*)) cpu_record_hash_clear,
+               tmp);
+}
+
+DEFUN(clear_thread_cpu,
+      clear_thread_cpu_cmd,
+      "clear thread cpu [FILTER]",
+      "Clear stored data\n"
+      "Thread information\n"
+      "Thread CPU usage\n"
+      "Display filter (rwtexb)\n")
+{
+  int i = 0;
+  thread_type filter = (thread_type) -1U;
+
+  if (argc > 0)
+    {
+      filter = 0;
+      while (argv[0][i] != '\0')
+       {
+         switch ( argv[0][i] )
+           {
+           case 'r':
+           case 'R':
+             filter |= (1 << THREAD_READ);
+             break;
+           case 'w':
+           case 'W':
+             filter |= (1 << THREAD_WRITE);
+             break;
+           case 't':
+           case 'T':
+             filter |= (1 << THREAD_TIMER);
+             break;
+           case 'e':
+           case 'E':
+             filter |= (1 << THREAD_EVENT);
+             break;
+           case 'x':
+           case 'X':
+             filter |= (1 << THREAD_EXECUTE);
+             break;
+           case 'b':
+           case 'B':
+             filter |= (1 << THREAD_BACKGROUND);
+             break;
+           default:
+             break;
+           }
+         ++i;
+       }
+      if (filter == 0)
+       {
+         vty_out(vty, "Invalid filter \"%s\" specified,"
+                  " must contain at least one of 'RWTEXB'%s",
+                 argv[0], VTY_NEWLINE);
+         return CMD_WARNING;
+       }
+    }
+
+  cpu_record_clear (filter);
+  return CMD_SUCCESS;
+}
 \f
 /* List allocation and head/tail print out. */
 static void
index 937bedbb30d340b013c7d96fe7f36c761d7b5a1b..978aa6b0ad4972908f1bdda89b758a5706fd1371 100644 (file)
@@ -197,6 +197,7 @@ extern int thread_should_yield (struct thread *);
 /* Internal libzebra exports */
 extern void thread_getrusage (RUSAGE_T *);
 extern struct cmd_element show_thread_cpu_cmd;
+extern struct cmd_element clear_thread_cpu_cmd;
 
 /* replacements for the system gettimeofday(), clock_gettime() and
  * time() functions, providing support for non-decrementing clock on