X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fmi-lttng.c;h=f77b6b648c30b541817c237cf0cfdb59f2f2afb0;hb=8d40c39b9aee3c018f41c4e5e8407911384b3ee5;hp=e2181f692d65c9beebe4890b256123c27b6336ef;hpb=b789735ec96305f2e14fc9b9c75406ca215ddabb;p=lttng-tools.git diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index e2181f692..f77b6b648 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2014 - Jonathan Rajotte * - Olivier Cotte + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -16,15 +17,31 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE -#include -#include +#include #include #include "mi-lttng.h" #include +#define MI_SCHEMA_MAJOR_VERSION 3 +#define MI_SCHEMA_MINOR_VERSION 0 + +/* Machine interface namespace URI */ +const char * const mi_lttng_xmlns = "xmlns"; +const char * const mi_lttng_ns_uri = "http://lttng.org/xml/ns/lttng-mi"; +const char * const mi_lttng_xmlns_xsi = "xmlns:xsi"; +const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance"; +const char * const mi_lttng_schema_location = "xsi:schemaLocation"; +const char * const mi_lttng_schema_location_uri = + "http://lttng.org/xml/ns/lttng-mi" " " + "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION) + "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "." + XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd"; +const char * const mi_lttng_schema_version = "schemaVersion"; +const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION) + "." XSTR(MI_SCHEMA_MINOR_VERSION); + /* Strings related to command */ const char * const mi_lttng_element_command = "command"; const char * const mi_lttng_element_command_action = "snapshot_action"; @@ -78,8 +95,7 @@ const char * const mi_lttng_context_type_perf_thread_counter = "PERF_THREAD_COUN const char * const mi_lttng_element_perf_counter_context = "perf_counter_context"; /* Strings related to pid */ -const char * const mi_lttng_element_processes = "processes"; -const char * const mi_lttng_element_process = "process"; +const char * const mi_lttng_element_pid_id = "id"; /* Strings related to save command */ const char * const mi_lttng_element_save = "save"; @@ -400,6 +416,7 @@ const char *mi_lttng_domaintype_string(enum lttng_domain_type value) default: /* Should not have an unknown domain */ assert(0); + return NULL; } } @@ -416,6 +433,7 @@ const char *mi_lttng_buffertype_string(enum lttng_buffer_type value) default: /* Should not have an unknow buffer type */ assert(0); + return NULL; } } @@ -488,10 +506,42 @@ int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command) { int ret; - ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command); + /* + * A command is always the MI's root node, it must declare the current + * namespace and schema URIs and the schema's version. + */ + ret = config_writer_open_element(writer->writer, + mi_lttng_element_command); + if (ret) { + goto end; + } + + ret = config_writer_write_attribute(writer->writer, + mi_lttng_xmlns, mi_lttng_ns_uri); + if (ret) { + goto end; + } + + ret = config_writer_write_attribute(writer->writer, + mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri); + if (ret) { + goto end; + } + + ret = config_writer_write_attribute(writer->writer, + mi_lttng_schema_location, + mi_lttng_schema_location_uri); + if (ret) { + goto end; + } + + ret = config_writer_write_attribute(writer->writer, + mi_lttng_schema_version, + mi_lttng_schema_version_value); if (ret) { goto end; } + ret = mi_lttng_writer_write_element_string(writer, mi_lttng_element_command_name, command); end: @@ -923,6 +973,7 @@ int mi_lttng_event_common_attributes(struct mi_writer *writer, struct lttng_event *event) { int ret; + const char *filter_expression; /* Open event element */ ret = mi_lttng_writer_open_element(writer, config_element_event); @@ -951,9 +1002,20 @@ int mi_lttng_event_common_attributes(struct mi_writer *writer, goto end; } - /* Event filter enabled? */ - ret = mi_lttng_writer_write_element_bool(writer, - config_element_filter, event->filter); + /* Event filter expression */ + ret = lttng_event_get_filter_string(event, &filter_expression); + if (ret) { + goto end; + } + + if (filter_expression) { + ret = mi_lttng_writer_write_element_string(writer, + config_element_filter_expression, + filter_expression); + if (ret) { + goto end; + } + } end: return ret; @@ -1153,27 +1215,25 @@ int mi_lttng_pids_open(struct mi_writer *writer) return mi_lttng_writer_open_element(writer, config_element_pids); } +/* + * TODO: move the listing of pid for user agent to process semantic on + * mi api bump. The use of process element break the mi api. + */ LTTNG_HIDDEN -int mi_lttng_processes_open(struct mi_writer *writer) -{ - return mi_lttng_writer_open_element(writer, mi_lttng_element_processes); -} - -LTTNG_HIDDEN -int mi_lttng_process(struct mi_writer *writer, pid_t pid , const char *name, +int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *name, int is_open) { int ret; - /* Open element process */ - ret = mi_lttng_writer_open_element(writer, mi_lttng_element_process); + /* Open pid process */ + ret = mi_lttng_writer_open_element(writer, config_element_pid); if (ret) { goto end; } /* Writing pid number */ ret = mi_lttng_writer_write_element_signed_int(writer, - config_element_pid, (int)pid); + mi_lttng_element_pid_id, (int)pid); if (ret) { goto end; }