+static
+int print_metadata_session_information(struct ust_registry_session *registry)
+{
+ int ret;
+ struct ltt_session *session = NULL;
+ char creation_datetime[ISO8601_STR_LEN];
+
+ rcu_read_lock();
+ session = session_find_by_id(registry->tracing_id);
+ if (!session) {
+ ret = -1;
+ goto error;
+ }
+
+ /* Print the trace name */
+ ret = lttng_metadata_printf(registry, " trace_name = \"");
+ if (ret) {
+ goto error;
+ }
+
+ /*
+ * This is necessary since the creation time is present in the session
+ * name when it is generated.
+ */
+ if (session->has_auto_generated_name) {
+ ret = print_escaped_ctf_string(registry, DEFAULT_SESSION_NAME);
+ } else {
+ ret = print_escaped_ctf_string(registry, session->name);
+ }
+ if (ret) {
+ goto error;
+ }
+
+ ret = lttng_metadata_printf(registry, "\";\n");
+ if (ret) {
+ goto error;
+ }
+
+ /* Prepare creation time */
+ ret = time_to_iso8601_str(session->creation_time, creation_datetime,
+ sizeof(creation_datetime));
+ if (ret) {
+ goto error;
+ }
+
+ /* Output the reste of the information */
+ ret = lttng_metadata_printf(registry,
+ " trace_creation_datetime = \"%s\";\n"
+ " hostname = \"%s\";\n",
+ creation_datetime, session->hostname);
+ if (ret) {
+ goto error;
+ }
+
+error:
+ if (session) {
+ session_put(session);
+ }
+ rcu_read_unlock();
+ return ret;
+}
+
+static
+int print_metadata_app_information(struct ust_registry_session *registry,
+ struct ust_app *app)
+{
+ int ret;
+ char datetime[ISO8601_STR_LEN];
+
+ if (!app) {
+ ret = 0;
+ goto end;
+ }
+
+ ret = time_to_iso8601_str(
+ app->registration_time, datetime, sizeof(datetime));
+ if (ret) {
+ goto end;
+ }
+
+ ret = lttng_metadata_printf(registry,
+ " tracer_patchlevel = %u;\n"
+ " vpid = %d;\n"
+ " procname = \"%s\";\n"
+ " vpid_datetime = \"%s\";\n",
+ app->version.patchlevel, (int) app->pid, app->name,
+ datetime);
+
+end:
+ return ret;
+}
+