summaryrefslogtreecommitdiffstats
path: root/src/vat/api_format.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-07-15 16:00:03 -0400
committerDamjan Marion <dmarion@me.com>2019-07-16 13:12:12 +0000
commitb09f4d0adb8364b3516c3a64e8238715887ffec8 (patch)
tree95f9f29d3d5a9c17fcff3cd670623cc16ff2806b /src/vat/api_format.c
parent7b8a30d08bffcb8c6fe7faa8d7f7dc557e175770 (diff)
api: enable binary API event logging in vat
Cleaned up a few instances of side-bet elog_string hash table usage. Elog_string handles that problem itself. Add cli commands to vat to initialize, enable/disable, and save an event log. Event logging at the same time in both vpp and vat yields a pair of event logs which can be merged by the "test_elog" tool. Type: refactor Change-Id: I8d6a72206f2309c967ea1630077fba31aef47f93 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vat/api_format.c')
-rw-r--r--src/vat/api_format.c102
1 files changed, 101 insertions, 1 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 5bba7efea46..a8d4a0db09d 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -85,6 +85,9 @@
#define __plugin_msg_base 0
#include <vlibapi/vat_helper_macros.h>
+void vl_api_set_elog_main (elog_main_t * m);
+int vl_api_set_elog_trace_api_messages (int enable);
+
#if VPP_API_TEST_BUILTIN == 0
#include <netdb.h>
@@ -164,7 +167,8 @@ errmsg (char *fmt, ...)
if (vam->ifp != stdin)
fformat (vam->ofp, "%s(%d): \n", vam->current_file,
vam->input_line_number);
- fformat (vam->ofp, (char *) s);
+ else
+ fformat (vam->ofp, "%s\n", (char *) s);
fflush (vam->ofp);
}
#endif
@@ -21403,6 +21407,98 @@ comment (vat_main_t * vam)
}
static int
+elog_save (vat_main_t * vam)
+{
+#if VPP_API_TEST_BUILTIN == 0
+ elog_main_t *em = &vam->elog_main;
+ unformat_input_t *i = vam->input;
+ char *file, *chroot_file;
+ clib_error_t *error;
+
+ if (!unformat (i, "%s", &file))
+ {
+ errmsg ("expected file name, got `%U'", format_unformat_error, i);
+ return 0;
+ }
+
+ /* It's fairly hard to get "../oopsie" through unformat; just in case */
+ if (strstr (file, "..") || index (file, '/'))
+ {
+ errmsg ("illegal characters in filename '%s'", file);
+ return 0;
+ }
+
+ chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
+
+ vec_free (file);
+
+ errmsg ("Saving %wd of %wd events to %s",
+ elog_n_events_in_buffer (em),
+ elog_buffer_capacity (em), chroot_file);
+
+ error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
+ vec_free (chroot_file);
+
+ if (error)
+ clib_error_report (error);
+#else
+ errmsg ("Use the vpp event loger...");
+#endif
+
+ return 0;
+}
+
+static int
+elog_setup (vat_main_t * vam)
+{
+#if VPP_API_TEST_BUILTIN == 0
+ elog_main_t *em = &vam->elog_main;
+ unformat_input_t *i = vam->input;
+ u32 nevents = 128 << 10;
+
+ (void) unformat (i, "nevents %d", &nevents);
+
+ elog_init (em, nevents);
+ vl_api_set_elog_main (em);
+ vl_api_set_elog_trace_api_messages (1);
+ errmsg ("Event logger initialized with %u events", nevents);
+#else
+ errmsg ("Use the vpp event loger...");
+#endif
+ return 0;
+}
+
+static int
+elog_enable (vat_main_t * vam)
+{
+#if VPP_API_TEST_BUILTIN == 0
+ elog_main_t *em = &vam->elog_main;
+
+ elog_enable_disable (em, 1 /* enable */ );
+ vl_api_set_elog_trace_api_messages (1);
+ errmsg ("Event logger enabled...");
+#else
+ errmsg ("Use the vpp event loger...");
+#endif
+ return 0;
+}
+
+static int
+elog_disable (vat_main_t * vam)
+{
+#if VPP_API_TEST_BUILTIN == 0
+ elog_main_t *em = &vam->elog_main;
+
+ elog_enable_disable (em, 0 /* enable */ );
+ vl_api_set_elog_trace_api_messages (1);
+ errmsg ("Event logger disabled...");
+#else
+ errmsg ("Use the vpp event loger...");
+#endif
+ return 0;
+}
+
+static int
statseg (vat_main_t * vam)
{
ssvm_private_t *ssvmp = &vam->stat_segment;
@@ -22286,6 +22382,10 @@ _(dump_ipv6_table, "usage: dump_ipv6_table") \
_(dump_macro_table, "usage: dump_macro_table ") \
_(dump_node_table, "usage: dump_node_table") \
_(dump_msg_api_table, "usage: dump_msg_api_table") \
+_(elog_setup, "usage: elog_setup [nevents, default 128K]") \
+_(elog_disable, "usage: elog_disable") \
+_(elog_enable, "usage: elog_enable") \
+_(elog_save, "usage: elog_save <filename>") \
_(get_msg_id, "usage: get_msg_id name_and_crc") \
_(echo, "usage: echo <message>") \
_(exec, "usage: exec <vpe-debug-CLI-command>") \