From: Jérémie Galarneau Date: Tue, 9 Feb 2016 20:12:33 +0000 (-0500) Subject: Introduce application contexts to session configuration schema X-Git-Tag: v2.8.0-rc1~170 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=045fc61744f711fd2e4ca84c6339d97f1eafc71d;p=lttng-tools.git Introduce application contexts to session configuration schema Session configuration schema version is bumped to 2.8. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index a6fea46ce..b33287855 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -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_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 @@ -845,7 +848,8 @@ int save_kernel_context(struct config_writer *writer, } 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; @@ -942,6 +946,124 @@ end: 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) @@ -959,9 +1081,6 @@ int save_ust_context(struct config_writer *writer, } 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) { @@ -969,61 +1088,19 @@ int save_ust_context(struct config_writer *writer, 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 */ diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index 9251b22fc..23f8c8416 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -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_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; @@ -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_app; #endif /* CONFIG_SESSION_INTERNAL_H */ diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 87e9c03c8..ba938d9f1 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -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_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"; @@ -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_app = "APP"; + 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); + if (!content) { ret = -LTTNG_ERR_NOMEM; goto end; @@ -2004,10 +2010,11 @@ int process_context_node(xmlNodePtr context_node, } context.ctx = ret; - } else { + } else if (!strcmp((const char *) context_child_node->name, + config_element_context_perf)) { + /* perf */ 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; @@ -2085,9 +2092,41 @@ int process_context_node(xmlNodePtr context_node, 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); + 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; } diff --git a/src/common/config/session.xsd b/src/common/config/session.xsd index 49b7cd112..550fea0ee 100644 --- a/src/common/config/session.xsd +++ b/src/common/config/session.xsd @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> +elementFormDefault="qualified" version="2.8"> @@ -136,6 +136,13 @@ elementFormDefault="qualified" version="2.7"> + + + + + + + @@ -151,6 +158,7 @@ elementFormDefault="qualified" version="2.7"> + @@ -158,6 +166,7 @@ elementFormDefault="qualified" version="2.7"> +