From 14ce5bd8eefa248c5abedc32b02394ef74307e81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 6 Oct 2014 19:44:21 -0400 Subject: [PATCH] Fix: save UST context informations as a event_perf_context_type MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This fixes UST perf counters not being recognized by the session restore code at the linting stage. Reported-by: Philipe Proulx Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/save.c | 72 ++++++++++++++++++++++++++++------- src/common/config/config.c | 4 +- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index d3fb7b8f3..d268f3319 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -260,8 +260,10 @@ const char *get_ust_context_type_string( context_type_string = config_event_context_pthread_id; break; case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: - context_type_string = config_event_context_perf_thread_counter; - break; + /* + * Error, should not be stored in the XML, perf contexts + * are stored as a node of type event_perf_context_type. + */ default: context_type_string = NULL; break; @@ -841,12 +843,6 @@ int save_ust_context(struct config_writer *writer, cds_list_for_each_entry(ctx, ctx_list, list) { const char *context_type_string; - 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_open_element(writer, config_element_context); @@ -855,11 +851,61 @@ int save_ust_context(struct config_writer *writer, 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; + 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; + } } /* /context */ diff --git a/src/common/config/config.c b/src/common/config/config.c index 4a07e9947..e44710b5a 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -1960,7 +1960,9 @@ int process_context_node(xmlNodePtr context_node, xmlNodePtr perf_attr_node; /* perf */ - context.ctx = LTTNG_EVENT_CONTEXT_PERF_COUNTER; + context.ctx = handle->domain.type == LTTNG_DOMAIN_KERNEL ? + LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER : + LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER; for (perf_attr_node = xmlFirstElementChild(context_child_node); perf_attr_node; perf_attr_node = xmlNextElementSibling(perf_attr_node)) { -- 2.34.1