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
return ret;
}
-static
-int save_kernel_syscall(struct config_writer *writer,
- struct ltt_kernel_channel *kchan)
-{
- int ret, i;
- ssize_t count;
- struct lttng_event *events = NULL;
-
- assert(writer);
- assert(kchan);
-
- count = syscall_list_channel(kchan, &events, 0);
- if (!count) {
- /* No syscalls, just gracefully return. */
- ret = 0;
- goto end;
- }
-
- for (i = 0; i < count; i++) {
- struct ltt_kernel_event *kevent;
-
- /* Create a temporary kevent in order to save it. */
- /*
- * TODO: struct lttng_event does not really work for a filter,
- * but unfortunately, it is exposed as external API (and used as
- * internal representation. Using NULL meanwhile.
- */
- kevent = trace_kernel_create_event(&events[i],
- NULL, NULL);
- if (!kevent) {
- ret = -ENOMEM;
- goto end;
- }
- /* Init list in order so the destroy call can del the node. */
- CDS_INIT_LIST_HEAD(&kevent->list);
-
- ret = save_kernel_event(writer, kevent);
- trace_kernel_destroy_event(kevent);
- if (ret) {
- goto end;
- }
- }
-
- /* Everything went well */
- ret = 0;
-
-end:
- free(events);
- return ret;
-}
-
static
int save_kernel_events(struct config_writer *writer,
struct ltt_kernel_channel *kchan)
}
}
- /* Save syscalls if any. */
- ret = save_kernel_syscall(writer, kchan);
- if (ret) {
- goto end;
- }
-
/* /events */
ret = config_writer_close_element(writer);
if (ret) {
}
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 */