diff options
author | Ray Kinsella <mdr@ashroe.eu> | 2021-03-10 15:12:02 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-04-01 13:07:09 +0000 |
commit | 7e3862927ec0fd92a1237a9b4286aaf410f34166 (patch) | |
tree | 242b9f604622270f830dc260e3edd0fc5e8d6296 /src | |
parent | 74a4a70efaa4a3af998cae32ff3612ad7a7fa879 (diff) |
perfmon: combined set and start command.
Original set, start, stop, reset, show etc interface was somewhat cumbersome, we
can improve slightly by combining set and start.
Type: improvement
Signed-off-by: Ray Kinsella <mdr@ashroe.eu>
Change-Id: I7b865b2c29d2ab32adbd24d7f8a580da6990bb76
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/perfmon/cli.c | 63 | ||||
-rw-r--r-- | src/plugins/perfmon/perfmon.c | 17 | ||||
-rw-r--r-- | src/plugins/perfmon/perfmon.h | 3 |
3 files changed, 36 insertions, 47 deletions
diff --git a/src/plugins/perfmon/cli.c b/src/plugins/perfmon/cli.c index 7ffa6e89c0a..39e0319603a 100644 --- a/src/plugins/perfmon/cli.c +++ b/src/plugins/perfmon/cli.c @@ -250,7 +250,6 @@ show_perfmon_active_bundle_command_fn (vlib_main_t *vm, perfmon_main_t *pm = &perfmon_main; vlib_cli_output (vm, "%U\n", format_perfmon_bundle, pm->active_bundle, 1); - return 0; } @@ -278,7 +277,7 @@ show_perfmon_stats_command_fn (vlib_main_t *vm, unformat_input_t *input, u8 raw = 0; if (b == 0) - return clib_error_return (0, "no budle selected"); + return clib_error_return (0, "no bundle selected"); while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -376,19 +375,37 @@ VLIB_CLI_COMMAND (show_perfmon_stats_command, static) = { }; static clib_error_t * -set_perfmon_bundle_command_fn (vlib_main_t *vm, unformat_input_t *input, - vlib_cli_command_t *cmd) +perfmon_reset_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + perfmon_reset (vm); + return 0; +} + +VLIB_CLI_COMMAND (perfmon_reset_command, static) = { + .path = "perfmon reset", + .short_help = "perfmon reset", + .function = perfmon_reset_command_fn, + .is_mp_safe = 1, +}; + +static clib_error_t * +perfmon_start_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) { perfmon_main_t *pm = &perfmon_main; unformat_input_t _line_input, *line_input = &_line_input; perfmon_bundle_t *b = 0; + if (pm->is_running) + return clib_error_return (0, "please stop first"); + if (unformat_user (input, unformat_line_input, line_input) == 0) return clib_error_return (0, "please specify bundle name"); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "%U", unformat_perfmon_bundle_name, &b)) + if (unformat (line_input, "bundle %U", unformat_perfmon_bundle_name, &b)) ; else return clib_error_return (0, "unknown input '%U'", @@ -399,44 +416,12 @@ set_perfmon_bundle_command_fn (vlib_main_t *vm, unformat_input_t *input, if (b == 0) return clib_error_return (0, "please specify bundle name"); - if (pm->is_running) - return clib_error_return (0, "please stop first"); - - return perfmon_set (vm, b); -} - -VLIB_CLI_COMMAND (set_perfmon_bundle_command, static) = { - .path = "set perfmon bundle", - .short_help = "set perfmon bundle [<bundle-name>]", - .function = set_perfmon_bundle_command_fn, - .is_mp_safe = 1, -}; - -static clib_error_t * -perfmon_reset_command_fn (vlib_main_t *vm, unformat_input_t *input, - vlib_cli_command_t *cmd) -{ - perfmon_reset (vm); - return 0; -} - -VLIB_CLI_COMMAND (perfmon_reset_command, static) = { - .path = "perfmon reset", - .short_help = "perfmon reset", - .function = perfmon_reset_command_fn, - .is_mp_safe = 1, -}; - -static clib_error_t * -perfmon_start_command_fn (vlib_main_t *vm, unformat_input_t *input, - vlib_cli_command_t *cmd) -{ - return perfmon_start (vm); + return perfmon_start (vm, b); } VLIB_CLI_COMMAND (perfmon_start_command, static) = { .path = "perfmon start", - .short_help = "perfmon start", + .short_help = "perfmon start bundle [<bundle-name>]", .function = perfmon_start_command_fn, .is_mp_safe = 1, }; diff --git a/src/plugins/perfmon/perfmon.c b/src/plugins/perfmon/perfmon.c index 316e7a5d60a..f9402f8f8e9 100644 --- a/src/plugins/perfmon/perfmon.c +++ b/src/plugins/perfmon/perfmon.c @@ -79,7 +79,7 @@ perfmon_reset (vlib_main_t *vm) pm->active_bundle = 0; } -clib_error_t * +static clib_error_t * perfmon_set (vlib_main_t *vm, perfmon_bundle_t *b) { clib_error_t *err = 0; @@ -212,17 +212,20 @@ error: } clib_error_t * -perfmon_start (vlib_main_t *vm) +perfmon_start (vlib_main_t *vm, perfmon_bundle_t *b) { + clib_error_t *err = 0; perfmon_main_t *pm = &perfmon_main; - int n_groups = vec_len (pm->group_fds); - - if (n_groups == 0) - return clib_error_return (0, "no bundle configured"); + int n_groups; if (pm->is_running == 1) return clib_error_return (0, "already running"); + if ((err = perfmon_set (vm, b)) != 0) + return err; + + n_groups = vec_len (pm->group_fds); + for (int i = 0; i < n_groups; i++) { if (ioctl (pm->group_fds[i], PERF_EVENT_IOC_ENABLE, @@ -238,8 +241,10 @@ perfmon_start (vlib_main_t *vm) vlib_node_set_dispatch_wrapper (vlib_get_main_by_index (i), perfmon_dispatch_wrapper); } + pm->sample_time = vlib_time_now (vm); pm->is_running = 1; + return 0; } diff --git a/src/plugins/perfmon/perfmon.h b/src/plugins/perfmon/perfmon.h index c8b8cc47716..f24a23bd974 100644 --- a/src/plugins/perfmon/perfmon.h +++ b/src/plugins/perfmon/perfmon.h @@ -164,8 +164,7 @@ extern perfmon_main_t perfmon_main; perfmon_bundle_t __perfmon_bundle_##x void perfmon_reset (vlib_main_t *vm); -clib_error_t *perfmon_set (vlib_main_t *vm, perfmon_bundle_t *); -clib_error_t *perfmon_start (vlib_main_t *vm); +clib_error_t *perfmon_start (vlib_main_t *vm, perfmon_bundle_t *); clib_error_t *perfmon_stop (vlib_main_t *vm); #define PERFMON_STRINGS(...) \ |