lib: move trace class's name, UUID, and environment props to trace API
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-data-copy.c
index 39cb9fb7bbf6a9f54e8abb6617ef7b81aef14750..60c52e5d78bbb8dcf59f1bc7c913f24f87182190 100644 (file)
@@ -41,6 +41,7 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
 {
        bt_trace_set_name_status status;
        const char *trace_name;
+       uint64_t i, env_field_count;
 
        BT_COMP_LOGD("Copying content of trace: in-t-addr=%p, out-t-addr=%p",
                        in_trace, out_trace);
@@ -51,6 +52,57 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
                if (status != BT_TRACE_SET_NAME_STATUS_OK) {
                        BT_COMP_LOGE("Cannot set trace's name: trace-addr=%p, name=\"%s\"",
                                out_trace, trace_name);
+                       bt_current_thread_clear_error();
+                       goto end;
+               }
+       }
+
+       /*
+        * Do not copy the trace UUID as it may be modified and should
+        * no longer have the same UUID.
+        */
+
+       /*
+        * Go over all the entries in the environment section of the
+        * trace and copy the content to the new trace.
+        */
+       env_field_count = bt_trace_get_environment_entry_count(in_trace);
+       for (i = 0; i < env_field_count; i++) {
+               const char *value_name;
+               const bt_value *value = NULL;
+               bt_trace_set_environment_entry_status set_env_status;
+
+               bt_trace_borrow_environment_entry_by_index_const(
+                       in_trace, i, &value_name, &value);
+
+               BT_COMP_LOGD("Copying trace environnement entry: "
+                       "index=%" PRId64 ", value-addr=%p, value-name=%s",
+                       i, value, value_name);
+
+               BT_ASSERT(value_name);
+               BT_ASSERT(value);
+
+               if (bt_value_is_signed_integer(value)) {
+                       set_env_status =
+                               bt_trace_set_environment_entry_integer(
+                                               out_trace, value_name,
+                                               bt_value_signed_integer_get(
+                                                       value));
+               } else if (bt_value_is_string(value)) {
+                       set_env_status =
+                               bt_trace_set_environment_entry_string(
+                                       out_trace, value_name,
+                                       bt_value_string_get(value));
+               } else {
+                       abort();
+               }
+
+               if (set_env_status !=
+                               BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) {
+                       BT_COMP_LOGE("Cannot copy trace's environment: "
+                               "trace-addr=%p, name=\"%s\"",
+                               out_trace, trace_name);
+                       bt_current_thread_clear_error();
                        goto end;
                }
        }
@@ -190,6 +242,8 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        BT_COMP_LOGE("Cannot set string field's value: "
                                "str-field-addr=%p, str=%s" PRId64,
                                out_field, str);
+                       bt_current_thread_clear_error();
+
                }
                break;
        }
@@ -249,6 +303,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                                BT_COMP_LOGE("Cannot set dynamic array field's "
                                        "length field: field-addr=%p, "
                                        "length=%" PRIu64, out_field, array_len);
+                               bt_current_thread_clear_error();
                        }
                }
 
@@ -281,6 +336,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        BT_COMP_LOGE("Cannot select variant field's option field: "
                                "var-field-addr=%p, opt-index=%" PRId64,
                                out_field, in_selected_option_idx);
+                       bt_current_thread_clear_error();
                }
 
                in_option_field = bt_field_variant_borrow_selected_option_field_const(in_field);
This page took 0.02623 seconds and 4 git commands to generate.