Implement PID tracking for kernel tracing
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index d3fb7b8f3f1dd8816a11a3d914488dfc8cbcb7e5..6cb220c2f28d1e56bffeef8dbf49a68d4cd6d516 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <inttypes.h>
 #include <string.h>
@@ -260,8 +261,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;
@@ -713,6 +716,8 @@ end:
        return ret;
 }
 
+/* TODO: save/restore tracker pid */
+
 static
 int save_kernel_context(struct config_writer *writer,
        struct lttng_kernel_context *ctx)
@@ -799,6 +804,11 @@ int save_kernel_contexts(struct config_writer *writer,
        int ret;
        struct ltt_kernel_context *ctx;
 
+       if (cds_list_empty(&kchan->ctx_list)) {
+               ret = 0;
+               goto end;
+       }
+
        ret = config_writer_open_element(writer, config_element_contexts);
        if (ret) {
                ret = LTTNG_ERR_SAVE_IO_FAIL;
@@ -841,12 +851,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 +859,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 */
@@ -1110,7 +1164,8 @@ int save_ust_session(struct config_writer *writer,
 
                ust_chan = caa_container_of(node, struct ltt_ust_channel, node);
                agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) ||
-                       !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name);
+                       !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name) ||
+                       !strcmp(DEFAULT_PYTHON_CHANNEL_NAME, ust_chan->name);
                if (!(save_agent ^ agent_channel)) {
                        ret = save_ust_channel(writer, ust_chan, session->ust_session);
                        if (ret) {
@@ -1172,6 +1227,8 @@ int save_domains(struct config_writer *writer, struct ltt_session *session)
        }
 
        if (session->ust_session) {
+               unsigned long agent_count;
+
                ret = config_writer_open_element(writer,
                        config_element_domain);
                if (ret) {
@@ -1190,30 +1247,37 @@ int save_domains(struct config_writer *writer, struct ltt_session *session)
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
-       }
 
-       if (session->ust_session &&
-                       lttng_ht_get_count(session->ust_session->agents) > 0) {
-               ret = config_writer_open_element(writer,
-                       config_element_domain);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end;
-               }
+               rcu_read_lock();
+               agent_count =
+                       lttng_ht_get_count(session->ust_session->agents);
+               rcu_read_unlock();
 
-               ret = save_ust_session(writer, session, 1);
-               if (ret) {
-                       goto end;
-               }
+               if (agent_count > 0) {
+                       ret = config_writer_open_element(writer,
+                               config_element_domain);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
 
-               /* /domain */
-               ret = config_writer_close_element(writer);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end;
+                       ret = save_ust_session(writer, session, 1);
+                       if (ret) {
+                               goto end;
+                       }
+
+                       /* /domain */
+                       ret = config_writer_close_element(writer);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
                }
        }
 
+       if (session->ust_session) {
+       }
+
        /* /domains */
        ret = config_writer_close_element(writer);
        if (ret) {
This page took 0.024845 seconds and 4 git commands to generate.