cli: add `--allowed-mip-versions` option to restrict MIP version
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 10 Apr 2024 15:46:27 +0000 (11:46 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Oct 2024 02:56:57 +0000 (22:56 -0400)
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 <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12792
Tested-by: jenkins <jenkins@lttng.org>
doc/man/babeltrace2-convert.1.txt
doc/man/babeltrace2-run.1.txt
src/cli/babeltrace2-cfg-cli-args.c
src/cli/babeltrace2-cfg.h
src/cli/babeltrace2.c

index d20862a97a69b90b5949eeb3d50e3441f4c293a4..61d7f403c654e9a3ffe1c9ac385554492b1bfb2a 100644 (file)
@@ -14,19 +14,20 @@ Pretty-print (plain text) the events, in order, of one or more traces:
 
 [verse]
 *babeltrace2* [<<gen-opts,'GENERAL OPTIONS'>>] [*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* [<<gen-opts,'GENERAL OPTIONS'>>] [*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* [<<gen-opts,'GENERAL OPTIONS'>>] [*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,
index 4c376b789e40f9014889cd0f01f424d04c519e52..a50a840673adff5e8735ba4bc347473467f945d6 100644 (file)
@@ -13,6 +13,7 @@ babeltrace2-run - Create a Babeltrace 2 trace processing graph and run it
 
 [verse]
 *babeltrace2* [<<gen-opts,'GENERAL OPTIONS'>>] *run* [opt:--retry-duration='TIME-US']
+            [opt:--allowed-mip-versions='VERSION']
             opt:--connect='CONN-RULE'... 'COMPONENTS'
 
 
@@ -270,6 +271,12 @@ See <<connect-comps,``Connect components''>> 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,
index 2fdadf219958088e13c5122a9fc445945df65464..cd026aba3b178fd9300ceb2c05fb3df61677f935 100644 (file)
@@ -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:
index 81db306a075a1110a4481556d8b0151625614dee..a17d778a2fbeae1aee14dae559702f18f61c68ca 100644 (file)
@@ -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.
index fbe38a87d93c2d82a5ab63163372b3f1de9e9a75..bb497d444cf7810e59c30211b5a00397ed797106 100644 (file)
@@ -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;
 }
This page took 0.031345 seconds and 4 git commands to generate.