VPP-26 Iterate through empty command line in cli history
[vpp.git] / vlib / vlib / main.c
index f541ed3..18273bf 100644 (file)
@@ -46,9 +46,6 @@
 
 CJ_GLOBAL_LOG_PROTOTYPE;
 
-
-//#define VLIB_ELOG_MAIN_LOOP 1
-
 /* Actually allocate a few extra slots of vector data to support
    speculative vector enqueues which overflow vector data in next frame. */
 #define VLIB_FRAME_SIZE_ALLOC (VLIB_FRAME_SIZE + 4)
@@ -135,7 +132,7 @@ vlib_frame_alloc_to_node (vlib_main_t * vm, u32 to_node_index, u32 frame_flags)
     }
   else
     {
-      f = clib_mem_alloc_aligned_no_fail (n, CLIB_CACHE_LINE_BYTES);
+      f = clib_mem_alloc_aligned_no_fail (n, VLIB_FRAME_ALIGN);
       f->cpu_index = vm->cpu_index;
       fi = vlib_frame_index_no_check (vm, f);
     }
@@ -668,8 +665,8 @@ vlib_cli_elog_clear (vlib_main_t * vm,
 }
 
 VLIB_CLI_COMMAND (elog_clear_cli, static) = {
-  .path = "clear event-logger",
-  .short_help = "Clear current event log",
+  .path = "event-logger clear",
+  .short_help = "Clear the event log",
   .function = vlib_cli_elog_clear,
 };
 
@@ -714,11 +711,78 @@ elog_save_buffer (vlib_main_t * vm,
 }
 
 VLIB_CLI_COMMAND (elog_save_cli, static) = {
-  .path = "save event-logger",
-  .short_help = "save event-logger <filename> (saves log in /tmp/<filename>)",
+  .path = "event-logger save",
+  .short_help = "event-logger save <filename> (saves log in /tmp/<filename>)",
   .function = elog_save_buffer,
 };
 
+static clib_error_t *
+elog_stop (vlib_main_t * vm,
+           unformat_input_t * input,
+           vlib_cli_command_t * cmd)
+{
+  elog_main_t * em = &vm->elog_main;
+
+  em->n_total_events_disable_limit = em->n_total_events;
+
+  vlib_cli_output (vm, "Stopped the event logger...");
+  return 0;
+}
+
+VLIB_CLI_COMMAND (elog_stop_cli, static) = {
+  .path = "event-logger stop",
+  .short_help = "Stop the event-logger",
+  .function = elog_stop,
+};
+
+static clib_error_t *
+elog_restart (vlib_main_t * vm,
+            unformat_input_t * input,
+            vlib_cli_command_t * cmd)
+{
+  elog_main_t * em = &vm->elog_main;
+
+  em->n_total_events_disable_limit = ~0;
+
+  vlib_cli_output (vm, "Restarted the event logger...");
+  return 0;
+}
+
+VLIB_CLI_COMMAND (elog_restart_cli, static) = {
+  .path = "event-logger restart",
+  .short_help = "Restart the event-logger",
+  .function = elog_restart,
+};
+
+static clib_error_t *
+elog_resize (vlib_main_t * vm,
+             unformat_input_t * input,
+             vlib_cli_command_t * cmd)
+{
+  elog_main_t * em = &vm->elog_main;
+  u32 tmp;
+
+  /* Stop the parade */
+  elog_reset_buffer (&vm->elog_main);
+
+  if (unformat (input, "%d", &tmp))
+    {
+      elog_alloc (em, tmp);
+      em->n_total_events_disable_limit = ~0;
+    }
+  else 
+    return clib_error_return (0, "Must specify how many events in the ring");
+
+  vlib_cli_output (vm, "Resized ring and restarted the event logger...");
+  return 0;
+}
+
+VLIB_CLI_COMMAND (elog_resize_cli, static) = {
+  .path = "event-logger resize",
+  .short_help = "event-logger resize <nnn>",
+  .function = elog_resize,
+};
+
 #endif /* CLIB_UNIX */
 
 static void elog_show_buffer_internal (vlib_main_t * vm, u32 n_events_to_show)
@@ -732,7 +796,10 @@ static void elog_show_buffer_internal (vlib_main_t * vm, u32 n_events_to_show)
     * vm->clib_time.seconds_per_clock;
 
   es = elog_peek_events (em);
-  vlib_cli_output (vm, "%d events in buffer", vec_len (es));
+  vlib_cli_output (vm, "%d of %d events in buffer, logger %s", vec_len (es), 
+                   em->event_ring_size,
+                   em->n_total_events < em->n_total_events_disable_limit ?
+                   "running" : "stopped");
   vec_foreach (e, es)
     {
       vlib_cli_output (vm, "%18.9f: %U",
@@ -779,22 +846,26 @@ void vlib_gdb_show_event_log (void)
   elog_show_buffer_internal (vlib_get_main(), (u32)~0);
 }
 
-always_inline void
+static inline void
 vlib_elog_main_loop_event (vlib_main_t * vm,
                           u32 node_index,
                           u64 time,
                           u32 n_vectors,
                           u32 is_return)
 {
-  elog_main_t * em = &vm->elog_main;
+  vlib_main_t * evm = &vlib_global_main;
+  elog_main_t * em = &evm->elog_main;
 
-  if (VLIB_ELOG_MAIN_LOOP)
-    elog (em,
+  if (VLIB_ELOG_MAIN_LOOP && n_vectors)
+    elog_track (em,
          /* event type */
          vec_elt_at_index (is_return
-                           ? vm->node_return_elog_event_types
-                           : vm->node_call_elog_event_types,
+                           ? evm->node_return_elog_event_types
+                           : evm->node_call_elog_event_types,
                            node_index),
+          /* track */
+          (vm->cpu_index ? &vlib_worker_threads[vm->cpu_index].elog_track :
+           &em->default_track),
          /* data to log */ n_vectors);
 }
 
@@ -1392,10 +1463,10 @@ static void vlib_main_loop (vlib_main_t * vm)
                  void * data;
                  data = vlib_process_signal_event_helper (nm, n, p, te->event_type_index, te->n_data_elts, te->n_data_elt_bytes);
                  if (te->n_data_bytes < sizeof (te->inline_event_data))
-                   memcpy (data, te->inline_event_data, te->n_data_bytes);
+                   clib_memcpy (data, te->inline_event_data, te->n_data_bytes);
                  else
                    {
-                     memcpy (data, te->event_data_as_vector, te->n_data_bytes);
+                     clib_memcpy (data, te->event_data_as_vector, te->n_data_bytes);
                      vec_free (te->event_data_as_vector);
                    }
                  pool_put (nm->signal_timed_event_data_pool, te);