Add MI output to the metadata regenerate command
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 17 Sep 2015 14:58:10 +0000 (10:58 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 14 Mar 2016 19:30:16 +0000 (15:30 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/metadata.c
src/common/mi-lttng-3.0.xsd
src/common/mi-lttng.c
src/common/mi-lttng.h
tests/regression/tools/mi/test_mi

index 20c577e53a9c2b07cf2d54effac7d59166b60887..0faf4172a370349fabb2e8a46e7283d634b4bab6 100644 (file)
@@ -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);
        }
index 5c58f6896bc50e56af45c6157010f38a7bb149aa..cfccc2a655cbfa9923516ac4956bcad106d925ce 100644 (file)
@@ -489,7 +489,7 @@ THE SOFTWARE.
                </xs:sequence>
        </xs:complexType>
 
-       <!-- Maps to an action dutring snapshot command -->
+       <!-- Maps to an action during snapshot command -->
        <xs:complexType name="snapshot_action_type">
                <xs:sequence>
                        <xs:element name="name" type="tns:snapshot_actiontype_type" minOccurs="0" />
@@ -507,6 +507,20 @@ THE SOFTWARE.
                </xs:restriction>
        </xs:simpleType>
 
+       <!-- Maps to an action during metadata command -->
+       <xs:complexType name="metadata_action_type">
+               <xs:sequence>
+                       <xs:element name="name" type="tns:metadata_actiontype_type" minOccurs="0" />
+               </xs:sequence>
+       </xs:complexType>
+
+       <!-- Type of metadata commands -->
+       <xs:simpleType name="metadata_actiontype_type">
+               <xs:restriction base="xs:string">
+                       <xs:enumeration value="regenerate" />
+               </xs:restriction>
+       </xs:simpleType>
+
        <xs:complexType name="output_type">
                <xs:choice>
                        <xs:element name="domains" type="tns:domains_type" minOccurs="0" />
@@ -523,6 +537,7 @@ THE SOFTWARE.
                        <xs:element name="events" type="tns:event_list_type" minOccurs="0" />
                        <xs:element name="channel" type="tns:channel_type" minOccurs="0" />
                        <xs:element name="targets" type="tns:targets_type" minOccurs="0" />
+                       <xs:element name="metadata_action" type="tns:metadata_action_type" minOccurs="0" />
                </xs:choice>
        </xs:complexType>
 
@@ -547,6 +562,7 @@ THE SOFTWARE.
                        <xs:enumeration value="disable-channel" />
                        <xs:enumeration value="track" />
                        <xs:enumeration value="untrack" />
+                       <xs:enumeration value="metadata" />
                </xs:restriction>
        </xs:simpleType>
 
index 8401c26716aeaefd8e4ea8a6342582952e00d59a..c3ed1ce2d64975ea82c0b1e38f2678c5ae14cb57 100644 (file)
@@ -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";
index 192f31804d5a177c45983fe292529d9682603e1a..585818dae4387b5698dde31af7d5d0355a0c1094 100644 (file)
@@ -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;
index cd18b58ddf0a12465b242ce58ee8a06704c6ef55..e8c032ce52a75eff5bc9912299e46e62bbedff05 100755 (executable)
@@ -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
This page took 0.040063 seconds and 4 git commands to generate.