-static
-int set_trace_name(struct ctx *ctx)
-{
- GString *name;
- int ret = 0;
- struct bt_value *value = NULL;
-
- assert(bt_trace_get_stream_class_count(ctx->trace) == 0);
- name = g_string_new(NULL);
- if (!name) {
- BT_LOGE_STR("Failed to allocate a GString.");
- ret = -1;
- goto end;
- }
-
- /*
- * Check if we have a trace environment string value named `hostname`.
- * If so, use it as the trace name's prefix.
- */
- value = bt_trace_get_environment_field_value_by_name(ctx->trace,
- "hostname");
- if (bt_value_is_string(value)) {
- const char *hostname;
-
- ret = bt_value_string_get(value, &hostname);
- assert(ret == 0);
- g_string_append(name, hostname);
-
- if (ctx->trace_name_suffix) {
- g_string_append_c(name, G_DIR_SEPARATOR);
- }
- }
-
- if (ctx->trace_name_suffix) {
- g_string_append(name, ctx->trace_name_suffix);
- }
-
- ret = bt_trace_set_name(ctx->trace, name->str);
- if (ret) {
- BT_LOGE("Cannot set trace's name: name=\"%s\"", name->str);
- goto error;
- }
-
- goto end;
-
-error:
- ret = -1;
-
-end:
- bt_put(value);
-
- if (name) {
- g_string_free(name, TRUE);
- }
-
- return ret;
-}
-
-static
-int move_ctx_stream_classes_to_trace(struct ctx *ctx)
-{
- int ret = 0;
- GHashTableIter iter;
- gpointer key, stream_class;
-
- if (g_hash_table_size(ctx->stream_classes) > 0 &&
- bt_trace_get_stream_class_count(ctx->trace) == 0) {
- /*
- * We're about to add the first stream class to the
- * trace. This will freeze the trace, and after this
- * we cannot set the name anymore. At this point,
- * set the trace name.
- */
- ret = set_trace_name(ctx);
- if (ret) {
- BT_LOGE_STR("Cannot set trace's name.");
- goto end;
- }
- }
-
- g_hash_table_iter_init(&iter, ctx->stream_classes);
-
- while (g_hash_table_iter_next(&iter, &key, &stream_class)) {
- ret = bt_trace_add_stream_class(ctx->trace,
- stream_class);
- if (ret) {
- int64_t id = bt_stream_class_get_id(stream_class);
- BT_LOGE("Cannot add stream class to trace: id=%" PRId64,
- id);
- goto end;
- }
- }
-
- g_hash_table_remove_all(ctx->stream_classes);
-
-end:
- return ret;
-}
-