#include <string.h>
#include <assert.h>
+#include <common/mi-lttng.h>
#include <common/config/config.h>
+
#include "../command.h"
static char *opt_input_path;
OPT_FORCE,
};
+static struct mi_writer *writer;
+
static struct poptOption load_opts[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
{"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
fprintf(ofp, " before creating new one(s).\n");
}
+static int mi_partial_session(const char *session_name)
+{
+ int ret;
+ assert(writer);
+ assert(session_name);
+
+ /* Open session element */
+ ret = mi_lttng_writer_open_element(writer, config_element_session);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+ session_name);
+ if (ret) {
+ goto end;
+ }
+
+ /* Closing session element */
+ ret = mi_lttng_writer_close_element(writer);
+end:
+ return ret;
+}
+
+/*
+ * Mi print of load command
+ */
+static int mi_load_print(const char *session_name)
+{
+ int ret;
+ assert(writer);
+
+ if (opt_load_all) {
+ /* We use a wildcard to represent all sessions */
+ session_name = "*";
+ }
+
+ /* Print load element */
+ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_load);
+ if (ret) {
+ goto end;
+ }
+
+ /* Print session element */
+ ret = mi_partial_session(session_name);
+ if (ret) {
+ goto end;
+ }
+
+ /* Path element */
+ if (opt_input_path) {
+ ret = mi_lttng_writer_write_element_string(writer, config_element_path,
+ opt_input_path);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* Close load element */
+ ret = mi_lttng_writer_close_element(writer);
+
+end:
+ return ret;
+}
+
/*
* The 'load <options>' first level command
*/
int cmd_load(int argc, const char **argv)
{
- int ret = CMD_SUCCESS;
+ int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success;
int opt;
poptContext pc;
pc = poptGetContext(NULL, argc, argv, load_opts, 0);
poptReadDefaultConfig(pc, 0);
- /* TODO: mi support */
- if (lttng_opt_mi) {
- ret = -LTTNG_ERR_MI_NOT_IMPLEMENTED;
- ERR("mi option not supported");
- goto end;
- }
-
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
session_name = poptGetArg(pc);
if (session_name) {
DBG2("Loading session name: %s", session_name);
+ } else {
+ /* Default to load_all */
+ opt_load_all = 1;
}
}
- ret = config_load_session(opt_input_path, session_name, opt_force, 0);
- if (ret) {
- ERR("%s", lttng_strerror(ret));
- ret = -ret;
+ /* 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_load);
+ 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 = config_load_session(opt_input_path, session_name, opt_force, 0);
+ if (command_ret) {
+ ERR("%s", lttng_strerror(command_ret));
+ success = 0;
} else {
if (opt_load_all) {
MSG("All sessions have been loaded successfully");
} else {
MSG("Session has been loaded successfully");
}
+ success = 1;
+ }
+
+ /* Mi Printing and closing */
+ if (lttng_opt_mi) {
+ /* Mi print */
+ ret = mi_load_print(session_name);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* 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:
+ if (writer && mi_lttng_writer_destroy(writer)) {
+ /* Preserve original error code */
+ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
+ }
+
+ /* Overwrite ret if the was an error with the load command */
+ ret = command_ret ? -command_ret : ret;
+
poptFreeContext(pc);
return ret;
}
#include <string.h>
#include <assert.h>
+#include <common/mi-lttng.h>
+
#include "../command.h"
#include <lttng/save.h>
{0, 0, 0, 0, 0, 0, 0}
};
+static struct mi_writer *writer;
+
/*
* usage
*/
fprintf(ofp, " -f, --force Overwrite existing session configuration(s)\n");
}
+static int mi_partial_session(const char *session_name)
+{
+ int ret;
+ assert(writer);
+ assert(session_name);
+
+ /* Open session element */
+ ret = mi_lttng_writer_open_element(writer, config_element_session);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+ session_name);
+ if (ret) {
+ goto end;
+ }
+
+ /* Closing session element */
+ ret = mi_lttng_writer_close_element(writer);
+end:
+ return ret;
+}
+
+/*
+ * Mi print of save command
+ */
+static int mi_save_print(const char *session_name)
+{
+ int ret;
+ assert(writer);
+
+ if (opt_save_all) {
+ /* We use a wildcard to represent all sessions */
+ session_name = "*";
+ }
+
+ /* Print save element */
+ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_save);
+ if (ret) {
+ goto end;
+ }
+
+ /* Print session element */
+ ret = mi_partial_session(session_name);
+ if (ret) {
+ goto end;
+ }
+
+ /* Path element */
+ if (opt_output_path) {
+ ret = mi_lttng_writer_write_element_string(writer, config_element_path,
+ opt_output_path);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* Close save element */
+ ret = mi_lttng_writer_close_element(writer);
+end:
+ return ret;
+}
+
/*
* The 'save <options>' first level command
*/
int cmd_save(int argc, const char **argv)
{
- int ret = CMD_SUCCESS;
+ int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success;
int opt;
const char *session_name = NULL;
poptContext pc;
pc = poptGetContext(NULL, argc, argv, save_opts, 0);
poptReadDefaultConfig(pc, 0);
- /* TODO: mi support */
- if (lttng_opt_mi) {
- ret = -LTTNG_ERR_MI_NOT_IMPLEMENTED;
- ERR("mi option not supported");
- goto end;
- }
-
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
session_name = poptGetArg(pc);
if (session_name) {
DBG2("Session name: %s", session_name);
+ } else {
+ /* default to opt_save_all */
+ opt_save_all = 1;
}
}
goto end_destroy;
}
- ret = lttng_save_session(attr);
- if (ret < 0) {
- ERR("%s", lttng_strerror(ret));
+ /* Mi check */
+ if (lttng_opt_mi) {
+ writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
+ if (!writer) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end_destroy;
+ }
+
+ /* Open command element */
+ ret = mi_lttng_writer_command_open(writer,
+ mi_lttng_element_command_save);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Open output element */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_command_output);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+ }
+
+ command_ret = lttng_save_session(attr);
+ if (command_ret < 0) {
+ ERR("%s", lttng_strerror(command_ret));
+ success = 0;
} else {
/* Inform the user of what just happened on success. */
if (session_name && opt_output_path) {
} else {
MSG("All sessions have been saved successfully.");
}
+ success = 1;
+ }
+
+ /* Mi Printing and closing */
+ if (lttng_opt_mi) {
+ /* Mi print */
+ ret = mi_save_print(session_name);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Close output element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Success ? */
+ ret = mi_lttng_writer_write_element_bool(writer,
+ mi_lttng_element_command_success, success);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Command element close */
+ ret = mi_lttng_writer_command_close(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
}
end_destroy:
lttng_save_session_attr_destroy(attr);
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 command failed */
+ ret = command_ret ? -command_ret : ret;
+
poptFreeContext(pc);
return ret;
}
const char * const mi_lttng_element_command = "command";
const char * const mi_lttng_element_command_version = "version";
const char * const mi_lttng_element_command_list = "list";
+const char * const mi_lttng_element_command_save = "save";
+const char * const mi_lttng_element_command_load = "load";
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_success = "success";
-/* Strings related to command: version */
+/* Strings related to version command */
const char * const mi_lttng_element_version = "version";
const char * const mi_lttng_element_version_str = "string";
const char * const mi_lttng_element_version_web = "url";
const char * const mi_lttng_element_pid = "pid";
const char * const mi_lttng_element_pid_id = "id";
+/* Strings related to save command */
+const char * const mi_lttng_element_save = "save";
+
+/* Strings related to load command */
+const char * const mi_lttng_element_load = "load";
+
/* String related to a lttng_event_field */
const char * const mi_lttng_element_event_field = "event_field";
const char * const mi_lttng_element_event_fields = "event_fields";
const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN";
const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING";
+/* String related to loglevel type */
const char * const mi_lttng_loglevel_type_all = "ALL";
const char * const mi_lttng_loglevel_type_range = "RANGE";
const char * const mi_lttng_loglevel_type_single = "SINGLE";
const char * const mi_lttng_element_command;
const char * const mi_lttng_element_command_version;
const char * const mi_lttng_element_command_list;
+const char * const mi_lttng_element_command_save;
+const char * const mi_lttng_element_command_load;
const char * const mi_lttng_element_command_name;
const char * const mi_lttng_element_command_output;
+const char * const mi_lttng_element_command_success;
-/* Strings related to command: version */
+/* Strings related to version command */
const char * const mi_lttng_element_version;
const char * const mi_lttng_element_version_str;
const char * const mi_lttng_element_version_web;
const char * const mi_lttng_element_pid;
const char * const mi_lttng_element_pid_id;
+/* Strings related to save command */
+const char * const mi_lttng_element_save;
+
+/* Strings related to load command */
+const char * const mi_lttng_element_load;
+
/* General element of mi_lttng */
const char * const mi_lttng_element_type_other;
const char * const mi_lttng_element_type_integer;
const char * const mi_lttng_loglevel_str_unknown;
const char * const mi_lttng_loglevel_str_warning;
+/* String related to loglevel type */
const char * const mi_lttng_loglevel_type_all;
const char * const mi_lttng_loglevel_type_range;
const char * const mi_lttng_loglevel_type_single;
<xs:complexType name="session_type">
<xs:all>
<xs:element name="name" type="name_type" />
- <xs:element name="path" type="name_type" />
- <xs:element name="enabled" type="xs:boolean" default="false" />
- <xs:element name="snapshot_mode" type="uint32_type" />
- <xs:element name="live_timer_interval" type="uint32_type" />
+ <xs:element name="path" type="name_type" minOccurs="0" />
+ <xs:element name="enabled" type="xs:boolean" default="false" minOccurs="0" />
+ <xs:element name="snapshot_mode" type="uint32_type" minOccurs="0" />
+ <xs:element name="live_timer_interval" type="uint32_type" minOccurs="0" />
<xs:element name="channels" type="channels_type" minOccurs="0" />
<xs:element name="domains" type="domains_type" minOccurs="0" />
</xs:all>
</xs:all>
</xs:complexType>
+ <!-- map to the save command -->
+ <xs:complexType name="save_type">
+ <xs:all>
+ <xs:element name="session" type="session_type" />
+ <xs:element name="path" type="name_type"/>
+ </xs:all>
+ </xs:complexType>
+
+ <!-- map to the load command -->
+ <xs:complexType name="load_type">
+ <xs:all>
+ <xs:element name="session" type="session_type" />
+ <xs:element name="path" type="name_type"/>
+ </xs:all>
+ </xs:complexType>
<xs:complexType name="domains_type">
<xs:sequence>
<xs:element name="domains" type="domains_type" minOccurs="0" />
<xs:element name="sessions" type="sessions_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:choice>
</xs:complexType>
<xs:restriction base="xs:string">
<xs:enumeration value="list" />
<xs:enumeration value="version" />
+ <xs:enumeration value="save" />
+ <xs:enumeration value="load" />
</xs:restriction>
</xs:simpleType>
<xs:all>
<xs:element name="name" type="command_string_type" maxOccurs="1" />
<xs:element name="output" type="output_type" maxOccurs="1" />
+ <xs:element name="success" type="xs:boolean" minOccurs="0" maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>