From: Mathieu Desnoyers Date: Wed, 10 Apr 2024 15:46:27 +0000 (-0400) Subject: cli: add `--allowed-mip-versions` option to restrict MIP version X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=696126c6a30f831f08ed6f78669600c9ddfc6d0a;p=babeltrace.git cli: add `--allowed-mip-versions` option to restrict MIP version Introduce a new "--allowed-mip-versions=VER" command line argument to babeltrace2. By default, versions 0 and 1 are allowed (prior behavior before this patch). It allows specifying that either version 0 or 1 are to be allowed in the graph. Its main purpose is for testing implementation of plugin components interactions for specific MIP versions. Philippe's changes to the original patch: ‣ Use `--allowed-mip-versions` instead of `--allowed-mip-version`: in the future we might want to make it possible to specify more than one version, for example `--allowed-mip-versions=0,1,5` or even `--allowed-mip-versions=0-2,5`. The current single-version format is to be considered an initial, temporary limitation. ‣ Use the short option `-m` for `--allowed-mip-versions`. ‣ Sort options alphabetically by long name in the output of `--help`. ‣ Updated the manual pages. Change-Id: I1c9f74176f6686ec560ede2494b89e28f35da6a6 Signed-off-by: Simon Marchi Signed-off-by: Mathieu Desnoyers Signed-off-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12792 Tested-by: jenkins --- diff --git a/doc/man/babeltrace2-convert.1.txt b/doc/man/babeltrace2-convert.1.txt index d20862a9..61d7f403 100644 --- a/doc/man/babeltrace2-convert.1.txt +++ b/doc/man/babeltrace2-convert.1.txt @@ -14,19 +14,20 @@ Pretty-print (plain text) the events, in order, of one or more traces: [verse] *babeltrace2* [<>] [*convert*] [opt:--retry-duration='TIME-US'] - 'TRACE-PATH'... + [opt:--allowed-mip-versions='VERSION'] 'TRACE-PATH'... Convert one or more traces to a given format: [verse] *babeltrace2* [<>] [*convert*] [opt:--retry-duration='TIME-US'] - 'CONVERSION ARGS' + [opt:--allowed-mip-versions='VERSION'] 'CONVERSION ARGS' Get the equivalent man:babeltrace2-run(1) command arguments to convert one or more traces to a given format: [verse] *babeltrace2* [<>] [*convert*] [opt:--retry-duration='TIME-US'] + [opt:--allowed-mip-versions='VERSION'] (opt:--run-args | opt:--run-args-0) 'CONVERSION ARGS' Print the metadata text of a CTF trace: @@ -854,6 +855,12 @@ opt:--stream-intersection option. === Conversion graph configuration +opt:-m 'VERSION':: +opt:--allowed-mip-versions='VERSION':: + Only allow the conversion graph to honour version 'VERSION' (0 or 1) + of the Message Interchange Protocol (MIP) instead of allowing + both versions. + opt:--retry-duration='TIME-US':: Set the duration of a single retry to 'TIME-US'~µs when a sink component reports "try again later" (busy network or file system, diff --git a/doc/man/babeltrace2-run.1.txt b/doc/man/babeltrace2-run.1.txt index 4c376b78..a50a8406 100644 --- a/doc/man/babeltrace2-run.1.txt +++ b/doc/man/babeltrace2-run.1.txt @@ -13,6 +13,7 @@ babeltrace2-run - Create a Babeltrace 2 trace processing graph and run it [verse] *babeltrace2* [<>] *run* [opt:--retry-duration='TIME-US'] + [opt:--allowed-mip-versions='VERSION'] opt:--connect='CONN-RULE'... 'COMPONENTS' @@ -270,6 +271,12 @@ See <> to learn more. === Graph configuration +opt:-m 'VERSION':: +opt:--allowed-mip-versions='VERSION':: + Only allow the graph to honour version 'VERSION' (0 or 1) + of the Message Interchange Protocol (MIP) instead of allowing + both versions. + opt:--retry-duration='TIME-US':: Set the duration of a single retry to 'TIME-US'~µs when a sink component reports "try again later" (busy network or file system, diff --git a/src/cli/babeltrace2-cfg-cli-args.c b/src/cli/babeltrace2-cfg-cli-args.c index 2fdadf21..cd026aba 100644 --- a/src/cli/babeltrace2-cfg-cli-args.c +++ b/src/cli/babeltrace2-cfg-cli-args.c @@ -829,6 +829,7 @@ end: /* argpar options */ enum { OPT_NONE = 0, + OPT_ALLOWED_MIP_VERSIONS, OPT_BASE_PARAMS, OPT_BEGIN, OPT_CLOCK_CYCLES, @@ -1874,6 +1875,8 @@ void print_run_usage(FILE *fp) fprintf(fp, "\n"); fprintf(fp, "Options:\n"); fprintf(fp, "\n"); + fprintf(fp, " -m, --allowed-mip-versions=VER Allow only the MIP version VER (0 or 1)\n"); + fprintf(fp, " (default: all MIP versions are allowed)\n"); fprintf(fp, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n"); fprintf(fp, " for all the following components until\n"); fprintf(fp, " --reset-base-params is encountered\n"); @@ -1954,6 +1957,7 @@ enum bt_config_cli_args_status bt_config_run_from_args(int argc, const char *arg bt_value *connection_args = NULL; char error_buf[256] = { 0 }; long retry_duration = -1; + long allowed_mip_version = -1; bt_value_map_extend_status extend_status; GString *error_str = NULL; struct argpar_iter *argpar_iter = NULL; @@ -1968,6 +1972,7 @@ enum bt_config_cli_args_status bt_config_run_from_args(int argc, const char *arg { OPT_PARAMS, 'p', "params", true }, { OPT_RESET_BASE_PARAMS, 'r', "reset-base-params", false }, { OPT_RETRY_DURATION, '\0', "retry-duration", true }, + { OPT_ALLOWED_MIP_VERSIONS, 'm', "allowed-mip-versions", true }, ARGPAR_OPT_DESCR_SENTINEL }; @@ -1989,6 +1994,8 @@ enum bt_config_cli_args_status bt_config_run_from_args(int argc, const char *arg } cfg->cmd_data.run.retry_duration_us = 100000; + cfg->cmd_data.run.allow_mip_0 = true; + cfg->cmd_data.run.allow_mip_1 = true; cur_base_params = bt_value_map_create(); if (!cur_base_params) { BT_CLI_LOGE_APPEND_CAUSE_OOM(); @@ -2179,6 +2186,29 @@ enum bt_config_cli_args_status bt_config_run_from_args(int argc, const char *arg (uint64_t) retry_duration; break; } + case OPT_ALLOWED_MIP_VERSIONS: { + gchar *end; + size_t arg_len = strlen(arg); + + allowed_mip_version = g_ascii_strtoll(arg, &end, 10); + + if (arg_len == 0 || end != (arg + arg_len)) { + BT_CLI_LOGE_APPEND_CAUSE( + "Could not parse --allowed-mip-versions option's argument as an unsigned integer: `%s`", + arg); + goto error; + } + + if (allowed_mip_version < 0 || allowed_mip_version > 1) { + BT_CLI_LOGE_APPEND_CAUSE("--allowed-mip-versions option's argument must be 0 or 1: %ld", + allowed_mip_version); + goto error; + } + + cfg->cmd_data.run.allow_mip_0 = (allowed_mip_version == 0); + cfg->cmd_data.run.allow_mip_1 = (allowed_mip_version == 1); + break; + } default: bt_common_abort(); } @@ -2279,6 +2309,8 @@ void print_convert_usage(FILE *fp) fprintf(fp, "\n"); fprintf(fp, "Options:\n"); fprintf(fp, "\n"); + fprintf(fp, " -m, --allowed-mip-versions=VER Allow only the MIP version VER (0 or 1)\n"); + fprintf(fp, " (default: all MIP versions are allowed)\n"); fprintf(fp, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n"); fprintf(fp, " Instantiate the component class CLS of type\n"); fprintf(fp, " TYPE (`source`, `filter`, or `sink`) found\n"); @@ -2395,6 +2427,7 @@ void print_convert_usage(FILE *fp) static const struct argpar_opt_descr convert_options[] = { /* id, short_name, long_name, with_arg */ + { OPT_ALLOWED_MIP_VERSIONS, 'm', "allowed-mip-versions", true }, { OPT_BEGIN, 'b', "begin", true }, { OPT_CLOCK_CYCLES, '\0', "clock-cycles", false }, { OPT_CLOCK_DATE, '\0', "clock-date", false }, @@ -3694,6 +3727,18 @@ enum bt_config_cli_args_status bt_config_convert_from_args(int argc, goto error; } + if (bt_value_array_append_string_element(run_args, arg)) { + BT_CLI_LOGE_APPEND_CAUSE_OOM(); + goto error; + } + break; + case OPT_ALLOWED_MIP_VERSIONS: + if (bt_value_array_append_string_element(run_args, + "--allowed-mip-versions")) { + BT_CLI_LOGE_APPEND_CAUSE_OOM(); + goto error; + } + if (bt_value_array_append_string_element(run_args, arg)) { BT_CLI_LOGE_APPEND_CAUSE_OOM(); goto error; @@ -4059,6 +4104,7 @@ enum bt_config_cli_args_status bt_config_convert_from_args(int argc, *default_log_level = logging_level_min(*default_log_level, BT_LOG_TRACE); break; + case OPT_ALLOWED_MIP_VERSIONS: case OPT_COMPONENT: case OPT_HELP: case OPT_LOG_LEVEL: diff --git a/src/cli/babeltrace2-cfg.h b/src/cli/babeltrace2-cfg.h index 81db306a..a17d778a 100644 --- a/src/cli/babeltrace2-cfg.h +++ b/src/cli/babeltrace2-cfg.h @@ -73,6 +73,10 @@ struct bt_config { */ uint64_t retry_duration_us; + /* Allowed MIP versions */ + bool allow_mip_0; + bool allow_mip_1; + /* * Whether or not to trim the source trace to the * intersection of its streams. diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index fbe38a87..bb497d44 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -1763,6 +1763,7 @@ bt_get_greatest_operative_mip_version_status get_greatest_operative_mip_version( bt_get_greatest_operative_mip_version_status status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_OK; bt_component_descriptor_set *comp_descr_set = NULL; + bt_integer_range_set_unsigned *mip_version_restriction = NULL; int ret; BT_ASSERT(cfg); @@ -1812,10 +1813,41 @@ bt_get_greatest_operative_mip_version_status get_greatest_operative_mip_version( } } - status = bt_get_greatest_operative_mip_version(comp_descr_set, - (bt_logging_level) bt_cli_log_level, mip_version); + /* Set MIP version restrictions if needed */ + if (!cfg->cmd_data.run.allow_mip_0 || !cfg->cmd_data.run.allow_mip_1) { + mip_version_restriction = bt_integer_range_set_unsigned_create(); + if (!mip_version_restriction) { + status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_MEMORY_ERROR; + goto end; + } + + if (cfg->cmd_data.run.allow_mip_0) { + bt_integer_range_set_add_range_status add_range_status = + bt_integer_range_set_unsigned_add_range( + mip_version_restriction, 0, 0); + if (add_range_status != BT_INTEGER_RANGE_SET_ADD_RANGE_STATUS_OK) { + status = (int) add_range_status; + goto end; + } + } + + if (cfg->cmd_data.run.allow_mip_1) { + bt_integer_range_set_add_range_status add_range_status = + bt_integer_range_set_unsigned_add_range( + mip_version_restriction, 1, 1); + if (add_range_status != BT_INTEGER_RANGE_SET_ADD_RANGE_STATUS_OK) { + status = (int) add_range_status; + goto end; + } + } + } + + status = bt_get_greatest_operative_mip_version_with_restriction( + comp_descr_set, (bt_logging_level) bt_cli_log_level, + mip_version_restriction, mip_version); end: + bt_object_put_ref(mip_version_restriction); bt_component_descriptor_set_put_ref(comp_descr_set); return status; }