#include <unistd.h>
#include <inttypes.h>
#include <ctype.h>
+#include <assert.h>
+
+#include <common/mi-lttng.h>
#include "../command.h"
};
static struct lttng_handle *handle;
+static struct mi_writer *writer;
static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
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;
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);
*/
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);
}
}
- 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:
+ /* 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;
}
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_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 *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)
{
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;
+}
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_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);
+const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
/*
* Create an instance of a machine interface writer.
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 */
</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>
<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: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: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:enumeration value="start" />
<xs:enumeration value="stop" />
<xs:enumeration value="destroy" />
+ <xs:enumeration value="calibrate" />
</xs:restriction>
</xs:simpleType>