diff options
author | Dave Barach <dave@barachs.net> | 2016-03-28 17:12:19 -0400 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2016-03-28 17:12:36 -0400 |
commit | e5389bb05330a9bd2f24478f996adbcce532ded5 (patch) | |
tree | 09243972dbf1e63c3fa746a1fb86221759da719e | |
parent | fb6e59d839001b37bbb70e253627d5b1331ae918 (diff) |
event logger skeletons, improve debug CLI
Change-Id: Ieb2e4043fc7bc3b4a5436a7a6aa35f573d8d4506
Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r-- | build-root/emacs-lisp/all-skel.el | 4 | ||||
-rw-r--r-- | build-root/emacs-lisp/elog-4-int-skel.el | 31 | ||||
-rw-r--r-- | build-root/emacs-lisp/elog-4-int-track-skel.el | 34 | ||||
-rw-r--r-- | build-root/emacs-lisp/elog-enum-skel.el | 35 | ||||
-rw-r--r-- | build-root/emacs-lisp/elog-one-datum-skel.el | 28 | ||||
-rw-r--r-- | vlib/vlib/elog_samples.c | 108 | ||||
-rw-r--r-- | vlib/vlib/main.c | 80 | ||||
-rw-r--r-- | vppinfra/vppinfra/elog.c | 2 | ||||
-rw-r--r-- | vppinfra/vppinfra/elog.h | 1 |
9 files changed, 317 insertions, 6 deletions
diff --git a/build-root/emacs-lisp/all-skel.el b/build-root/emacs-lisp/all-skel.el index fc961998070..2bf15b240f1 100644 --- a/build-root/emacs-lisp/all-skel.el +++ b/build-root/emacs-lisp/all-skel.el @@ -35,3 +35,7 @@ (load-file "./tunnel-decap-skel.el") (load-file "./tunnel-encap-skel.el") (load-file "./tunnel-h-skel.el") +(load-file "./elog-4-int-skel.el") +(load-file "./elog-4-int-track-skel.el") +(load-file "./elog-enum-skel.el") +(load-file "./elog-one-datum-skel.el") diff --git a/build-root/emacs-lisp/elog-4-int-skel.el b/build-root/emacs-lisp/elog-4-int-skel.el new file mode 100644 index 00000000000..fda412a7bb8 --- /dev/null +++ b/build-root/emacs-lisp/elog-4-int-skel.el @@ -0,0 +1,31 @@ +;;; elog-4-int-skel.el - 4 integer elog skeleton + +(require 'skeleton) + +(define-skeleton skel-elog-4-int +"Insert a skeleton 4-integer event definition" +nil +'(setq function-name (skeleton-read "Function: ")) +'(setq label (skeleton-read "Label: ")) + +" + +/* $$$ May or may not be needed */ +#include <vlib/vlib.h> +#include <vppinfra/elog.h> + +static inline void " function-name " (u32 *data) +{ + ELOG_TYPE_DECLARE(e) = + { + .format = \"" label ": first %d second %d third %d fourth %d\", + .format_args = \"i4i4i4i4\", + }; + struct { u32 data[4];} * ed; + ed = ELOG_DATA (&vlib_global_main.elog_main, e); + ed->data[0] = data[0]; + ed->data[1] = data[1]; + ed->data[2] = data[2]; + ed->data[3] = data[3]; +} +") diff --git a/build-root/emacs-lisp/elog-4-int-track-skel.el b/build-root/emacs-lisp/elog-4-int-track-skel.el new file mode 100644 index 00000000000..506cc3a2aa9 --- /dev/null +++ b/build-root/emacs-lisp/elog-4-int-track-skel.el @@ -0,0 +1,34 @@ +;;; elog-4-int-skel.el - 4 integer elog skeleton + +(require 'skeleton) + +(define-skeleton skel-elog-4-int-track +"Insert a skeleton 4-integer-with-track event definition" +nil +'(setq function-name (skeleton-read "Function: ")) +'(setq track-label (skeleton-read "Track Label: ")) +'(setq label (skeleton-read "Label: ")) + +" + +/* $$$ May or may not be needed */ +#include <vlib/vlib.h> +#include <vppinfra/elog.h> + +static inline void " function-name " (u32 *data) +{ + ELOG_TYPE_DECLARE(e) = + { + .format = \"" label ": first %d second %d third %d fourth %d\", + .format_args = \"i4i4i4i4\", + }; + struct { u32 data[4];} * ed; + ELOG_TRACK(" track-label "); + ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, " track-label "); + ed->data[0] = data[0]; + ed->data[1] = data[1]; + ed->data[2] = data[2]; + ed->data[3] = data[3]; +} + +") diff --git a/build-root/emacs-lisp/elog-enum-skel.el b/build-root/emacs-lisp/elog-enum-skel.el new file mode 100644 index 00000000000..836ce86a9d9 --- /dev/null +++ b/build-root/emacs-lisp/elog-enum-skel.el @@ -0,0 +1,35 @@ +;;; elog-enum-skel.el - enum elog skeleton + +(require 'skeleton) + +(define-skeleton skel-elog-enum +"Insert a skeleton enum event definition" +nil +'(setq function-name (skeleton-read "Function: ")) +'(setq label (skeleton-read "Label: ")) + +" + +/* $$$ May or may not be needed */ +#include <vlib/vlib.h> +#include <vppinfra/elog.h> + +static inline void " function-name " (u8 which) +{ + ELOG_TYPE_DECLARE (e) = + { + .format = \"" label ": %s\", + .format_args = \"t1\", + .n_enum_strings = 2, + .enum_strings = + { + \"string 1\", + \"string 2\", + }, + }; + struct { u8 which;} * ed; + ed = ELOG_DATA (&vlib_global_main.elog_main, e); + ed->which = which; +} + +") diff --git a/build-root/emacs-lisp/elog-one-datum-skel.el b/build-root/emacs-lisp/elog-one-datum-skel.el new file mode 100644 index 00000000000..11f8389619a --- /dev/null +++ b/build-root/emacs-lisp/elog-one-datum-skel.el @@ -0,0 +1,28 @@ +;;; elog-one-datum-skel.el - single u32 datum elog skeleton + +(require 'skeleton) + +(define-skeleton skel-elog-one-datum +"Insert a skeleton single datum event definition" +nil +'(setq function-name (skeleton-read "Function: ")) +'(setq label (skeleton-read "Label: ")) + +" + +/* $$$ May or may not be needed */ +#include <vlib/vlib.h> +#include <vppinfra/elog.h> + +static inline void " function-name " (u32 data) +{ + ELOG_TYPE_DECLARE (e) = + { + .format = \"" label ": %d\", + .format_args = \"i4\", + }; + + elog (&vlib_global_main.elog_main, &e, data); +} + +") diff --git a/vlib/vlib/elog_samples.c b/vlib/vlib/elog_samples.c new file mode 100644 index 00000000000..0a5cd202252 --- /dev/null +++ b/vlib/vlib/elog_samples.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <vlib/vlib.h> +#include <vppinfra/elog.h> + +static inline void elog_four_int_sample (u32 *data) +{ + ELOG_TYPE_DECLARE(e) = + { + .format = "four int: first %d second %d third %d fourth %d", + .format_args = "i4i4i4i4", + }; + struct { u32 data[4];} * ed; + ed = ELOG_DATA (&vlib_global_main.elog_main, e); + ed->data[0] = data[0]; + ed->data[1] = data[1]; + ed->data[2] = data[2]; + ed->data[3] = data[3]; +} + +static inline void elog_four_int_track_sample (u32 *data) +{ + ELOG_TYPE_DECLARE(e) = + { + .format = "four_int_track: first %d second %d third %d fourth %d", + .format_args = "i4i4i4i4", + }; + struct { u32 data[4];} * ed; + ELOG_TRACK(sample_track); + ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, sample_track); + ed->data[0] = data[0]; + ed->data[1] = data[1]; + ed->data[2] = data[2]; + ed->data[3] = data[3]; +} + +static inline void elog_enum_sample (u8 which) +{ + ELOG_TYPE_DECLARE (e) = + { + .format = "my enum: %s", + .format_args = "t1", + .n_enum_strings = 2, + .enum_strings = + { + "string 1", + "string 2", + }, + }; + struct { u8 which;} * ed; + ed = ELOG_DATA (&vlib_global_main.elog_main, e); + ed->which = which; +} + +static inline void elog_one_datum_sample (u32 data) +{ + ELOG_TYPE_DECLARE (e) = + { + .format = "one datum: %d", + .format_args = "i4", + }; + + elog (&vlib_global_main.elog_main, &e, data); +} + +static clib_error_t * +test_elog_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + int i; + u32 samples[4]; + + for (i = 0; i < 10; i++) + { + samples[0] = i; + samples[1] = i+1; + samples[2] = i+2; + samples[3] = i+3; + + elog_four_int_sample (samples); + elog_four_int_track_sample (samples); + elog_enum_sample (0); + elog_enum_sample (1); + elog_one_datum_sample (i); + } + + return 0; +} + +VLIB_CLI_COMMAND (test_elog_command, static) = { + .path = "test elog sample", + .short_help = "test elog sample", + .function = test_elog_command_fn, +}; diff --git a/vlib/vlib/main.c b/vlib/vlib/main.c index fe9a7da8243..07cf7fb2e6b 100644 --- a/vlib/vlib/main.c +++ b/vlib/vlib/main.c @@ -665,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, }; @@ -711,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) @@ -729,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", diff --git a/vppinfra/vppinfra/elog.c b/vppinfra/vppinfra/elog.c index 222c55fd63e..b748963933c 100644 --- a/vppinfra/vppinfra/elog.c +++ b/vppinfra/vppinfra/elog.c @@ -419,7 +419,7 @@ elog_nsec_per_clock (elog_main_t * em) &em->init_time)); } -static void elog_alloc (elog_main_t * em, u32 n_events) +void elog_alloc (elog_main_t * em, u32 n_events) { if (em->event_ring) vec_free (em->event_ring); diff --git a/vppinfra/vppinfra/elog.h b/vppinfra/vppinfra/elog.h index db84c95f7ca..afa677338e5 100644 --- a/vppinfra/vppinfra/elog.h +++ b/vppinfra/vppinfra/elog.h @@ -408,6 +408,7 @@ void serialize_elog_main (serialize_main_t * m, va_list * va); void unserialize_elog_main (serialize_main_t * m, va_list * va); void elog_init (elog_main_t * em, u32 n_events); +void elog_alloc (elog_main_t * em, u32 n_events); #ifdef CLIB_UNIX always_inline clib_error_t * |