From: Jonathan Rajotte Julien Date: Wed, 18 Jun 2014 18:28:04 +0000 (-0400) Subject: Mi calibrate command: support and validation X-Git-Tag: v2.6.0-rc1~123 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7e66b1b0255bbe6b5a55a83d3ff182ba3d4300ee;p=lttng-tools.git Mi calibrate command: support and validation Signed-off-by: Jonathan Rajotte Julien --- diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index 7d4de2909..567f4a5fa 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -26,6 +26,9 @@ #include #include #include +#include + +#include #include "../command.h" @@ -51,6 +54,7 @@ enum { }; static struct lttng_handle *handle; +static struct mi_writer *writer; static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ @@ -133,13 +137,6 @@ static int calibrate_lttng(void) 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; @@ -174,7 +171,14 @@ static int calibrate_lttng(void) 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); @@ -189,7 +193,7 @@ error: */ 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); @@ -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: + /* 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; } diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 15deeb21a..2fb1c1905 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -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_calibrate = "calibrate"; 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"; +/* 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) @@ -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) { @@ -969,3 +989,28 @@ close: 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; +} diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index 0f263fc5a..1c2a653a4 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -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_calibrate; 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; +/* 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. @@ -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); +/* + * 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 */ diff --git a/src/common/mi_lttng.xsd b/src/common/mi_lttng.xsd index 76e9a152e..884830d1c 100644 --- a/src/common/mi_lttng.xsd +++ b/src/common/mi_lttng.xsd @@ -106,6 +106,13 @@ THE SOFTWARE. + + + + + + + @@ -217,7 +224,7 @@ THE SOFTWARE. - + @@ -291,6 +298,13 @@ THE SOFTWARE. + + + + + + + @@ -317,6 +331,7 @@ THE SOFTWARE. + @@ -331,6 +346,7 @@ THE SOFTWARE. +