Add auto start UST trace support
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 8 Nov 2011 17:07:07 +0000 (12:07 -0500)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 8 Nov 2011 17:07:07 +0000 (12:07 -0500)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng-sessiond/main.c
lttng-sessiond/trace-ust.c
lttng-sessiond/trace-ust.h
lttng-sessiond/ust-app.c

index f13571ab37159fc00d9aac331444eab9cb68db42..40ad9add84747538fe860662f95e5bf19f5a9a18 100644 (file)
@@ -1718,6 +1718,7 @@ static int create_ust_session(struct ltt_session *session,
                /* No ustctl for the global UST domain */
                break;
        default:
+               ERR("Unknown UST domain on create session %d", domain->type);
                goto error;
        }
        session->ust_session = lus;
@@ -2433,6 +2434,9 @@ static int cmd_start_trace(struct ltt_session *session)
                kernel_wait_quiescent(kernel_tracer_fd);
        }
 
+       /* Flag session that trace should start automatically */
+       usess->start_trace = 1;
+
        ret = ust_app_start_trace(usess);
        if (ret < 0) {
                ret = LTTCOMM_UST_START_FAIL;
index 3e1055a8ba8e990556ebd41b1a1f7748a6ff08d9..a1715f2532e793b7793c6fafb3c9ae062d978898 100644 (file)
@@ -92,13 +92,14 @@ struct ltt_ust_session *trace_ust_create_session(char *path, unsigned int uid,
        /* Allocate a new ltt ust session */
        lus = malloc(sizeof(struct ltt_ust_session));
        if (lus == NULL) {
-               perror("create ust session malloc");
+               PERROR("create ust session malloc");
                goto error;
        }
 
        /* Init data structure */
        lus->consumer_fds_sent = 0;
        lus->uid = uid;
+       lus->start_trace = 0;
 
        /* Alloc UST domain hash tables */
        lus->domain_pid = hashtable_new(0);
index 604024b18b00f7e56c4da266ef9ea518096c4307..f2ec7405f83fe4ca4e35b418fba0724f2b02bf20 100644 (file)
@@ -100,6 +100,7 @@ struct ltt_ust_session {
        int uid;   /* Unique identifier of session */
        int consumer_fds_sent;
        int consumer_fd;
+       int start_trace;
        char pathname[PATH_MAX];
        struct ltt_ust_domain_global domain_global;
        /*
index 21481b0f7e230ee7ecd454050a14a8d60679bfa7..7eb454a5e53222888e679a70a08f936f61deeacc 100644 (file)
@@ -843,6 +843,7 @@ void ust_app_global_update(struct ltt_ust_session *usess, int sock)
        struct lttng_ust_event ltt_uevent;
        struct ltt_ust_channel *uchan;
        struct lttng_ust_object_data *obj_event;
+       struct lttng_ust_channel_attr uattr;
 
        DBG2("UST app global update for app sock %d for session uid %d", sock,
                        usess->uid);
@@ -957,11 +958,111 @@ next_event:
                        hashtable_get_next(ua_chan->events, &iter);
                }
 
+               for (;;) {
+                       struct lttng_ust_object_data *obj;
+                       struct ltt_ust_stream *ustream;
+
+                       ret = ustctl_create_stream(app->key.sock, ua_chan->obj, &obj);
+                       if (ret < 0) {
+                               /* Got all streams */
+                               break;
+                       }
+
+                       ustream = zmalloc(sizeof(*ustream));
+                       if (ustream == NULL) {
+                               PERROR("zmalloc ust stream");
+                               goto error;
+                       }
+
+                       ustream->obj = obj;
+                       ustream->handle = ustream->obj->handle;
+                       /* Order is important */
+                       cds_list_add_tail(&ustream->list, &ua_chan->streams.head);
+
+                       ret = snprintf(ustream->pathname, PATH_MAX, "%s/%s_%u",
+                                       uchan->pathname, uchan->name, ua_chan->streams.count++);
+                       if (ret < 0) {
+                               PERROR("asprintf UST create stream");
+                               goto error;
+                       }
+               }
+
 next_chan:
                /* Next applications */
                hashtable_get_next(ua_sess->channels, &iter);
        }
 
+       if (ua_sess->metadata == NULL) {
+               /* Allocate UST metadata */
+               ua_sess->metadata = trace_ust_create_metadata(usess->pathname);
+               if (ua_sess->metadata == NULL) {
+                       ERR("UST app session %d creating metadata failed",
+                                       ua_sess->handle);
+                       goto error;
+               }
+
+               uattr.overwrite = ua_sess->metadata->attr.overwrite;
+               uattr.subbuf_size = ua_sess->metadata->attr.subbuf_size;
+               uattr.num_subbuf = ua_sess->metadata->attr.num_subbuf;
+               uattr.switch_timer_interval =
+                       ua_sess->metadata->attr.switch_timer_interval;
+               uattr.read_timer_interval =
+                       ua_sess->metadata->attr.read_timer_interval;
+               uattr.output = ua_sess->metadata->attr.output;
+
+               /* UST tracer metadata creation */
+               ret = ustctl_open_metadata(app->key.sock, ua_sess->handle, &uattr,
+                               &ua_sess->metadata->obj);
+               if (ret < 0) {
+                       ERR("UST app open metadata failed for app pid:%d",
+                                       app->key.pid);
+                       goto error;
+               }
+
+               DBG2("UST metadata opened for app pid %d", app->key.pid);
+       }
+
+       /* Open UST metadata stream */
+       if (ua_sess->metadata->stream_obj == NULL) {
+               ret = ustctl_create_stream(app->key.sock, ua_sess->metadata->obj,
+                               &ua_sess->metadata->stream_obj);
+               if (ret < 0) {
+                       ERR("UST create metadata stream failed");
+                       goto error;
+               }
+
+               ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, "%s/%s",
+                               usess->pathname, "metadata");
+               if (ret < 0) {
+                       PERROR("asprintf UST create stream");
+                       goto error;
+               }
+
+               DBG2("UST metadata stream object created for app pid %d",
+                               app->key.pid);
+       }
+
+       if (usess->start_trace) {
+               /* Setup UST consumer socket and send fds to it */
+               ret = ust_consumer_send_session(usess->consumer_fd, ua_sess);
+               if (ret < 0) {
+                       ERR("UST consumer send session failed");
+                       goto error;
+               }
+
+               /* This start the UST tracing */
+               ret = ustctl_start_session(app->key.sock, ua_sess->handle);
+               if (ret < 0) {
+                       ERR("Error starting tracing for app pid: %d", app->key.pid);
+                       goto error;
+               }
+
+               /* Quiescent wait after starting trace */
+               ustctl_wait_quiescent(app->key.sock);
+
+               DBG2("UST trace started for app pid %d", app->key.pid);
+       }
+
 error:
        rcu_read_unlock();
        return;
This page took 0.03259 seconds and 4 git commands to generate.