+ 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);
+ }
+