Mi calibrate command: support and validation
authorJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Wed, 18 Jun 2014 18:28:04 +0000 (14:28 -0400)
committerJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Tue, 22 Jul 2014 20:14:57 +0000 (16:14 -0400)
Signed-off-by: Jonathan Rajotte Julien <jonathan.r.julien@gmail.com>
src/bin/lttng/commands/calibrate.c
src/common/mi-lttng.c
src/common/mi-lttng.h
src/common/mi_lttng.xsd

index 7d4de2909cf0f3fc45c1234c52b1f09e7fb2ec3f..567f4a5fa560b6b031ca02b505e4e8b286a84760 100644 (file)
@@ -26,6 +26,9 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <inttypes.h>
 #include <ctype.h>
+#include <assert.h>
+
+#include <common/mi-lttng.h>
 
 #include "../command.h"
 
 
 #include "../command.h"
 
@@ -51,6 +54,7 @@ enum {
 };
 
 static struct lttng_handle *handle;
 };
 
 static struct lttng_handle *handle;
+static struct mi_writer *writer;
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
@@ -133,13 +137,6 @@ static int calibrate_lttng(void)
                goto error;
        }
 
                goto error;
        }
 
-       /* TODO: mi support */
-       if (lttng_opt_mi) {
-               ret = -LTTNG_ERR_MI_NOT_IMPLEMENTED;
-               ERR("mi option not supported");
-               goto error;
-       }
-
        handle = lttng_create_handle(NULL, &dom);
        if (handle == NULL) {
                ret = CMD_ERROR;
        handle = lttng_create_handle(NULL, &dom);
        if (handle == NULL) {
                ret = CMD_ERROR;
@@ -174,7 +171,14 @@ static int calibrate_lttng(void)
                goto error;
        }
 
                goto error;
        }
 
-       ret = CMD_SUCCESS;
+       if (lttng_opt_mi) {
+               assert(writer);
+               ret = mi_lttng_calibrate(writer, &calibrate);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto error;
+               }
+       }
 
 error:
        lttng_destroy_handle(handle);
 
 error:
        lttng_destroy_handle(handle);
@@ -189,7 +193,7 @@ error:
  */
 int cmd_calibrate(int argc, const char **argv)
 {
  */
 int cmd_calibrate(int argc, const char **argv)
 {
-       int opt, ret = CMD_SUCCESS;
+       int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
        static poptContext pc;
 
        pc = poptGetContext(NULL, argc, argv, long_options, 0);
        static poptContext pc;
 
        pc = poptGetContext(NULL, argc, argv, long_options, 0);
@@ -234,9 +238,71 @@ int cmd_calibrate(int argc, const char **argv)
                }
        }
 
                }
        }
 
-       ret = calibrate_lttng();
+       /* Mi check */
+       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_calibrate);
+               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;
+               }
+       }
+
+       command_ret = calibrate_lttng();
+       if (command_ret) {
+               success = 0;
+       }
+
+       /* Mi closing */
+       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:
 
 end:
+       /* Mi clean-up */
+       if (writer && mi_lttng_writer_destroy(writer)) {
+               /* Preserve original error code */
+               ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
+       }
+
+       /* Overwrite ret if an error occurred during calibrate_lttng() */
+       ret = command_ret ? command_ret : ret;
+
        poptFreeContext(pc);
        return ret;
 }
        poptFreeContext(pc);
        return ret;
 }
index 15deeb21ac64f6de1b214882f8a7f89fc7798548..2fb1c19050da82acc07ac1ec9f89b22cb0c01c59 100644 (file)
@@ -34,6 +34,7 @@ const char * const mi_lttng_element_command_start = "start";
 const char * const mi_lttng_element_command_stop = "stop";
 const char * const mi_lttng_element_command_create = "create";
 const char * const mi_lttng_element_command_destroy = "destroy";
 const char * const mi_lttng_element_command_stop = "stop";
 const char * const mi_lttng_element_command_create = "create";
 const char * const mi_lttng_element_command_destroy = "destroy";
+const char * const mi_lttng_element_command_calibrate = "calibrate";
 const char * const mi_lttng_element_command_output = "output";
 const char * const mi_lttng_element_command_success = "success";
 
 const char * const mi_lttng_element_command_output = "output";
 const char * const mi_lttng_element_command_success = "success";
 
@@ -95,6 +96,10 @@ const char * const mi_lttng_loglevel_type_range = "RANGE";
 const char * const mi_lttng_loglevel_type_single = "SINGLE";
 const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
 
 const char * const mi_lttng_loglevel_type_single = "SINGLE";
 const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
 
+/* String related to lttng_calibrate */
+const char * const mi_lttng_element_calibrate = "calibrate";
+const char * const mi_lttng_element_calibrate_function = "FUNCTION";
+
 const char * const mi_lttng_element_empty = "";
 
 const char *mi_lttng_loglevel_string(int value)
 const char * const mi_lttng_element_empty = "";
 
 const char *mi_lttng_loglevel_string(int value)
@@ -220,6 +225,21 @@ const char *mi_lttng_buffertype_string(enum lttng_buffer_type value)
        }
 }
 
        }
 }
 
+const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val)
+{
+       const char *ret;
+
+       switch (val) {
+       case LTTNG_CALIBRATE_FUNCTION:
+               ret = mi_lttng_element_calibrate_function;
+               break;
+       default:
+               ret = mi_lttng_element_empty;
+               break;
+       }
+       return ret;
+}
+
 LTTNG_HIDDEN
 struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
 {
 LTTNG_HIDDEN
 struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
 {
@@ -969,3 +989,28 @@ close:
 end:
        return ret;
 }
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int mi_lttng_calibrate(struct mi_writer *writer,
+               struct lttng_calibrate *calibrate)
+{
+       int ret;
+
+       /* Open calibrate element */
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_calibrate);
+       if (ret) {
+               goto end;
+       }
+
+       /* Calibration type */
+       ret = mi_lttng_writer_write_element_string(writer, config_element_type,
+                       mi_lttng_calibratetype_string(calibrate->type));
+       if (ret) {
+               goto end;
+       }
+
+       /* Closing calibrate element */
+       ret = mi_lttng_writer_close_element(writer);
+end:
+       return ret;
+}
index 0f263fc5a69710bfc96efa5e7812d6a20c33bece..1c2a653a45d8aa1b77debfaaf90bf8594e0a9e9c 100644 (file)
@@ -56,6 +56,7 @@ const char * const mi_lttng_element_command_stop;
 const char * const mi_lttng_element_command_start;
 const char * const mi_lttng_element_command_create;
 const char * const mi_lttng_element_command_destroy;
 const char * const mi_lttng_element_command_start;
 const char * const mi_lttng_element_command_create;
 const char * const mi_lttng_element_command_destroy;
+const char * const mi_lttng_element_command_calibrate;
 const char * const mi_lttng_element_command_output;
 const char * const mi_lttng_element_command_success;
 
 const char * const mi_lttng_element_command_output;
 const char * const mi_lttng_element_command_success;
 
@@ -117,12 +118,17 @@ const char * const mi_lttng_loglevel_type_range;
 const char * const mi_lttng_loglevel_type_single;
 const char * const mi_lttng_loglevel_type_unknown;
 
 const char * const mi_lttng_loglevel_type_single;
 const char * const mi_lttng_loglevel_type_unknown;
 
+/* Sting related to lttng_calibrate */
+const char * const mi_lttng_element_calibrate;
+const char * const mi_lttng_element_calibrate_function;
+
 /* Utility string function  */
 const char *mi_lttng_loglevel_string(int value);
 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value);
 const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
 /* Utility string function  */
 const char *mi_lttng_loglevel_string(int value);
 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value);
 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type value);
 const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
+const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
 
 /*
  * Create an instance of a machine interface writer.
 
 /*
  * Create an instance of a machine interface writer.
@@ -510,4 +516,17 @@ int mi_lttng_pids_open(struct mi_writer *writer);
 int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
                int is_open);
 
 int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
                int is_open);
 
+/*
+ * Machine interface for struct lttng_calibrate.
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * calibrate A lttng_calibrate instance.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ */
+int mi_lttng_calibrate(struct mi_writer *writer,
+               struct lttng_calibrate *calibrate);
+
 #endif /* _MI_LTTNG_H */
 #endif /* _MI_LTTNG_H */
index 76e9a152ef18fd85127d52169f16bc73235fed76..884830d1c32c65de867de363501a283def9a7b64 100644 (file)
@@ -106,6 +106,13 @@ THE SOFTWARE.
                </xs:restriction>
        </xs:simpleType>
 
                </xs:restriction>
        </xs:simpleType>
 
+       <!-- Maps to the lttng_calibrate_type enum -->
+       <xs:simpleType name="calibrate_type_type">
+               <xs:restriction base="xs:string">
+                       <xs:enumeration value="FUNCTION" />
+               </xs:restriction>
+       </xs:simpleType>
+
        <!-- Maps to the lttng_event_probe_attr struct -->
        <xs:complexType name="event_probe_attributes_type">
                <xs:all>
        <!-- Maps to the lttng_event_probe_attr struct -->
        <xs:complexType name="event_probe_attributes_type">
                <xs:all>
@@ -217,7 +224,7 @@ THE SOFTWARE.
        <xs:complexType name="domain_type">
                <xs:all>
                        <xs:element name="type" type="domain_type_type"/>
        <xs:complexType name="domain_type">
                <xs:all>
                        <xs:element name="type" type="domain_type_type"/>
-                       <xs:element name="buffer_type" type="domain_buffer_type"/>
+                       <xs:element name="buffer_type" type="domain_buffer_type" />
                        <xs:element name="pids" type="pids_type" minOccurs="0" />
                        <xs:element name="channels" type="channels_type" minOccurs="0" />
                        <xs:element name="events" type="event_list_type" minOccurs="0" />
                        <xs:element name="pids" type="pids_type" minOccurs="0" />
                        <xs:element name="channels" type="channels_type" minOccurs="0" />
                        <xs:element name="events" type="event_list_type" minOccurs="0" />
@@ -291,6 +298,13 @@ THE SOFTWARE.
                </xs:all>
        </xs:complexType>
 
                </xs:all>
        </xs:complexType>
 
+       <!-- Maps to struct lttng_calibrate -->
+       <xs:complexType name="calibrate_type">
+               <xs:all>
+                       <xs:element name="type" type="calibrate_type_type" />
+               </xs:all>
+       </xs:complexType>
+
        <xs:complexType name="domains_type">
                <xs:sequence>
                        <xs:element name="domain" type="domain_type" minOccurs="0" maxOccurs="unbounded" />
        <xs:complexType name="domains_type">
                <xs:sequence>
                        <xs:element name="domain" type="domain_type" minOccurs="0" maxOccurs="unbounded" />
@@ -317,6 +331,7 @@ THE SOFTWARE.
                        <xs:element name="version" type="version_type" minOccurs="0" />
                        <xs:element name="save" type="save_type" minOccurs="0" />
                        <xs:element name="load" type="load_type" minOccurs="0" />
                        <xs:element name="version" type="version_type" minOccurs="0" />
                        <xs:element name="save" type="save_type" minOccurs="0" />
                        <xs:element name="load" type="load_type" minOccurs="0" />
+                       <xs:element name="calibrate" type="calibrate_type" minOccurs="0" />
                </xs:choice>
        </xs:complexType>
 
                </xs:choice>
        </xs:complexType>
 
@@ -331,6 +346,7 @@ THE SOFTWARE.
                        <xs:enumeration value="start" />
                        <xs:enumeration value="stop" />
                        <xs:enumeration value="destroy" />
                        <xs:enumeration value="start" />
                        <xs:enumeration value="stop" />
                        <xs:enumeration value="destroy" />
+                       <xs:enumeration value="calibrate" />
                </xs:restriction>
        </xs:simpleType>
 
                </xs:restriction>
        </xs:simpleType>
 
This page took 0.030731 seconds and 4 git commands to generate.