From 54897b571f12970647556f1ad73fc8e30db2258d Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Thu, 17 Sep 2015 10:58:10 -0400 Subject: [PATCH] Add MI output to the metadata regenerate command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/metadata.c | 83 ++++++++++++++++++++++++++++++- src/common/mi-lttng-3.0.xsd | 18 ++++++- src/common/mi-lttng.c | 2 + src/common/mi-lttng.h | 2 + tests/regression/tools/mi/test_mi | 7 ++- 5 files changed, 109 insertions(+), 3 deletions(-) diff --git a/src/bin/lttng/commands/metadata.c b/src/bin/lttng/commands/metadata.c index 20c577e53..0faf4172a 100644 --- a/src/bin/lttng/commands/metadata.c +++ b/src/bin/lttng/commands/metadata.c @@ -39,6 +39,8 @@ enum { OPT_LIST_COMMANDS, }; +static struct mi_writer *writer; + static struct poptOption long_options[] = { /* { longName, shortName, argInfo, argPtr, value, descrip, argDesc, } */ { "help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0, }, @@ -114,7 +116,32 @@ static int handle_command(const char **argv) while (cmd->func != NULL) { /* Find command */ if (strcmp(argv[0], cmd->name) == 0) { + if (lttng_opt_mi) { + /* Action element */ + ret = mi_lttng_writer_open_element(writer, + mi_lttng_element_command_metadata_action); + if (ret) { + ret = CMD_ERROR; + goto end; + } + + /* Name of the action */ + ret = mi_lttng_writer_write_element_string(writer, + config_element_name, argv[0]); + if (ret) { + ret = CMD_ERROR; + goto end; + } + } command_ret = cmd->func(argc, argv); + if (lttng_opt_mi) { + /* Close output and action element */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + ret = CMD_ERROR; + goto end; + } + } goto end; } @@ -134,7 +161,7 @@ end: */ int cmd_metadata(int argc, const char **argv) { - int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; + int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; if (argc < 1) { @@ -146,6 +173,29 @@ int cmd_metadata(int argc, const char **argv) pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); + if (lttng_opt_mi) { + writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); + if (!writer) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + /* Open command element */ + ret = mi_lttng_writer_command_open(writer, + mi_lttng_element_command_metadata); + if (ret) { + ret = CMD_ERROR; + goto end; + } + + /* Open output element */ + ret = mi_lttng_writer_open_element(writer, + mi_lttng_element_command_output); + if (ret) { + ret = CMD_ERROR; + goto end; + } + } + while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: @@ -179,11 +229,42 @@ int cmd_metadata(int argc, const char **argv) switch (-command_ret) { default: ERR("%s", lttng_strerror(command_ret)); + success = 0; break; } } + if (lttng_opt_mi) { + /* Close output element */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + ret = CMD_ERROR; + goto end; + } + + /* Success ? */ + ret = mi_lttng_writer_write_element_bool(writer, + mi_lttng_element_command_success, success); + if (ret) { + ret = CMD_ERROR; + goto end; + } + + /* Command element close */ + ret = mi_lttng_writer_command_close(writer); + if (ret) { + ret = CMD_ERROR; + goto end; + } + } + end: + /* Mi clean-up */ + if (writer && mi_lttng_writer_destroy(writer)) { + /* Preserve original error code */ + ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; + } + if (!opt_session_name) { free(session_name); } diff --git a/src/common/mi-lttng-3.0.xsd b/src/common/mi-lttng-3.0.xsd index 5c58f6896..cfccc2a65 100644 --- a/src/common/mi-lttng-3.0.xsd +++ b/src/common/mi-lttng-3.0.xsd @@ -489,7 +489,7 @@ THE SOFTWARE. - + @@ -507,6 +507,20 @@ THE SOFTWARE. + + + + + + + + + + + + + + @@ -523,6 +537,7 @@ THE SOFTWARE. + @@ -547,6 +562,7 @@ THE SOFTWARE. + diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 8401c2671..c3ed1ce2d 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -56,6 +56,8 @@ const char * const mi_lttng_element_command_enable_channels = "enable-channel"; const char * const mi_lttng_element_command_enable_event = "enable-event"; const char * const mi_lttng_element_command_list = "list"; const char * const mi_lttng_element_command_load = "load"; +const char * const mi_lttng_element_command_metadata = "metadata"; +const char * const mi_lttng_element_command_metadata_action = "metadata_action"; const char * const mi_lttng_element_command_name = "name"; const char * const mi_lttng_element_command_output = "output"; const char * const mi_lttng_element_command_save = "save"; diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index 192f31804..585818dae 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -62,6 +62,8 @@ extern const char * const mi_lttng_element_command_enable_channels; extern const char * const mi_lttng_element_command_enable_event; extern const char * const mi_lttng_element_command_list; extern const char * const mi_lttng_element_command_load; +extern const char * const mi_lttng_element_command_metadata; +extern const char * const mi_lttng_element_command_metadata_action; extern const char * const mi_lttng_element_command_name; extern const char * const mi_lttng_element_command_output; extern const char * const mi_lttng_element_command_save; diff --git a/tests/regression/tools/mi/test_mi b/tests/regression/tools/mi/test_mi index cd18b58dd..e8c032ce5 100755 --- a/tests/regression/tools/mi/test_mi +++ b/tests/regression/tools/mi/test_mi @@ -59,7 +59,7 @@ DEVNULL=/dev/null 2>&1 DIR=$(readlink -f $TESTDIR) -NUM_TESTS=222 +NUM_TESTS=224 source $TESTDIR/utils/utils.sh @@ -608,6 +608,11 @@ function test_start_stop () { test "$result" = "true" ok $? "Mi test: enabled element : $result expected: true" + #Test metadata regenerate command + metadata_regenerate_ok $session_name + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: metadata regenerate" + #Test stop command stop_lttng_tracing_ok $session_name $XML_VALIDATE $OUTPUT_DEST -- 2.34.1