Fix: Only save kernel enablers in session configuration
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index a6fea46ce55e5e9d3dcca669bf4bd1d8839ce1f4..1a98515fa0c73f0272c82b346aa102ff5f5117f8 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_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
@@ -499,57 +502,6 @@ end:
        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)
@@ -570,12 +522,6 @@ int save_kernel_events(struct config_writer *writer,
                }
        }
 
-       /* Save syscalls if any. */
-       ret = save_kernel_syscall(writer, kchan);
-       if (ret) {
-               goto end;
-       }
-
        /* /events */
        ret = config_writer_close_element(writer);
        if (ret) {
@@ -845,7 +791,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 +889,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 +1024,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 +1031,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 */
This page took 0.026392 seconds and 4 git commands to generate.