buffers: fix vlib_buffer_free_no_next
[vpp.git] / src / vlib / cli.c
index d7b2a46..6d83e2a 100644 (file)
@@ -552,6 +552,31 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
                                        parent_command_index);
       unformat_free (&sub_input);
     }
+  else if (unformat (input, "leak-check %U",
+                    unformat_vlib_cli_sub_input, &sub_input))
+    {
+      u8 *leak_report;
+      clib_mem_trace (1);
+      error =
+       vlib_cli_dispatch_sub_commands (vm, cm, &sub_input,
+                                       parent_command_index);
+      unformat_free (&sub_input);
+
+      /* Otherwise, the clib_error_t shows up as a leak... */
+      if (error)
+       {
+         vlib_cli_output (vm, "%v", error->what);
+         clib_error_free (error);
+         error = 0;
+       }
+
+      (void) clib_mem_trace_enable_disable (0);
+      leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (),
+                           1 /* verbose, i.e. print leaks */ );
+      clib_mem_trace (0);
+      vlib_cli_output (vm, "%v", leak_report);
+      vec_free (leak_report);
+    }
 
   else
     if (unformat_user (input, unformat_vlib_cli_sub_command, vm, parent, &c))
@@ -684,7 +709,7 @@ vlib_unix_error_report (vlib_main_t * vm, clib_error_t * error)
 }
 
 /* Process CLI input. */
-void
+int
 vlib_cli_input (vlib_main_t * vm,
                unformat_input_t * input,
                vlib_cli_output_function_t * function, uword function_arg)
@@ -694,6 +719,7 @@ vlib_cli_input (vlib_main_t * vm,
   clib_error_t *error;
   vlib_cli_output_function_t *save_function;
   uword save_function_arg;
+  int rv = 0;
 
   save_function = cp->output_function;
   save_function_arg = cp->output_function_arg;
@@ -713,11 +739,15 @@ vlib_cli_input (vlib_main_t * vm,
     {
       vlib_cli_output (vm, "%v", error->what);
       vlib_unix_error_report (vm, error);
+      /* clib_error_return is unfortunately often called with a '0'
+         return code */
+      rv = error->code != 0 ? error->code : -1;
       clib_error_free (error);
     }
 
   cp->output_function = save_function;
   cp->output_function_arg = save_function_arg;
+  return rv;
 }
 
 /* Output to current CLI connection. */
@@ -852,7 +882,7 @@ show_cpu (vlib_main_t * vm, unformat_input_t * input,
 {
 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
   _("Model name", "%U", format_cpu_model_name);
-  _("Microarchitecture", "%U", format_cpu_uarch);
+  _("Microarch model (family)", "%U", format_cpu_uarch);
   _("Flags", "%U", format_cpu_flags);
   _("Base frequency", "%.2f GHz",
     ((f64) vm->clib_time.clocks_per_second) * 1e-9);
@@ -1465,7 +1495,8 @@ elog_trace_command_fn (vlib_main_t * vm,
 {
   unformat_input_t _line_input, *line_input = &_line_input;
   int enable = 1;
-  int api = 0, cli = 0, barrier = 0;
+  int api = 0, cli = 0, barrier = 0, dispatch = 0, circuit = 0;
+  u32 circuit_node_index;
 
   if (!unformat_user (input, unformat_line_input, line_input))
     goto print_status;
@@ -1474,6 +1505,11 @@ elog_trace_command_fn (vlib_main_t * vm,
     {
       if (unformat (line_input, "api"))
        api = 1;
+      else if (unformat (line_input, "dispatch"))
+       dispatch = 1;
+      else if (unformat (line_input, "circuit-node %U",
+                        unformat_vlib_node, vm, &circuit_node_index))
+       circuit = 1;
       else if (unformat (line_input, "cli"))
        cli = 1;
       else if (unformat (line_input, "barrier"))
@@ -1489,8 +1525,28 @@ elog_trace_command_fn (vlib_main_t * vm,
 
   vm->elog_trace_api_messages = api ? enable : vm->elog_trace_api_messages;
   vm->elog_trace_cli_commands = cli ? enable : vm->elog_trace_cli_commands;
+  vm->elog_trace_graph_dispatch = dispatch ?
+    enable : vm->elog_trace_graph_dispatch;
+  vm->elog_trace_graph_circuit = circuit ?
+    enable : vm->elog_trace_graph_circuit;
   vlib_worker_threads->barrier_elog_enabled =
     barrier ? enable : vlib_worker_threads->barrier_elog_enabled;
+  vm->elog_trace_graph_circuit_node_index = circuit_node_index;
+
+  /*
+   * Set up start-of-buffer logic-analyzer trigger
+   * for main loop event logs, which are fairly heavyweight.
+   * See src/vlib/main/vlib_elog_main_loop_event(...), which
+   * will fully disable the scheme when the elog buffer fills.
+   */
+  if (dispatch || circuit)
+    {
+      elog_main_t *em = &vm->elog_main;
+
+      em->n_total_events_disable_limit =
+       em->n_total_events + vec_len (em->event_ring);
+    }
+
 
 print_status:
   vlib_cli_output (vm, "Current status:");
@@ -1502,6 +1558,16 @@ print_status:
   vlib_cli_output
     (vm, "    Barrier sync trace: %s",
      vlib_worker_threads->barrier_elog_enabled ? "on" : "off");
+  vlib_cli_output
+    (vm, "    Graph Dispatch: %s",
+     vm->elog_trace_graph_dispatch ? "on" : "off");
+  vlib_cli_output
+    (vm, "    Graph Circuit: %s",
+     vm->elog_trace_graph_circuit ? "on" : "off");
+  if (vm->elog_trace_graph_circuit)
+    vlib_cli_output
+      (vm, "                   node %U",
+       format_vlib_node_name, vm, vm->elog_trace_graph_circuit_node_index);
 
   return 0;
 }
@@ -1515,6 +1581,8 @@ print_status:
  * @clistart
  * elog trace api cli barrier
  * elog trace api cli barrier disable
+ * elog trace dispatch
+ * elog trace circuit-node ethernet-input
  * elog trace
  * @cliend
  * @cliexcmd{elog trace [api][cli][barrier][disable]}
@@ -1523,7 +1591,8 @@ print_status:
 VLIB_CLI_COMMAND (elog_trace_command, static) =
 {
   .path = "elog trace",
-  .short_help = "elog trace [api][cli][barrier][disable]",
+  .short_help = "elog trace [api][cli][barrier][dispatch]\n"
+  "[circuit-node <name> e.g. ethernet-input][disable]",
   .function = elog_trace_command_fn,
 };
 /* *INDENT-ON* */