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
}
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;
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)
}
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) {
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 */
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_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;
config_element_type)) {
/* type */
xmlChar *content = xmlNodeGetContent(context_child_node);
+
if (!content) {
ret = -LTTNG_ERR_NOMEM;
goto end;
}
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;
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;
}