session: add session stats
[vpp.git] / src / vnet / session / session_cli.c
index da2df33..ba2cba0 100644 (file)
@@ -841,7 +841,6 @@ session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input,
                           vlib_cli_command_t * cmd)
 {
   u8 is_en = 2;
-  clib_error_t *error;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -850,12 +849,8 @@ session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input,
       else if (unformat (input, "disable"))
        is_en = 0;
       else
-       {
-         error = clib_error_return (0, "unknown input `%U'",
-                                    format_unformat_error, input);
-         unformat_free (input);
-         return error;
-       }
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
     }
 
   if (is_en > 1)
@@ -873,6 +868,62 @@ VLIB_CLI_COMMAND (session_enable_disable_command, static) =
 };
 /* *INDENT-ON* */
 
+static clib_error_t *
+show_session_stats_fn (vlib_main_t *vm, unformat_input_t *input,
+                      vlib_cli_command_t *cmd)
+{
+  session_main_t *smm = &session_main;
+  session_worker_t *wrk;
+  unsigned int *e;
+
+  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    return clib_error_return (0, "unknown input `%U'", format_unformat_error,
+                             input);
+
+  vec_foreach (wrk, smm->wrk)
+    {
+      vlib_cli_output (vm, "Thread %u:\n", wrk - smm->wrk);
+      e = wrk->stats.errors;
+#define _(name, str)                                                          \
+  if (e[SESSION_EP_##name])                                                   \
+    vlib_cli_output (vm, " %lu %s", e[SESSION_EP_##name], str);
+      foreach_session_error
+#undef _
+    }
+  return 0;
+}
+
+VLIB_CLI_COMMAND (show_session_stats_command, static) = {
+  .path = "show session stats",
+  .short_help = "show session stats",
+  .function = show_session_stats_fn,
+};
+
+static clib_error_t *
+clear_session_stats_fn (vlib_main_t *vm, unformat_input_t *input,
+                       vlib_cli_command_t *cmd)
+{
+  session_main_t *smm = &session_main;
+  session_worker_t *wrk;
+
+  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    return clib_error_return (0, "unknown input `%U'", format_unformat_error,
+                             input);
+
+  vec_foreach (wrk, smm->wrk)
+    {
+      clib_memset (&wrk->stats, 0, sizeof (wrk->stats));
+    }
+
+  return 0;
+}
+
+VLIB_CLI_COMMAND (clear_session_stats_command, static) = {
+  .path = "clear session stats",
+  .short_help = "clear session stats",
+  .function = clear_session_stats_fn,
+};
+
 /*
  * fd.io coding-style-patch-verification: ON
  *