Introduce application contexts to session configuration schema
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 9 Feb 2016 20:12:33 +0000 (15:12 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 12 Feb 2016 22:54:03 +0000 (17:54 -0500)
Session configuration schema version is bumped to 2.8.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/save.c
src/common/config/config-session-abi.h
src/common/config/session-config.c
src/common/config/session.xsd

index a6fea46ce55e5e9d3dcca669bf4bd1d8839ce1f4..b33287855e373ef0b9f253d02eb78294ccaab3e7 100644 (file)
@@ -261,6 +261,9 @@ const char *get_ust_context_type_string(
        case LTTNG_UST_CONTEXT_PTHREAD_ID:
                context_type_string = config_event_context_pthread_id;
                break;
        case LTTNG_UST_CONTEXT_PTHREAD_ID:
                context_type_string = config_event_context_pthread_id;
                break;
+       case LTTNG_UST_CONTEXT_APP_CONTEXT:
+               context_type_string = config_event_context_app;
+               break;
        case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
                /*
                 * Error, should not be stored in the XML, perf contexts
        case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
                /*
                 * Error, should not be stored in the XML, perf contexts
@@ -845,7 +848,8 @@ int save_kernel_context(struct config_writer *writer,
        }
 
        if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
        }
 
        if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
-               ret = config_writer_open_element(writer, config_element_perf);
+               ret = config_writer_open_element(writer,
+                               config_element_context_perf);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
@@ -942,6 +946,124 @@ end:
        return ret;
 }
 
        return ret;
 }
 
+static
+int save_ust_context_perf_thread_counter(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Perf contexts are saved as event_perf_context_type */
+       ret = config_writer_open_element(writer, config_element_context_perf);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_unsigned_int(writer,
+                       config_element_type, ctx->ctx.u.perf_counter.type);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_unsigned_int(writer,
+                       config_element_config, ctx->ctx.u.perf_counter.config);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer, config_element_name,
+                       ctx->ctx.u.perf_counter.name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       /* /perf */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static
+int save_ust_context_app_ctx(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Application contexts are saved as application_context_type */
+       ret = config_writer_open_element(writer, config_element_context_app);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_context_app_provider_name,
+                       ctx->ctx.u.app_ctx.provider_name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_context_app_ctx_name,
+                       ctx->ctx.u.app_ctx.ctx_name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       /* /app */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static
+int save_ust_context_generic(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+       const char *context_type_string;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Save context as event_context_type_type */
+       context_type_string = get_ust_context_type_string(
+                       ctx->ctx.ctx);
+       if (!context_type_string) {
+               ERR("Unsupported UST context type.");
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_type, context_type_string);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
 static
 int save_ust_context(struct config_writer *writer,
        struct cds_list_head *ctx_list)
 static
 int save_ust_context(struct config_writer *writer,
        struct cds_list_head *ctx_list)
@@ -959,9 +1081,6 @@ int save_ust_context(struct config_writer *writer,
        }
 
        cds_list_for_each_entry(ctx, ctx_list, list) {
        }
 
        cds_list_for_each_entry(ctx, ctx_list, list) {
-               const char *context_type_string;
-
-
                ret = config_writer_open_element(writer,
                        config_element_context);
                if (ret) {
                ret = config_writer_open_element(writer,
                        config_element_context);
                if (ret) {
@@ -969,61 +1088,19 @@ int save_ust_context(struct config_writer *writer,
                        goto end;
                }
 
                        goto end;
                }
 
-               if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) {
-                       /* Perf contexts are saved as event_perf_context_type */
-                       ret = config_writer_open_element(writer,
-                               config_element_perf);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_unsigned_int(writer,
-                               config_element_type,
-                               ctx->ctx.u.perf_counter.type);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_unsigned_int(writer,
-                               config_element_config,
-                               ctx->ctx.u.perf_counter.config);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_string(writer,
-                               config_element_name,
-                               ctx->ctx.u.perf_counter.name);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       /* /perf */
-                       ret = config_writer_close_element(writer);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-               } else {
-                       /* Save context as event_context_type_type */
-                       context_type_string = get_ust_context_type_string(
-                               ctx->ctx.ctx);
-                       if (!context_type_string) {
-                               ERR("Unsupported UST context type.")
-                                       ret = LTTNG_ERR_INVALID;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_string(writer,
-                               config_element_type, context_type_string);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
+               switch (ctx->ctx.ctx) {
+               case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
+                       ret = save_ust_context_perf_thread_counter(writer, ctx);
+                       break;
+               case LTTNG_UST_CONTEXT_APP_CONTEXT:
+                       ret = save_ust_context_app_ctx(writer, ctx);
+                       break;
+               default:
+                       /* Save generic context. */
+                       ret = save_ust_context_generic(writer, ctx);
+               }
+               if (ret) {
+                       goto end;
                }
 
                /* /context */
                }
 
                /* /context */
index 9251b22fc02bdfb942d4686249b84ab2699a9017..23f8c84165acc78edc3b4d96b3fe9e13cb5fc61d 100644 (file)
@@ -50,7 +50,10 @@ extern const char * const config_element_type;
 extern const char * const config_element_buffer_type;
 extern const char * const config_element_session;
 extern const char * const config_element_sessions;
 extern const char * const config_element_buffer_type;
 extern const char * const config_element_session;
 extern const char * const config_element_sessions;
-extern const char * const config_element_perf;
+extern const char * const config_element_context_perf;
+extern const char * const config_element_context_app;
+extern const char * const config_element_context_app_provider_name;
+extern const char * const config_element_context_app_ctx_name;
 extern const char * const config_element_config;
 extern const char * const config_element_started;
 extern const char * const config_element_snapshot_mode;
 extern const char * const config_element_config;
 extern const char * const config_element_started;
 extern const char * const config_element_snapshot_mode;
@@ -116,5 +119,6 @@ extern const char * const config_event_context_pthread_id;
 extern const char * const config_event_context_hostname;
 extern const char * const config_event_context_ip;
 extern const char * const config_event_context_perf_thread_counter;
 extern const char * const config_event_context_hostname;
 extern const char * const config_event_context_ip;
 extern const char * const config_event_context_perf_thread_counter;
+extern const char * const config_event_context_app;
 
 #endif /* CONFIG_SESSION_INTERNAL_H */
 
 #endif /* CONFIG_SESSION_INTERNAL_H */
index 87e9c03c8f667a65efee86dead199f77d7ee8884..ba938d9f1578863b9253c28d61bbe7bd29b4ff08 100644 (file)
@@ -99,7 +99,10 @@ const char * const config_element_type = "type";
 const char * const config_element_buffer_type = "buffer_type";
 const char * const config_element_session = "session";
 const char * const config_element_sessions = "sessions";
 const char * const config_element_buffer_type = "buffer_type";
 const char * const config_element_session = "session";
 const char * const config_element_sessions = "sessions";
-const char * const config_element_perf = "perf";
+const char * const config_element_context_perf = "perf";
+const char * const config_element_context_app = "app";
+const char * const config_element_context_app_provider_name = "provider_name";
+const char * const config_element_context_app_ctx_name = "ctx_name";
 const char * const config_element_config = "config";
 const char * const config_element_started = "started";
 const char * const config_element_snapshot_mode = "snapshot_mode";
 const char * const config_element_config = "config";
 const char * const config_element_started = "started";
 const char * const config_element_snapshot_mode = "snapshot_mode";
@@ -165,6 +168,8 @@ const char * const config_event_context_pthread_id = "PTHREAD_ID";
 const char * const config_event_context_hostname = "HOSTNAME";
 const char * const config_event_context_ip = "IP";
 const char * const config_event_context_perf_thread_counter = "PERF_THREAD_COUNTER";
 const char * const config_event_context_hostname = "HOSTNAME";
 const char * const config_event_context_ip = "IP";
 const char * const config_event_context_perf_thread_counter = "PERF_THREAD_COUNTER";
+const char * const config_event_context_app = "APP";
+
 
 struct consumer_output {
        int enabled;
 
 struct consumer_output {
        int enabled;
@@ -1991,6 +1996,7 @@ int process_context_node(xmlNodePtr context_node,
                config_element_type)) {
                /* type */
                xmlChar *content = xmlNodeGetContent(context_child_node);
                config_element_type)) {
                /* type */
                xmlChar *content = xmlNodeGetContent(context_child_node);
+
                if (!content) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
                if (!content) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
@@ -2004,10 +2010,11 @@ int process_context_node(xmlNodePtr context_node,
                }
 
                context.ctx = ret;
                }
 
                context.ctx = ret;
-       } else {
+       } else if (!strcmp((const char *) context_child_node->name,
+               config_element_context_perf)) {
+               /* perf */
                xmlNodePtr perf_attr_node;
 
                xmlNodePtr perf_attr_node;
 
-               /* perf */
                context.ctx = handle->domain.type == LTTNG_DOMAIN_KERNEL ?
                        LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER :
                        LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER;
                context.ctx = handle->domain.type == LTTNG_DOMAIN_KERNEL ?
                        LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER :
                        LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER;
@@ -2085,9 +2092,41 @@ int process_context_node(xmlNodePtr context_node,
                                free(content);
                        }
                }
                                free(content);
                        }
                }
+       } else if (!strcmp((const char *) context_child_node->name,
+               config_element_context_app)) {
+               /* application context */
+               xmlNodePtr app_ctx_node;
+
+               context.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT;
+               for (app_ctx_node = xmlFirstElementChild(context_child_node);
+                               app_ctx_node; app_ctx_node =
+                               xmlNextElementSibling(app_ctx_node)) {
+                       xmlChar *content;
+                       char **target = strcmp(
+                               (const char *) app_ctx_node->name,
+                               config_element_context_app_provider_name) == 0 ?
+                                       &context.u.app_ctx.provider_name :
+                                       &context.u.app_ctx.ctx_name;
+
+                       content = xmlNodeGetContent(app_ctx_node);
+                       if (!content) {
+                               ret = -LTTNG_ERR_NOMEM;
+                               goto end;
+                       }
+
+                       *target = (char *) content;
+               }
+       } else {
+               /* Unrecognized context type */
+               ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
+               goto end;
        }
 
        ret = lttng_add_context(handle, &context, NULL, channel_name);
        }
 
        ret = lttng_add_context(handle, &context, NULL, channel_name);
+       if (context.ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+               free(context.u.app_ctx.provider_name);
+               free(context.u.app_ctx.ctx_name);
+       }
 end:
        return ret;
 }
 end:
        return ret;
 }
index 49b7cd112e82c902fa663e7697145b06d7792528..550fea0ee2376d427860d0b1a6744aad003558dc 100644 (file)
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -->
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 THE SOFTWARE.
 -->
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-elementFormDefault="qualified" version="2.7">
+elementFormDefault="qualified" version="2.8">
 
 <xs:simpleType name="name_type">
        <xs:restriction base="xs:string">
 
 <xs:simpleType name="name_type">
        <xs:restriction base="xs:string">
@@ -136,6 +136,13 @@ elementFormDefault="qualified" version="2.7">
        </xs:all>
 </xs:complexType>
 
        </xs:all>
 </xs:complexType>
 
+<xs:complexType name="event_app_context_type">
+       <xs:all>
+         <xs:element name="provider_name" type="xs:string"/>
+         <xs:element name="ctx_name" type="xs:string"/>
+       </xs:all>
+</xs:complexType>
+
 <!-- Maps to the lttng_event_context_type enum -->
 <xs:simpleType name="event_context_type_type">
        <xs:restriction base="xs:string">
 <!-- Maps to the lttng_event_context_type enum -->
 <xs:simpleType name="event_context_type_type">
        <xs:restriction base="xs:string">
@@ -151,6 +158,7 @@ elementFormDefault="qualified" version="2.7">
                <xs:enumeration value="PTHREAD_ID"/>
                <xs:enumeration value="HOSTNAME"/>
                <xs:enumeration value="IP"/>
                <xs:enumeration value="PTHREAD_ID"/>
                <xs:enumeration value="HOSTNAME"/>
                <xs:enumeration value="IP"/>
+               <xs:enumeration value="APP"/>
        </xs:restriction>
 </xs:simpleType>
 
        </xs:restriction>
 </xs:simpleType>
 
@@ -158,6 +166,7 @@ elementFormDefault="qualified" version="2.7">
        <xs:choice>
                <xs:element name="type" type="event_context_type_type"/>
                <xs:element name="perf" type="event_perf_context_type"/>
        <xs:choice>
                <xs:element name="type" type="event_context_type_type"/>
                <xs:element name="perf" type="event_perf_context_type"/>
+               <xs:element name="app" type="event_app_context_type"/>
        </xs:choice>
 </xs:complexType>
 
        </xs:choice>
 </xs:complexType>
 
This page took 0.031029 seconds and 4 git commands to generate.