4 * Babeltrace CTF file system Reader Component
6 * Copyright 2015-2017 Philippe Proulx <pproulx@efficios.com>
7 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #define BT_COMP_LOG_SELF_COMP self_comp
29 #define BT_LOG_OUTPUT_LEVEL log_level
30 #define BT_LOG_TAG "PLUGIN/SRC.CTF.FS"
31 #include "logging/comp-logging.h"
33 #include "common/common.h"
34 #include <babeltrace2/babeltrace.h>
35 #include "common/uuid.h"
37 #include "common/assert.h"
42 #include "data-stream-file.h"
44 #include "../common/metadata/decoder.h"
45 #include "../common/metadata/ctf-meta-configure-ir-trace.h"
46 #include "../common/msg-iter/msg-iter.h"
48 #include "plugins/common/param-validation/param-validation.h"
58 void ctf_fs_msg_iter_data_destroy(
59 struct ctf_fs_msg_iter_data
*msg_iter_data
)
65 if (msg_iter_data
->msg_iter
) {
66 ctf_msg_iter_destroy(msg_iter_data
->msg_iter
);
69 if (msg_iter_data
->msg_iter_medops_data
) {
70 ctf_fs_ds_group_medops_data_destroy(
71 msg_iter_data
->msg_iter_medops_data
);
74 g_free(msg_iter_data
);
78 bt_message_iterator_class_next_method_status
ctf_fs_iterator_next_one(
79 struct ctf_fs_msg_iter_data
*msg_iter_data
,
80 const bt_message
**out_msg
)
82 bt_message_iterator_class_next_method_status status
;
83 enum ctf_msg_iter_status msg_iter_status
;
84 bt_logging_level log_level
= msg_iter_data
->log_level
;
86 msg_iter_status
= ctf_msg_iter_get_next_message(
87 msg_iter_data
->msg_iter
, out_msg
);
89 switch (msg_iter_status
) {
90 case CTF_MSG_ITER_STATUS_OK
:
91 /* Cool, message has been written to *out_msg. */
92 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
95 case CTF_MSG_ITER_STATUS_EOF
:
96 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
;
99 case CTF_MSG_ITER_STATUS_AGAIN
:
101 * Should not make it this far as this is
102 * medium-specific; there is nothing for the user to do
103 * and it should have been handled upstream.
107 case CTF_MSG_ITER_MEDIUM_STATUS_ERROR
:
108 BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data
->self_msg_iter
,
109 "Failed to get next message from CTF message iterator.");
110 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
113 case CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR
:
114 BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data
->self_msg_iter
,
115 "Failed to get next message from CTF message iterator.");
116 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR
;
127 bt_message_iterator_class_next_method_status
ctf_fs_iterator_next(
128 bt_self_message_iterator
*iterator
,
129 bt_message_array_const msgs
, uint64_t capacity
,
132 bt_message_iterator_class_next_method_status status
;
133 struct ctf_fs_msg_iter_data
*msg_iter_data
=
134 bt_self_message_iterator_get_data(iterator
);
137 if (G_UNLIKELY(msg_iter_data
->next_saved_error
)) {
139 * Last time we were called, we hit an error but had some
140 * messages to deliver, so we stashed the error here. Return
143 BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(msg_iter_data
->next_saved_error
);
144 status
= msg_iter_data
->next_saved_status
;
149 status
= ctf_fs_iterator_next_one(msg_iter_data
, &msgs
[i
]);
150 if (status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
) {
153 } while (i
< capacity
&&
154 status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
);
158 * Even if ctf_fs_iterator_next_one() returned something
159 * else than BT_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK, we
160 * accumulated message objects in the output
161 * message array, so we need to return
162 * BT_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK so that they are
163 * transfered to downstream. This other status occurs
164 * again the next time muxer_msg_iter_do_next() is
165 * called, possibly without any accumulated
166 * message, in which case we'll return it.
170 * Save this error for the next _next call. Assume that
171 * this component always appends error causes when
172 * returning an error status code, which will cause the
173 * current thread error to be non-NULL.
175 msg_iter_data
->next_saved_error
= bt_current_thread_take_error();
176 BT_ASSERT(msg_iter_data
->next_saved_error
);
177 msg_iter_data
->next_saved_status
= status
;
181 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
189 bt_message_iterator_class_seek_beginning_method_status
190 ctf_fs_iterator_seek_beginning(bt_self_message_iterator
*it
)
192 struct ctf_fs_msg_iter_data
*msg_iter_data
=
193 bt_self_message_iterator_get_data(it
);
195 BT_ASSERT(msg_iter_data
);
197 ctf_msg_iter_reset(msg_iter_data
->msg_iter
);
198 ctf_fs_ds_group_medops_data_reset(msg_iter_data
->msg_iter_medops_data
);
200 return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;
204 void ctf_fs_iterator_finalize(bt_self_message_iterator
*it
)
206 ctf_fs_msg_iter_data_destroy(
207 bt_self_message_iterator_get_data(it
));
211 bt_message_iterator_class_initialize_method_status
ctf_fs_iterator_init(
212 bt_self_message_iterator
*self_msg_iter
,
213 bt_self_message_iterator_configuration
*config
,
214 bt_self_component_port_output
*self_port
)
216 struct ctf_fs_port_data
*port_data
;
217 struct ctf_fs_msg_iter_data
*msg_iter_data
= NULL
;
218 bt_message_iterator_class_initialize_method_status status
;
219 bt_logging_level log_level
;
220 enum ctf_msg_iter_medium_status medium_status
;
221 bt_self_component
*self_comp
=
222 bt_self_message_iterator_borrow_component(self_msg_iter
);
224 port_data
= bt_self_component_port_get_data(
225 bt_self_component_port_output_as_self_component_port(
227 BT_ASSERT(port_data
);
228 log_level
= port_data
->ctf_fs
->log_level
;
229 msg_iter_data
= g_new0(struct ctf_fs_msg_iter_data
, 1);
230 if (!msg_iter_data
) {
231 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
235 msg_iter_data
->log_level
= log_level
;
236 msg_iter_data
->self_comp
= self_comp
;
237 msg_iter_data
->self_msg_iter
= self_msg_iter
;
238 msg_iter_data
->ds_file_group
= port_data
->ds_file_group
;
240 medium_status
= ctf_fs_ds_group_medops_data_create(
241 msg_iter_data
->ds_file_group
, self_msg_iter
, log_level
,
242 &msg_iter_data
->msg_iter_medops_data
);
244 medium_status
== CTF_MSG_ITER_MEDIUM_STATUS_OK
||
245 medium_status
== CTF_MSG_ITER_MEDIUM_STATUS_ERROR
||
246 medium_status
== CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR
);
247 if (medium_status
!= CTF_MSG_ITER_MEDIUM_STATUS_OK
) {
248 BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter
,
249 "Failed to create ctf_fs_ds_group_medops");
250 status
= (int) medium_status
;
254 msg_iter_data
->msg_iter
= ctf_msg_iter_create(
255 msg_iter_data
->ds_file_group
->ctf_fs_trace
->metadata
->tc
,
256 bt_common_get_page_size(msg_iter_data
->log_level
) * 8,
257 ctf_fs_ds_group_medops
,
258 msg_iter_data
->msg_iter_medops_data
,
259 msg_iter_data
->log_level
,
260 self_comp
, self_msg_iter
);
261 if (!msg_iter_data
->msg_iter
) {
262 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Cannot create a CTF message iterator.");
263 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
268 * This iterator can seek forward if its stream class has a default
271 if (msg_iter_data
->ds_file_group
->sc
->default_clock_class
) {
272 bt_self_message_iterator_configuration_set_can_seek_forward(
276 bt_self_message_iterator_set_data(self_msg_iter
,
278 msg_iter_data
= NULL
;
280 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK
;
284 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
287 ctf_fs_msg_iter_data_destroy(msg_iter_data
);
292 void ctf_fs_trace_destroy(struct ctf_fs_trace
*ctf_fs_trace
)
298 if (ctf_fs_trace
->ds_file_groups
) {
299 g_ptr_array_free(ctf_fs_trace
->ds_file_groups
, TRUE
);
302 BT_TRACE_PUT_REF_AND_RESET(ctf_fs_trace
->trace
);
304 if (ctf_fs_trace
->path
) {
305 g_string_free(ctf_fs_trace
->path
, TRUE
);
308 if (ctf_fs_trace
->metadata
) {
309 ctf_fs_metadata_fini(ctf_fs_trace
->metadata
);
310 g_free(ctf_fs_trace
->metadata
);
313 g_free(ctf_fs_trace
);
317 void ctf_fs_destroy(struct ctf_fs_component
*ctf_fs
)
323 ctf_fs_trace_destroy(ctf_fs
->trace
);
325 if (ctf_fs
->port_data
) {
326 g_ptr_array_free(ctf_fs
->port_data
, TRUE
);
333 void port_data_destroy(struct ctf_fs_port_data
*port_data
)
343 void port_data_destroy_notifier(void *data
) {
344 port_data_destroy(data
);
348 void ctf_fs_trace_destroy_notifier(void *data
)
350 struct ctf_fs_trace
*trace
= data
;
351 ctf_fs_trace_destroy(trace
);
354 struct ctf_fs_component
*ctf_fs_component_create(bt_logging_level log_level
,
355 bt_self_component
*self_comp
)
357 struct ctf_fs_component
*ctf_fs
;
359 ctf_fs
= g_new0(struct ctf_fs_component
, 1);
364 ctf_fs
->log_level
= log_level
;
366 g_ptr_array_new_with_free_func(port_data_destroy_notifier
);
367 if (!ctf_fs
->port_data
) {
374 ctf_fs_destroy(ctf_fs
);
381 void ctf_fs_finalize(bt_self_component_source
*component
)
383 ctf_fs_destroy(bt_self_component_get_data(
384 bt_self_component_source_as_self_component(component
)));
387 gchar
*ctf_fs_make_port_name(struct ctf_fs_ds_file_group
*ds_file_group
)
389 GString
*name
= g_string_new(NULL
);
392 * The unique port name is generated by concatenating unique identifiers
400 /* For the trace, use the uuid if present, else the path. */
401 if (ds_file_group
->ctf_fs_trace
->metadata
->tc
->is_uuid_set
) {
402 char uuid_str
[BT_UUID_STR_LEN
+ 1];
404 bt_uuid_to_str(ds_file_group
->ctf_fs_trace
->metadata
->tc
->uuid
, uuid_str
);
405 g_string_assign(name
, uuid_str
);
407 g_string_assign(name
, ds_file_group
->ctf_fs_trace
->path
->str
);
411 * For the stream class, use the id if present. We can omit this field
412 * otherwise, as there will only be a single stream class.
414 if (ds_file_group
->sc
->id
!= UINT64_C(-1)) {
415 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->sc
->id
);
418 /* For the stream, use the id if present, else, use the path. */
419 if (ds_file_group
->stream_id
!= UINT64_C(-1)) {
420 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->stream_id
);
422 BT_ASSERT(ds_file_group
->ds_file_infos
->len
== 1);
423 struct ctf_fs_ds_file_info
*ds_file_info
=
424 g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
425 g_string_append_printf(name
, " | %s", ds_file_info
->path
->str
);
428 return g_string_free(name
, FALSE
);
432 int create_one_port_for_trace(struct ctf_fs_component
*ctf_fs
,
433 struct ctf_fs_trace
*ctf_fs_trace
,
434 struct ctf_fs_ds_file_group
*ds_file_group
,
435 bt_self_component_source
*self_comp_src
)
438 struct ctf_fs_port_data
*port_data
= NULL
;
440 bt_logging_level log_level
= ctf_fs
->log_level
;
441 bt_self_component
*self_comp
=
442 bt_self_component_source_as_self_component(self_comp_src
);
444 port_name
= ctf_fs_make_port_name(ds_file_group
);
449 BT_COMP_LOGI("Creating one port named `%s`", port_name
);
451 /* Create output port for this file */
452 port_data
= g_new0(struct ctf_fs_port_data
, 1);
457 port_data
->ctf_fs
= ctf_fs
;
458 port_data
->ds_file_group
= ds_file_group
;
459 ret
= bt_self_component_source_add_output_port(
460 self_comp_src
, port_name
, port_data
, NULL
);
465 g_ptr_array_add(ctf_fs
->port_data
, port_data
);
475 port_data_destroy(port_data
);
480 int create_ports_for_trace(struct ctf_fs_component
*ctf_fs
,
481 struct ctf_fs_trace
*ctf_fs_trace
,
482 bt_self_component_source
*self_comp_src
)
486 bt_logging_level log_level
= ctf_fs_trace
->log_level
;
487 bt_self_component
*self_comp
=
488 bt_self_component_source_as_self_component(self_comp_src
);
490 /* Create one output port for each stream file group */
491 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
492 struct ctf_fs_ds_file_group
*ds_file_group
=
493 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
495 ret
= create_one_port_for_trace(ctf_fs
, ctf_fs_trace
,
496 ds_file_group
, self_comp_src
);
498 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Cannot create output port.");
508 void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info
*ds_file_info
)
514 if (ds_file_info
->path
) {
515 g_string_free(ds_file_info
->path
, TRUE
);
518 g_free(ds_file_info
);
522 struct ctf_fs_ds_file_info
*ctf_fs_ds_file_info_create(const char *path
,
525 struct ctf_fs_ds_file_info
*ds_file_info
;
527 ds_file_info
= g_new0(struct ctf_fs_ds_file_info
, 1);
532 ds_file_info
->path
= g_string_new(path
);
533 if (!ds_file_info
->path
) {
534 ctf_fs_ds_file_info_destroy(ds_file_info
);
539 ds_file_info
->begin_ns
= begin_ns
;
546 void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group
*ds_file_group
)
548 if (!ds_file_group
) {
552 if (ds_file_group
->ds_file_infos
) {
553 g_ptr_array_free(ds_file_group
->ds_file_infos
, TRUE
);
556 ctf_fs_ds_index_destroy(ds_file_group
->index
);
558 bt_stream_put_ref(ds_file_group
->stream
);
559 g_free(ds_file_group
);
563 struct ctf_fs_ds_file_group
*ctf_fs_ds_file_group_create(
564 struct ctf_fs_trace
*ctf_fs_trace
,
565 struct ctf_stream_class
*sc
,
566 uint64_t stream_instance_id
,
567 struct ctf_fs_ds_index
*index
)
569 struct ctf_fs_ds_file_group
*ds_file_group
;
571 ds_file_group
= g_new0(struct ctf_fs_ds_file_group
, 1);
572 if (!ds_file_group
) {
576 ds_file_group
->ds_file_infos
= g_ptr_array_new_with_free_func(
577 (GDestroyNotify
) ctf_fs_ds_file_info_destroy
);
578 if (!ds_file_group
->ds_file_infos
) {
582 ds_file_group
->index
= index
;
584 ds_file_group
->stream_id
= stream_instance_id
;
586 ds_file_group
->sc
= sc
;
587 ds_file_group
->ctf_fs_trace
= ctf_fs_trace
;
591 ctf_fs_ds_file_group_destroy(ds_file_group
);
592 ctf_fs_ds_index_destroy(index
);
593 ds_file_group
= NULL
;
596 return ds_file_group
;
599 /* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */
601 void array_insert(GPtrArray
*array
, gpointer element
, size_t pos
)
603 size_t original_array_len
= array
->len
;
605 /* Allocate an unused element at the end of the array. */
606 g_ptr_array_add(array
, NULL
);
608 /* If we are not inserting at the end, move the elements by one. */
609 if (pos
< original_array_len
) {
610 memmove(&(array
->pdata
[pos
+ 1]),
611 &(array
->pdata
[pos
]),
612 (original_array_len
- pos
) * sizeof(gpointer
));
615 /* Insert the value. */
616 array
->pdata
[pos
] = element
;
620 * Insert ds_file_info in ds_file_group's list of ds_file_infos at the right
621 * place to keep it sorted.
625 void ds_file_group_insert_ds_file_info_sorted(
626 struct ctf_fs_ds_file_group
*ds_file_group
,
627 struct ctf_fs_ds_file_info
*ds_file_info
)
631 /* Find the spot where to insert this ds_file_info. */
632 for (i
= 0; i
< ds_file_group
->ds_file_infos
->len
; i
++) {
633 struct ctf_fs_ds_file_info
*other_ds_file_info
=
634 g_ptr_array_index(ds_file_group
->ds_file_infos
, i
);
636 if (ds_file_info
->begin_ns
< other_ds_file_info
->begin_ns
) {
641 array_insert(ds_file_group
->ds_file_infos
, ds_file_info
, i
);
645 bool ds_index_entries_equal(
646 const struct ctf_fs_ds_index_entry
*left
,
647 const struct ctf_fs_ds_index_entry
*right
)
649 if (left
->packet_size
!= right
->packet_size
) {
653 if (left
->timestamp_begin
!= right
->timestamp_begin
) {
657 if (left
->timestamp_end
!= right
->timestamp_end
) {
661 if (left
->packet_seq_num
!= right
->packet_seq_num
) {
669 * Insert `entry` into `index`, without duplication.
671 * The entry is inserted only if there isn't an identical entry already.
673 * In any case, the ownership of `entry` is transferred to this function. So if
674 * the entry is not inserted, it is freed.
678 void ds_index_insert_ds_index_entry_sorted(
679 struct ctf_fs_ds_index
*index
,
680 struct ctf_fs_ds_index_entry
*entry
)
683 struct ctf_fs_ds_index_entry
*other_entry
= NULL
;
685 /* Find the spot where to insert this index entry. */
686 for (i
= 0; i
< index
->entries
->len
; i
++) {
687 other_entry
= g_ptr_array_index(index
->entries
, i
);
689 if (entry
->timestamp_begin_ns
<= other_entry
->timestamp_begin_ns
) {
695 * Insert the entry only if a duplicate doesn't already exist.
697 * There can be duplicate packets if reading multiple overlapping
698 * snapshots of the same trace. We then want the index to contain
699 * a reference to only one copy of that packet.
701 if (i
== index
->entries
->len
||
702 !ds_index_entries_equal(entry
, other_entry
)) {
703 array_insert(index
->entries
, entry
, i
);
710 void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index
*dest
, struct ctf_fs_ds_index
*src
)
714 for (i
= 0; i
< src
->entries
->len
; i
++) {
715 struct ctf_fs_ds_index_entry
*entry
=
716 g_ptr_array_index(src
->entries
, i
);
719 * Ownership of the ctf_fs_ds_index_entry is transferred to
720 * ds_index_insert_ds_index_entry_sorted.
722 g_ptr_array_index(src
->entries
, i
) = NULL
;
723 ds_index_insert_ds_index_entry_sorted(dest
, entry
);
728 int add_ds_file_to_ds_file_group(struct ctf_fs_trace
*ctf_fs_trace
,
731 int64_t stream_instance_id
= -1;
732 int64_t begin_ns
= -1;
733 struct ctf_fs_ds_file_group
*ds_file_group
= NULL
;
734 bool add_group
= false;
737 struct ctf_fs_ds_file
*ds_file
= NULL
;
738 struct ctf_fs_ds_file_info
*ds_file_info
= NULL
;
739 struct ctf_fs_ds_index
*index
= NULL
;
740 struct ctf_msg_iter
*msg_iter
= NULL
;
741 struct ctf_stream_class
*sc
= NULL
;
742 struct ctf_msg_iter_packet_properties props
;
743 bt_logging_level log_level
= ctf_fs_trace
->log_level
;
744 bt_self_component
*self_comp
= ctf_fs_trace
->self_comp
;
745 bt_self_component_class
*self_comp_class
= ctf_fs_trace
->self_comp_class
;
748 * Create a temporary ds_file to read some properties about the data
751 ds_file
= ctf_fs_ds_file_create(ctf_fs_trace
, NULL
, NULL
, path
,
757 /* Create a temporary iterator to read the ds_file. */
758 msg_iter
= ctf_msg_iter_create(ctf_fs_trace
->metadata
->tc
,
759 bt_common_get_page_size(log_level
) * 8,
760 ctf_fs_ds_file_medops
, ds_file
, log_level
, self_comp
, NULL
);
762 BT_COMP_LOGE_STR("Cannot create a CTF message iterator.");
766 ctf_msg_iter_set_dry_run(msg_iter
, true);
768 ret
= ctf_msg_iter_get_packet_properties(msg_iter
, &props
);
770 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
771 "Cannot get stream file's first packet's header and context fields (`%s`).",
776 sc
= ctf_trace_class_borrow_stream_class_by_id(ds_file
->metadata
->tc
,
777 props
.stream_class_id
);
779 stream_instance_id
= props
.data_stream_id
;
781 if (props
.snapshots
.beginning_clock
!= UINT64_C(-1)) {
782 BT_ASSERT(sc
->default_clock_class
);
783 ret
= bt_util_clock_cycles_to_ns_from_origin(
784 props
.snapshots
.beginning_clock
,
785 sc
->default_clock_class
->frequency
,
786 sc
->default_clock_class
->offset_seconds
,
787 sc
->default_clock_class
->offset_cycles
, &begin_ns
);
789 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
790 "Cannot convert clock cycles to nanoseconds from origin (`%s`).",
796 ds_file_info
= ctf_fs_ds_file_info_create(path
, begin_ns
);
801 index
= ctf_fs_ds_file_build_index(ds_file
, ds_file_info
, msg_iter
);
803 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
804 self_comp
, self_comp_class
,
805 "Failed to index CTF stream file \'%s\'",
806 ds_file
->file
->path
->str
);
810 if (begin_ns
== -1) {
812 * No beginning timestamp to sort the stream files
813 * within a stream file group, so consider that this
814 * file must be the only one within its group.
816 stream_instance_id
= -1;
819 if (stream_instance_id
== -1) {
821 * No stream instance ID or no beginning timestamp:
822 * create a unique stream file group for this stream
823 * file because, even if there's a stream instance ID,
824 * there's no timestamp to order the file within its
827 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
828 sc
, UINT64_C(-1), index
);
829 /* Ownership of index is transferred. */
832 if (!ds_file_group
) {
836 ds_file_group_insert_ds_file_info_sorted(ds_file_group
,
837 BT_MOVE_REF(ds_file_info
));
843 BT_ASSERT(stream_instance_id
!= -1);
844 BT_ASSERT(begin_ns
!= -1);
846 /* Find an existing stream file group with this ID */
847 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
848 ds_file_group
= g_ptr_array_index(
849 ctf_fs_trace
->ds_file_groups
, i
);
851 if (ds_file_group
->sc
== sc
&&
852 ds_file_group
->stream_id
==
853 stream_instance_id
) {
857 ds_file_group
= NULL
;
860 if (!ds_file_group
) {
861 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
862 sc
, stream_instance_id
, index
);
863 /* Ownership of index is transferred. */
865 if (!ds_file_group
) {
871 merge_ctf_fs_ds_indexes(ds_file_group
->index
, index
);
874 ds_file_group_insert_ds_file_info_sorted(ds_file_group
,
875 BT_MOVE_REF(ds_file_info
));
880 ctf_fs_ds_file_group_destroy(ds_file_group
);
881 ds_file_group
= NULL
;
885 if (add_group
&& ds_file_group
) {
886 g_ptr_array_add(ctf_fs_trace
->ds_file_groups
, ds_file_group
);
889 ctf_fs_ds_file_destroy(ds_file
);
890 ctf_fs_ds_file_info_destroy(ds_file_info
);
893 ctf_msg_iter_destroy(msg_iter
);
896 ctf_fs_ds_index_destroy(index
);
901 int create_ds_file_groups(struct ctf_fs_trace
*ctf_fs_trace
)
904 const char *basename
;
905 GError
*error
= NULL
;
907 bt_logging_level log_level
= ctf_fs_trace
->log_level
;
908 bt_self_component
*self_comp
= ctf_fs_trace
->self_comp
;
909 bt_self_component_class
*self_comp_class
= ctf_fs_trace
->self_comp_class
;
911 /* Check each file in the path directory, except specific ones */
912 dir
= g_dir_open(ctf_fs_trace
->path
->str
, 0, &error
);
914 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
915 "Cannot open directory `%s`: %s (code %d)",
916 ctf_fs_trace
->path
->str
, error
->message
,
921 while ((basename
= g_dir_read_name(dir
))) {
922 struct ctf_fs_file
*file
;
924 if (strcmp(basename
, CTF_FS_METADATA_FILENAME
) == 0) {
925 /* Ignore the metadata stream. */
926 BT_COMP_LOGI("Ignoring metadata file `%s" G_DIR_SEPARATOR_S
"%s`",
927 ctf_fs_trace
->path
->str
, basename
);
931 if (basename
[0] == '.') {
932 BT_COMP_LOGI("Ignoring hidden file `%s" G_DIR_SEPARATOR_S
"%s`",
933 ctf_fs_trace
->path
->str
, basename
);
937 /* Create the file. */
938 file
= ctf_fs_file_create(log_level
, self_comp
);
940 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
941 "Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S
"%s`",
942 ctf_fs_trace
->path
->str
, basename
);
946 /* Create full path string. */
947 g_string_append_printf(file
->path
, "%s" G_DIR_SEPARATOR_S
"%s",
948 ctf_fs_trace
->path
->str
, basename
);
949 if (!g_file_test(file
->path
->str
, G_FILE_TEST_IS_REGULAR
)) {
950 BT_COMP_LOGI("Ignoring non-regular file `%s`",
952 ctf_fs_file_destroy(file
);
957 ret
= ctf_fs_file_open(file
, "rb");
959 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
960 "Cannot open stream file `%s`",
965 if (file
->size
== 0) {
966 /* Skip empty stream. */
967 BT_COMP_LOGI("Ignoring empty file `%s`", file
->path
->str
);
968 ctf_fs_file_destroy(file
);
972 ret
= add_ds_file_to_ds_file_group(ctf_fs_trace
,
975 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
976 "Cannot add stream file `%s` to stream file group",
978 ctf_fs_file_destroy(file
);
982 ctf_fs_file_destroy(file
);
1004 int set_trace_name(bt_trace
*trace
, const char *name_suffix
,
1005 bt_logging_level log_level
, bt_self_component
*self_comp
)
1008 const bt_value
*val
;
1011 name
= g_string_new(NULL
);
1013 BT_COMP_LOGE_STR("Failed to allocate a GString.");
1019 * Check if we have a trace environment string value named `hostname`.
1020 * If so, use it as the trace name's prefix.
1022 val
= bt_trace_borrow_environment_entry_value_by_name_const(
1024 if (val
&& bt_value_is_string(val
)) {
1025 g_string_append(name
, bt_value_string_get(val
));
1028 g_string_append_c(name
, G_DIR_SEPARATOR
);
1033 g_string_append(name
, name_suffix
);
1036 ret
= bt_trace_set_name(trace
, name
->str
);
1045 g_string_free(name
, TRUE
);
1052 struct ctf_fs_trace
*ctf_fs_trace_create(
1053 bt_self_component
*self_comp
,
1054 bt_self_component_class
*self_comp_class
,
1055 const char *path
, const char *name
,
1056 struct ctf_fs_metadata_config
*metadata_config
,
1057 bt_logging_level log_level
)
1059 struct ctf_fs_trace
*ctf_fs_trace
;
1062 /* Only one of them must be set. */
1063 BT_ASSERT(!self_comp
!= !self_comp_class
);
1065 ctf_fs_trace
= g_new0(struct ctf_fs_trace
, 1);
1066 if (!ctf_fs_trace
) {
1070 ctf_fs_trace
->log_level
= log_level
;
1071 ctf_fs_trace
->self_comp
= self_comp
;
1072 ctf_fs_trace
->self_comp_class
= self_comp_class
;
1073 ctf_fs_trace
->path
= g_string_new(path
);
1074 if (!ctf_fs_trace
->path
) {
1078 ctf_fs_trace
->metadata
= g_new0(struct ctf_fs_metadata
, 1);
1079 if (!ctf_fs_trace
->metadata
) {
1083 ctf_fs_metadata_init(ctf_fs_trace
->metadata
);
1084 ctf_fs_trace
->ds_file_groups
= g_ptr_array_new_with_free_func(
1085 (GDestroyNotify
) ctf_fs_ds_file_group_destroy
);
1086 if (!ctf_fs_trace
->ds_file_groups
) {
1090 ret
= ctf_fs_metadata_set_trace_class(self_comp
, ctf_fs_trace
,
1096 if (ctf_fs_trace
->metadata
->trace_class
) {
1097 ctf_fs_trace
->trace
=
1098 bt_trace_create(ctf_fs_trace
->metadata
->trace_class
);
1099 if (!ctf_fs_trace
->trace
) {
1104 if (ctf_fs_trace
->trace
) {
1105 ret
= ctf_trace_class_configure_ir_trace(
1106 ctf_fs_trace
->metadata
->tc
, ctf_fs_trace
->trace
);
1111 ret
= set_trace_name(ctf_fs_trace
->trace
, name
, log_level
,
1118 ret
= create_ds_file_groups(ctf_fs_trace
);
1126 ctf_fs_trace_destroy(ctf_fs_trace
);
1127 ctf_fs_trace
= NULL
;
1130 return ctf_fs_trace
;
1134 int path_is_ctf_trace(const char *path
)
1136 GString
*metadata_path
= g_string_new(NULL
);
1139 if (!metadata_path
) {
1144 g_string_printf(metadata_path
, "%s" G_DIR_SEPARATOR_S
"%s", path
, CTF_FS_METADATA_FILENAME
);
1146 if (g_file_test(metadata_path
->str
, G_FILE_TEST_IS_REGULAR
)) {
1152 g_string_free(metadata_path
, TRUE
);
1156 /* Helper for ctf_fs_component_create_ctf_fs_trace, to handle a single path. */
1159 int ctf_fs_component_create_ctf_fs_trace_one_path(
1160 struct ctf_fs_component
*ctf_fs
,
1161 const char *path_param
,
1162 const char *trace_name
,
1164 bt_self_component
*self_comp
,
1165 bt_self_component_class
*self_comp_class
)
1167 struct ctf_fs_trace
*ctf_fs_trace
;
1170 bt_logging_level log_level
= ctf_fs
->log_level
;
1172 norm_path
= bt_common_normalize_path(path_param
, NULL
);
1174 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
1175 "Failed to normalize path: `%s`.",
1180 ret
= path_is_ctf_trace(norm_path
->str
);
1182 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
1183 "Failed to check if path is a CTF trace: path=%s",
1186 } else if (ret
== 0) {
1187 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
1188 "Path is not a CTF trace (does not contain a metadata file): `%s`.",
1193 // FIXME: Remove or ifdef for __MINGW32__
1194 if (strcmp(norm_path
->str
, "/") == 0) {
1195 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
1196 "Opening a trace in `/` is not supported.");
1201 ctf_fs_trace
= ctf_fs_trace_create(self_comp
, self_comp_class
, norm_path
->str
,
1202 trace_name
, &ctf_fs
->metadata_config
, log_level
);
1203 if (!ctf_fs_trace
) {
1204 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
1205 "Cannot create trace for `%s`.",
1210 g_ptr_array_add(traces
, ctf_fs_trace
);
1211 ctf_fs_trace
= NULL
;
1221 g_string_free(norm_path
, TRUE
);
1228 * Count the number of stream and event classes defined by this trace's metadata.
1230 * This is used to determine which metadata is the "latest", out of multiple
1231 * traces sharing the same UUID. It is assumed that amongst all these metadatas,
1232 * a bigger metadata is a superset of a smaller metadata. Therefore, it is
1233 * enough to just count the classes.
1237 unsigned int metadata_count_stream_and_event_classes(struct ctf_fs_trace
*trace
)
1239 unsigned int num
= trace
->metadata
->tc
->stream_classes
->len
;
1242 for (i
= 0; i
< trace
->metadata
->tc
->stream_classes
->len
; i
++) {
1243 struct ctf_stream_class
*sc
= trace
->metadata
->tc
->stream_classes
->pdata
[i
];
1244 num
+= sc
->event_classes
->len
;
1251 * Merge the src ds_file_group into dest. This consists of merging their
1252 * ds_file_infos, making sure to keep the result sorted.
1256 void merge_ctf_fs_ds_file_groups(struct ctf_fs_ds_file_group
*dest
, struct ctf_fs_ds_file_group
*src
)
1260 for (i
= 0; i
< src
->ds_file_infos
->len
; i
++) {
1261 struct ctf_fs_ds_file_info
*ds_file_info
=
1262 g_ptr_array_index(src
->ds_file_infos
, i
);
1264 /* Ownership of the ds_file_info is transferred to dest. */
1265 g_ptr_array_index(src
->ds_file_infos
, i
) = NULL
;
1267 ds_file_group_insert_ds_file_info_sorted(dest
, ds_file_info
);
1270 /* Merge both indexes. */
1271 merge_ctf_fs_ds_indexes(dest
->index
, src
->index
);
1273 /* Merge src_trace's data stream file groups into dest_trace's. */
1276 int merge_matching_ctf_fs_ds_file_groups(
1277 struct ctf_fs_trace
*dest_trace
,
1278 struct ctf_fs_trace
*src_trace
)
1281 GPtrArray
*dest
= dest_trace
->ds_file_groups
;
1282 GPtrArray
*src
= src_trace
->ds_file_groups
;
1287 * Save the initial length of dest: we only want to check against the
1288 * original elements in the inner loop.
1290 const guint dest_len
= dest
->len
;
1292 for (s_i
= 0; s_i
< src
->len
; s_i
++) {
1293 struct ctf_fs_ds_file_group
*src_group
= g_ptr_array_index(src
, s_i
);
1294 struct ctf_fs_ds_file_group
*dest_group
= NULL
;
1296 /* A stream instance without ID can't match a stream in the other trace. */
1297 if (src_group
->stream_id
!= -1) {
1300 /* Let's search for a matching ds_file_group in the destination. */
1301 for (d_i
= 0; d_i
< dest_len
; d_i
++) {
1302 struct ctf_fs_ds_file_group
*candidate_dest
= g_ptr_array_index(dest
, d_i
);
1304 /* Can't match a stream instance without ID. */
1305 if (candidate_dest
->stream_id
== -1) {
1310 * If the two groups have the same stream instance id
1311 * and belong to the same stream class (stream instance
1312 * ids are per-stream class), they represent the same
1315 if (candidate_dest
->stream_id
!= src_group
->stream_id
||
1316 candidate_dest
->sc
->id
!= src_group
->sc
->id
) {
1320 dest_group
= candidate_dest
;
1326 * Didn't find a friend in dest to merge our src_group into?
1327 * Create a new empty one. This can happen if a stream was
1328 * active in the source trace chunk but not in the destination
1332 struct ctf_stream_class
*sc
;
1333 struct ctf_fs_ds_index
*index
;
1335 sc
= ctf_trace_class_borrow_stream_class_by_id(
1336 dest_trace
->metadata
->tc
, src_group
->sc
->id
);
1339 index
= ctf_fs_ds_index_create(dest_trace
->log_level
,
1340 dest_trace
->self_comp
);
1346 dest_group
= ctf_fs_ds_file_group_create(dest_trace
, sc
,
1347 src_group
->stream_id
, index
);
1348 /* Ownership of index is transferred. */
1355 g_ptr_array_add(dest_trace
->ds_file_groups
, dest_group
);
1358 BT_ASSERT(dest_group
);
1359 merge_ctf_fs_ds_file_groups(dest_group
, src_group
);
1367 * Collapse the given traces, which must all share the same UUID, in a single
1370 * The trace with the most expansive metadata is chosen and all other traces
1371 * are merged into that one. The array slots of all the traces that get merged
1372 * in the chosen one are set to NULL, so only the slot of the chosen trace
1377 int merge_ctf_fs_traces(struct ctf_fs_trace
**traces
, unsigned int num_traces
,
1378 struct ctf_fs_trace
**out_trace
)
1380 unsigned int winner_count
;
1381 struct ctf_fs_trace
*winner
;
1385 BT_ASSERT(num_traces
>= 2);
1387 winner_count
= metadata_count_stream_and_event_classes(traces
[0]);
1391 /* Find the trace with the largest metadata. */
1392 for (i
= 1; i
< num_traces
; i
++) {
1393 struct ctf_fs_trace
*candidate
;
1394 unsigned int candidate_count
;
1396 candidate
= traces
[i
];
1398 /* A bit of sanity check. */
1399 BT_ASSERT(bt_uuid_compare(winner
->metadata
->tc
->uuid
, candidate
->metadata
->tc
->uuid
) == 0);
1401 candidate_count
= metadata_count_stream_and_event_classes(candidate
);
1403 if (candidate_count
> winner_count
) {
1404 winner_count
= candidate_count
;
1410 /* Merge all the other traces in the winning trace. */
1411 for (i
= 0; i
< num_traces
; i
++) {
1412 struct ctf_fs_trace
*trace
= traces
[i
];
1414 /* Don't merge the winner into itself. */
1415 if (trace
== winner
) {
1419 /* Merge trace's data stream file groups into winner's. */
1420 ret
= merge_matching_ctf_fs_ds_file_groups(winner
, trace
);
1427 * Move the winner out of the array, into `*out_trace`.
1429 *out_trace
= winner
;
1430 traces
[winner_i
] = NULL
;
1442 int decode_clock_snapshot_after_event(struct ctf_fs_trace
*ctf_fs_trace
,
1443 struct ctf_clock_class
*default_cc
,
1444 struct ctf_fs_ds_index_entry
*index_entry
,
1445 enum target_event target_event
, uint64_t *cs
, int64_t *ts_ns
)
1447 enum ctf_msg_iter_status iter_status
= CTF_MSG_ITER_STATUS_OK
;
1448 struct ctf_fs_ds_file
*ds_file
= NULL
;
1449 struct ctf_msg_iter
*msg_iter
= NULL
;
1450 bt_logging_level log_level
= ctf_fs_trace
->log_level
;
1451 bt_self_component
*self_comp
= ctf_fs_trace
->self_comp
;
1454 BT_ASSERT(ctf_fs_trace
);
1455 BT_ASSERT(index_entry
);
1456 BT_ASSERT(index_entry
->path
);
1458 ds_file
= ctf_fs_ds_file_create(ctf_fs_trace
, NULL
,
1459 NULL
, index_entry
->path
, log_level
);
1461 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Failed to create a ctf_fs_ds_file");
1466 BT_ASSERT(ctf_fs_trace
->metadata
);
1467 BT_ASSERT(ctf_fs_trace
->metadata
->tc
);
1469 msg_iter
= ctf_msg_iter_create(ctf_fs_trace
->metadata
->tc
,
1470 bt_common_get_page_size(log_level
) * 8, ctf_fs_ds_file_medops
,
1471 ds_file
, log_level
, self_comp
, NULL
);
1473 /* ctf_msg_iter_create() logs errors. */
1479 * Turn on dry run mode to prevent the creation and usage of Babeltrace
1480 * library objects (bt_field, bt_message_*, etc.).
1482 ctf_msg_iter_set_dry_run(msg_iter
, true);
1484 /* Seek to the beginning of the target packet. */
1485 iter_status
= ctf_msg_iter_seek(msg_iter
, index_entry
->offset
);
1487 /* ctf_msg_iter_seek() logs errors. */
1492 switch (target_event
) {
1495 * Start to decode the packet until we reach the end of
1496 * the first event. To extract the first event's clock
1499 iter_status
= ctf_msg_iter_curr_packet_first_event_clock_snapshot(
1503 /* Decode the packet to extract the last event's clock snapshot. */
1504 iter_status
= ctf_msg_iter_curr_packet_last_event_clock_snapshot(
1515 /* Convert clock snapshot to timestamp. */
1516 ret
= bt_util_clock_cycles_to_ns_from_origin(*cs
,
1517 default_cc
->frequency
, default_cc
->offset_seconds
,
1518 default_cc
->offset_cycles
, ts_ns
);
1520 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1521 "Failed to convert clock snapshot to timestamp");
1527 ctf_fs_ds_file_destroy(ds_file
);
1530 ctf_msg_iter_destroy(msg_iter
);
1537 int decode_packet_first_event_timestamp(struct ctf_fs_trace
*ctf_fs_trace
,
1538 struct ctf_clock_class
*default_cc
,
1539 struct ctf_fs_ds_index_entry
*index_entry
, uint64_t *cs
, int64_t *ts_ns
)
1541 return decode_clock_snapshot_after_event(ctf_fs_trace
, default_cc
,
1542 index_entry
, FIRST_EVENT
, cs
, ts_ns
);
1546 int decode_packet_last_event_timestamp(struct ctf_fs_trace
*ctf_fs_trace
,
1547 struct ctf_clock_class
*default_cc
,
1548 struct ctf_fs_ds_index_entry
*index_entry
, uint64_t *cs
, int64_t *ts_ns
)
1550 return decode_clock_snapshot_after_event(ctf_fs_trace
, default_cc
,
1551 index_entry
, LAST_EVENT
, cs
, ts_ns
);
1555 * Fix up packet index entries for lttng's "event-after-packet" bug.
1556 * Some buggy lttng tracer versions may emit events with a timestamp that is
1557 * larger (after) than the timestamp_end of the their packets.
1559 * To fix up this erroneous data we do the following:
1560 * 1. If it's not the stream file's last packet: set the packet index entry's
1561 * end time to the next packet's beginning time.
1562 * 2. If it's the stream file's last packet, set the packet index entry's end
1563 * time to the packet's last event's time, if any, or to the packet's
1564 * beginning time otherwise.
1566 * Known buggy tracer versions:
1567 * - before lttng-ust 2.11.0
1568 * - before lttng-module 2.11.0
1569 * - before lttng-module 2.10.10
1570 * - before lttng-module 2.9.13
1573 int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace
*trace
)
1576 guint ds_file_group_i
;
1577 GPtrArray
*ds_file_groups
= trace
->ds_file_groups
;
1578 bt_logging_level log_level
= trace
->log_level
;
1580 for (ds_file_group_i
= 0; ds_file_group_i
< ds_file_groups
->len
;
1581 ds_file_group_i
++) {
1583 struct ctf_clock_class
*default_cc
;
1584 struct ctf_fs_ds_index_entry
*last_entry
;
1585 struct ctf_fs_ds_index
*index
;
1587 struct ctf_fs_ds_file_group
*ds_file_group
=
1588 g_ptr_array_index(ds_file_groups
, ds_file_group_i
);
1590 BT_ASSERT(ds_file_group
);
1591 index
= ds_file_group
->index
;
1594 BT_ASSERT(index
->entries
);
1595 BT_ASSERT(index
->entries
->len
> 0);
1598 * Iterate over all entries but the last one. The last one is
1599 * fixed differently after.
1601 for (entry_i
= 0; entry_i
< index
->entries
->len
- 1;
1603 struct ctf_fs_ds_index_entry
*curr_entry
, *next_entry
;
1605 curr_entry
= g_ptr_array_index(index
->entries
, entry_i
);
1606 next_entry
= g_ptr_array_index(index
->entries
, entry_i
+ 1);
1609 * 1. Set the current index entry `end` timestamp to
1610 * the next index entry `begin` timestamp.
1612 curr_entry
->timestamp_end
= next_entry
->timestamp_begin
;
1613 curr_entry
->timestamp_end_ns
= next_entry
->timestamp_begin_ns
;
1617 * 2. Fix the last entry by decoding the last event of the last
1620 last_entry
= g_ptr_array_index(index
->entries
,
1621 index
->entries
->len
- 1);
1622 BT_ASSERT(last_entry
);
1624 BT_ASSERT(ds_file_group
->sc
->default_clock_class
);
1625 default_cc
= ds_file_group
->sc
->default_clock_class
;
1628 * Decode packet to read the timestamp of the last event of the
1631 ret
= decode_packet_last_event_timestamp(trace
, default_cc
,
1632 last_entry
, &last_entry
->timestamp_end
,
1633 &last_entry
->timestamp_end_ns
);
1635 BT_COMP_LOGE_APPEND_CAUSE(trace
->self_comp
,
1636 "Failed to decode stream's last packet to get its last event's clock snapshot.");
1646 * Fix up packet index entries for barectf's "event-before-packet" bug.
1647 * Some buggy barectf tracer versions may emit events with a timestamp that is
1648 * less than the timestamp_begin of the their packets.
1650 * To fix up this erroneous data we do the following:
1651 * 1. Starting at the second index entry, set the timestamp_begin of the
1652 * current entry to the timestamp of the first event of the packet.
1653 * 2. Set the previous entry's timestamp_end to the timestamp_begin of the
1656 * Known buggy tracer versions:
1657 * - before barectf 2.3.1
1660 int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace
*trace
)
1663 guint ds_file_group_i
;
1664 GPtrArray
*ds_file_groups
= trace
->ds_file_groups
;
1665 bt_logging_level log_level
= trace
->log_level
;
1667 for (ds_file_group_i
= 0; ds_file_group_i
< ds_file_groups
->len
;
1668 ds_file_group_i
++) {
1670 struct ctf_clock_class
*default_cc
;
1671 struct ctf_fs_ds_file_group
*ds_file_group
=
1672 g_ptr_array_index(ds_file_groups
, ds_file_group_i
);
1674 struct ctf_fs_ds_index
*index
= ds_file_group
->index
;
1677 BT_ASSERT(index
->entries
);
1678 BT_ASSERT(index
->entries
->len
> 0);
1680 BT_ASSERT(ds_file_group
->sc
->default_clock_class
);
1681 default_cc
= ds_file_group
->sc
->default_clock_class
;
1684 * 1. Iterate over the index, starting from the second entry
1687 for (entry_i
= 1; entry_i
< index
->entries
->len
;
1689 struct ctf_fs_ds_index_entry
*curr_entry
, *prev_entry
;
1690 prev_entry
= g_ptr_array_index(index
->entries
, entry_i
- 1);
1691 curr_entry
= g_ptr_array_index(index
->entries
, entry_i
);
1693 * 2. Set the current entry `begin` timestamp to the
1694 * timestamp of the first event of the current packet.
1696 ret
= decode_packet_first_event_timestamp(trace
, default_cc
,
1697 curr_entry
, &curr_entry
->timestamp_begin
,
1698 &curr_entry
->timestamp_begin_ns
);
1700 BT_COMP_LOGE_APPEND_CAUSE(trace
->self_comp
,
1701 "Failed to decode first event's clock snapshot");
1706 * 3. Set the previous entry `end` timestamp to the
1707 * timestamp of the first event of the current packet.
1709 prev_entry
->timestamp_end
= curr_entry
->timestamp_begin
;
1710 prev_entry
->timestamp_end_ns
= curr_entry
->timestamp_begin_ns
;
1718 * When using the lttng-crash feature it's likely that the last packets of each
1719 * stream have their timestamp_end set to zero. This is caused by the fact that
1720 * the tracer crashed and was not able to properly close the packets.
1722 * To fix up this erroneous data we do the following:
1723 * For each index entry, if the entry's timestamp_end is 0 and the
1724 * timestamp_begin is not 0:
1725 * - If it's the stream file's last packet: set the packet index entry's end
1726 * time to the packet's last event's time, if any, or to the packet's
1727 * beginning time otherwise.
1728 * - If it's not the stream file's last packet: set the packet index
1729 * entry's end time to the next packet's beginning time.
1731 * Affected versions:
1732 * - All current and future lttng-ust and lttng-modules versions.
1735 int fix_index_lttng_crash_quirk(struct ctf_fs_trace
*trace
)
1738 guint ds_file_group_idx
;
1739 GPtrArray
*ds_file_groups
= trace
->ds_file_groups
;
1740 bt_logging_level log_level
= trace
->log_level
;
1742 for (ds_file_group_idx
= 0; ds_file_group_idx
< ds_file_groups
->len
;
1743 ds_file_group_idx
++) {
1745 struct ctf_clock_class
*default_cc
;
1746 struct ctf_fs_ds_index_entry
*last_entry
;
1747 struct ctf_fs_ds_index
*index
;
1749 struct ctf_fs_ds_file_group
*ds_file_group
=
1750 g_ptr_array_index(ds_file_groups
, ds_file_group_idx
);
1752 BT_ASSERT(ds_file_group
);
1753 index
= ds_file_group
->index
;
1755 BT_ASSERT(ds_file_group
->sc
->default_clock_class
);
1756 default_cc
= ds_file_group
->sc
->default_clock_class
;
1759 BT_ASSERT(index
->entries
);
1760 BT_ASSERT(index
->entries
->len
> 0);
1762 last_entry
= g_ptr_array_index(index
->entries
,
1763 index
->entries
->len
- 1);
1764 BT_ASSERT(last_entry
);
1767 /* 1. Fix the last entry first. */
1768 if (last_entry
->timestamp_end
== 0 &&
1769 last_entry
->timestamp_begin
!= 0) {
1771 * Decode packet to read the timestamp of the
1772 * last event of the stream file.
1774 ret
= decode_packet_last_event_timestamp(trace
,
1775 default_cc
, last_entry
,
1776 &last_entry
->timestamp_end
,
1777 &last_entry
->timestamp_end_ns
);
1779 BT_COMP_LOGE_APPEND_CAUSE(trace
->self_comp
,
1780 "Failed to decode last event's clock snapshot");
1785 /* Iterate over all entries but the last one. */
1786 for (entry_idx
= 0; entry_idx
< index
->entries
->len
- 1;
1788 struct ctf_fs_ds_index_entry
*curr_entry
, *next_entry
;
1789 curr_entry
= g_ptr_array_index(index
->entries
, entry_idx
);
1790 next_entry
= g_ptr_array_index(index
->entries
, entry_idx
+ 1);
1792 if (curr_entry
->timestamp_end
== 0 &&
1793 curr_entry
->timestamp_begin
!= 0) {
1795 * 2. Set the current index entry `end` timestamp to
1796 * the next index entry `begin` timestamp.
1798 curr_entry
->timestamp_end
= next_entry
->timestamp_begin
;
1799 curr_entry
->timestamp_end_ns
= next_entry
->timestamp_begin_ns
;
1809 * Extract the tracer information necessary to compare versions.
1810 * Returns 0 on success, and -1 if the extraction is not successful because the
1811 * necessary fields are absents in the trace metadata.
1814 int extract_tracer_info(struct ctf_fs_trace
*trace
,
1815 struct tracer_info
*current_tracer_info
)
1818 struct ctf_trace_class_env_entry
*entry
;
1820 /* Clear the current_tracer_info struct */
1821 memset(current_tracer_info
, 0, sizeof(*current_tracer_info
));
1824 * To compare 2 tracer versions, at least the tracer name and it's
1825 * major version are needed. If one of these is missing, consider it an
1826 * extraction failure.
1828 entry
= ctf_trace_class_borrow_env_entry_by_name(
1829 trace
->metadata
->tc
, "tracer_name");
1830 if (!entry
|| entry
->type
!= CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR
) {
1831 goto missing_bare_minimum
;
1834 /* Set tracer name. */
1835 current_tracer_info
->name
= entry
->value
.str
->str
;
1837 entry
= ctf_trace_class_borrow_env_entry_by_name(
1838 trace
->metadata
->tc
, "tracer_major");
1839 if (!entry
|| entry
->type
!= CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT
) {
1840 goto missing_bare_minimum
;
1843 /* Set major version number. */
1844 current_tracer_info
->major
= entry
->value
.i
;
1846 entry
= ctf_trace_class_borrow_env_entry_by_name(
1847 trace
->metadata
->tc
, "tracer_minor");
1848 if (!entry
|| entry
->type
!= CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT
) {
1852 /* Set minor version number. */
1853 current_tracer_info
->minor
= entry
->value
.i
;
1855 entry
= ctf_trace_class_borrow_env_entry_by_name(
1856 trace
->metadata
->tc
, "tracer_patch");
1859 * If `tracer_patch` doesn't exist `tracer_patchlevel` might.
1860 * For example, `lttng-modules` uses entry name
1861 * `tracer_patchlevel`.
1863 entry
= ctf_trace_class_borrow_env_entry_by_name(
1864 trace
->metadata
->tc
, "tracer_patchlevel");
1867 if (!entry
|| entry
->type
!= CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT
) {
1871 /* Set patch version number. */
1872 current_tracer_info
->patch
= entry
->value
.i
;
1876 missing_bare_minimum
:
1883 bool is_tracer_affected_by_lttng_event_after_packet_bug(
1884 struct tracer_info
*curr_tracer_info
)
1886 bool is_affected
= false;
1888 if (strcmp(curr_tracer_info
->name
, "lttng-ust") == 0) {
1889 if (curr_tracer_info
->major
< 2) {
1891 } else if (curr_tracer_info
->major
== 2) {
1892 /* fixed in lttng-ust 2.11.0 */
1893 if (curr_tracer_info
->minor
< 11) {
1897 } else if (strcmp(curr_tracer_info
->name
, "lttng-modules") == 0) {
1898 if (curr_tracer_info
->major
< 2) {
1900 } else if (curr_tracer_info
->major
== 2) {
1901 /* fixed in lttng-modules 2.11.0 */
1902 if (curr_tracer_info
->minor
== 10) {
1903 /* fixed in lttng-modules 2.10.10 */
1904 if (curr_tracer_info
->patch
< 10) {
1907 } else if (curr_tracer_info
->minor
== 9) {
1908 /* fixed in lttng-modules 2.9.13 */
1909 if (curr_tracer_info
->patch
< 13) {
1912 } else if (curr_tracer_info
->minor
< 9) {
1922 bool is_tracer_affected_by_barectf_event_before_packet_bug(
1923 struct tracer_info
*curr_tracer_info
)
1925 bool is_affected
= false;
1927 if (strcmp(curr_tracer_info
->name
, "barectf") == 0) {
1928 if (curr_tracer_info
->major
< 2) {
1930 } else if (curr_tracer_info
->major
== 2) {
1931 if (curr_tracer_info
->minor
< 3) {
1933 } else if (curr_tracer_info
->minor
== 3) {
1934 /* fixed in barectf 2.3.1 */
1935 if (curr_tracer_info
->patch
< 1) {
1946 bool is_tracer_affected_by_lttng_crash_quirk(
1947 struct tracer_info
*curr_tracer_info
)
1949 bool is_affected
= false;
1951 /* All LTTng tracer may be affected by this lttng crash quirk. */
1952 if (strcmp(curr_tracer_info
->name
, "lttng-ust") == 0) {
1954 } else if (strcmp(curr_tracer_info
->name
, "lttng-modules") == 0) {
1962 * Looks for trace produced by known buggy tracers and fix up the index
1966 int fix_packet_index_tracer_bugs(struct ctf_fs_component
*ctf_fs
,
1967 bt_self_component
*self_comp
,
1968 bt_self_component_class
*self_comp_class
)
1971 struct tracer_info current_tracer_info
;
1972 bt_logging_level log_level
= ctf_fs
->log_level
;
1974 ret
= extract_tracer_info(ctf_fs
->trace
, ¤t_tracer_info
);
1977 * A trace may not have all the necessary environment
1978 * entries to do the tracer version comparison.
1979 * At least, the tracer name and major version number
1980 * are needed. Failing to extract these entries is not
1984 BT_LOGI_STR("Cannot extract tracer information necessary to compare with buggy versions.");
1988 /* Check if the trace may be affected by old tracer bugs. */
1989 if (is_tracer_affected_by_lttng_event_after_packet_bug(
1990 ¤t_tracer_info
)) {
1991 BT_LOGI_STR("Trace may be affected by LTTng tracer packet timestamp bug. Fixing up.");
1992 ret
= fix_index_lttng_event_after_packet_bug(ctf_fs
->trace
);
1994 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
1995 self_comp
, self_comp_class
,
1996 "Failed to fix LTTng event-after-packet bug.");
1999 ctf_fs
->trace
->metadata
->tc
->quirks
.lttng_event_after_packet
= true;
2002 if (is_tracer_affected_by_barectf_event_before_packet_bug(
2003 ¤t_tracer_info
)) {
2004 BT_LOGI_STR("Trace may be affected by barectf tracer packet timestamp bug. Fixing up.");
2005 ret
= fix_index_barectf_event_before_packet_bug(ctf_fs
->trace
);
2007 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
2008 self_comp
, self_comp_class
,
2009 "Failed to fix barectf event-before-packet bug.");
2012 ctf_fs
->trace
->metadata
->tc
->quirks
.barectf_event_before_packet
= true;
2015 if (is_tracer_affected_by_lttng_crash_quirk(
2016 ¤t_tracer_info
)) {
2017 ret
= fix_index_lttng_crash_quirk(ctf_fs
->trace
);
2019 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
2020 self_comp
, self_comp_class
,
2021 "Failed to fix lttng-crash timestamp quirks.");
2024 ctf_fs
->trace
->metadata
->tc
->quirks
.lttng_crash
= true;
2032 gint
compare_ds_file_groups_by_first_path(gconstpointer a
, gconstpointer b
)
2034 struct ctf_fs_ds_file_group
* const *ds_file_group_a
= a
;
2035 struct ctf_fs_ds_file_group
* const *ds_file_group_b
= b
;
2036 const struct ctf_fs_ds_file_info
*first_ds_file_info_a
;
2037 const struct ctf_fs_ds_file_info
*first_ds_file_info_b
;
2039 BT_ASSERT((*ds_file_group_a
)->ds_file_infos
->len
> 0);
2040 BT_ASSERT((*ds_file_group_b
)->ds_file_infos
->len
> 0);
2041 first_ds_file_info_a
= (*ds_file_group_a
)->ds_file_infos
->pdata
[0];
2042 first_ds_file_info_b
= (*ds_file_group_b
)->ds_file_infos
->pdata
[0];
2043 return strcmp(first_ds_file_info_a
->path
->str
,
2044 first_ds_file_info_b
->path
->str
);
2048 gint
compare_strings(gconstpointer p_a
, gconstpointer p_b
)
2050 const char *a
= *((const char **) p_a
);
2051 const char *b
= *((const char **) p_b
);
2053 return strcmp(a
, b
);
2056 int ctf_fs_component_create_ctf_fs_trace(
2057 struct ctf_fs_component
*ctf_fs
,
2058 const bt_value
*paths_value
,
2059 const bt_value
*trace_name_value
,
2060 bt_self_component
*self_comp
,
2061 bt_self_component_class
*self_comp_class
)
2065 bt_logging_level log_level
= ctf_fs
->log_level
;
2066 GPtrArray
*paths
= NULL
;
2068 const char *trace_name
;
2070 BT_ASSERT(bt_value_get_type(paths_value
) == BT_VALUE_TYPE_ARRAY
);
2071 BT_ASSERT(!bt_value_array_is_empty(paths_value
));
2073 traces
= g_ptr_array_new_with_free_func(ctf_fs_trace_destroy_notifier
);
2075 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2076 "Failed to allocate a GPtrArray.");
2080 paths
= g_ptr_array_new_with_free_func(g_free
);
2082 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2083 "Failed to allocate a GPtrArray.");
2087 trace_name
= trace_name_value
? bt_value_string_get(trace_name_value
) : NULL
;
2090 * Create a sorted array of the paths, to make the execution of this
2091 * component deterministic.
2093 for (i
= 0; i
< bt_value_array_get_length(paths_value
); i
++) {
2094 const bt_value
*path_value
=
2095 bt_value_array_borrow_element_by_index_const(paths_value
, i
);
2096 const char *input
= bt_value_string_get(path_value
);
2099 input_copy
= g_strdup(input
);
2101 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2102 "Failed to copy a string.");
2106 g_ptr_array_add(paths
, input_copy
);
2109 g_ptr_array_sort(paths
, compare_strings
);
2111 /* Create a separate ctf_fs_trace object for each path. */
2112 for (i
= 0; i
< paths
->len
; i
++) {
2113 const char *path
= g_ptr_array_index(paths
, i
);
2115 ret
= ctf_fs_component_create_ctf_fs_trace_one_path(ctf_fs
,
2116 path
, trace_name
, traces
, self_comp
, self_comp_class
);
2122 if (traces
->len
> 1) {
2123 struct ctf_fs_trace
*first_trace
= (struct ctf_fs_trace
*) traces
->pdata
[0];
2124 const uint8_t *first_trace_uuid
= first_trace
->metadata
->tc
->uuid
;
2125 struct ctf_fs_trace
*trace
;
2128 * We have more than one trace, they must all share the same
2129 * UUID, verify that.
2131 for (i
= 0; i
< traces
->len
; i
++) {
2132 struct ctf_fs_trace
*this_trace
=
2133 (struct ctf_fs_trace
*) traces
->pdata
[i
];
2134 const uint8_t *this_trace_uuid
= this_trace
->metadata
->tc
->uuid
;
2136 if (!this_trace
->metadata
->tc
->is_uuid_set
) {
2137 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2138 "Multiple traces given, but a trace does not have a UUID: path=%s",
2139 this_trace
->path
->str
);
2143 if (bt_uuid_compare(first_trace_uuid
, this_trace_uuid
) != 0) {
2144 char first_trace_uuid_str
[BT_UUID_STR_LEN
+ 1];
2145 char this_trace_uuid_str
[BT_UUID_STR_LEN
+ 1];
2147 bt_uuid_to_str(first_trace_uuid
, first_trace_uuid_str
);
2148 bt_uuid_to_str(this_trace_uuid
, this_trace_uuid_str
);
2150 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2151 "Multiple traces given, but UUIDs don't match: "
2152 "first-trace-uuid=%s, first-trace-path=%s, "
2153 "trace-uuid=%s, trace-path=%s",
2154 first_trace_uuid_str
, first_trace
->path
->str
,
2155 this_trace_uuid_str
, this_trace
->path
->str
);
2160 ret
= merge_ctf_fs_traces((struct ctf_fs_trace
**) traces
->pdata
,
2161 traces
->len
, &trace
);
2163 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2164 "Failed to merge traces with the same UUID.");
2168 ctf_fs
->trace
= trace
;
2170 /* Just one trace, it may or may not have a UUID, both are fine. */
2171 ctf_fs
->trace
= traces
->pdata
[0];
2172 traces
->pdata
[0] = NULL
;
2175 ret
= fix_packet_index_tracer_bugs(ctf_fs
, self_comp
, self_comp_class
);
2177 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2178 "Failed to fix packet index tracer bugs.");
2182 * Sort data stream file groups by first data stream file info
2183 * path to get a deterministic order. This order influences the
2184 * order of the output ports. It also influences the order of
2185 * the automatic stream IDs if the trace's packet headers do not
2186 * contain a `stream_instance_id` field, in which case the data
2187 * stream file to stream ID association is always the same,
2188 * whatever the build and the system.
2190 * Having a deterministic order here can help debugging and
2193 g_ptr_array_sort(ctf_fs
->trace
->ds_file_groups
,
2194 compare_ds_file_groups_by_first_path
);
2201 g_ptr_array_free(traces
, TRUE
);
2205 g_ptr_array_free(paths
, TRUE
);
2212 GString
*get_stream_instance_unique_name(
2213 struct ctf_fs_ds_file_group
*ds_file_group
)
2216 struct ctf_fs_ds_file_info
*ds_file_info
;
2218 name
= g_string_new(NULL
);
2224 * If there's more than one stream file in the stream file
2225 * group, the first (earliest) stream file's path is used as
2226 * the stream's unique name.
2228 BT_ASSERT(ds_file_group
->ds_file_infos
->len
> 0);
2229 ds_file_info
= g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
2230 g_string_assign(name
, ds_file_info
->path
->str
);
2236 /* Create the IR stream objects for ctf_fs_trace. */
2239 int create_streams_for_trace(struct ctf_fs_trace
*ctf_fs_trace
)
2242 GString
*name
= NULL
;
2244 bt_logging_level log_level
= ctf_fs_trace
->log_level
;
2245 bt_self_component
*self_comp
= ctf_fs_trace
->self_comp
;
2247 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
2248 struct ctf_fs_ds_file_group
*ds_file_group
=
2249 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
2250 name
= get_stream_instance_unique_name(ds_file_group
);
2256 if (ds_file_group
->sc
->ir_sc
) {
2257 BT_ASSERT(ctf_fs_trace
->trace
);
2259 if (ds_file_group
->stream_id
== UINT64_C(-1)) {
2260 /* No stream ID: use 0 */
2261 ds_file_group
->stream
= bt_stream_create_with_id(
2262 ds_file_group
->sc
->ir_sc
,
2263 ctf_fs_trace
->trace
,
2264 ctf_fs_trace
->next_stream_id
);
2265 ctf_fs_trace
->next_stream_id
++;
2267 /* Specific stream ID */
2268 ds_file_group
->stream
= bt_stream_create_with_id(
2269 ds_file_group
->sc
->ir_sc
,
2270 ctf_fs_trace
->trace
,
2271 (uint64_t) ds_file_group
->stream_id
);
2274 ds_file_group
->stream
= NULL
;
2277 if (!ds_file_group
->stream
) {
2278 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
2279 "Cannot create stream for DS file group: "
2280 "addr=%p, stream-name=\"%s\"",
2281 ds_file_group
, name
->str
);
2285 ret
= bt_stream_set_name(ds_file_group
->stream
,
2288 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Cannot set stream's name: "
2289 "addr=%p, stream-name=\"%s\"",
2290 ds_file_group
->stream
, name
->str
);
2294 g_string_free(name
, TRUE
);
2307 g_string_free(name
, TRUE
);
2312 static const struct bt_param_validation_value_descr inputs_elem_descr
= {
2313 .type
= BT_VALUE_TYPE_STRING
,
2316 static const struct bt_param_validation_map_value_entry_descr fs_params_entries_descr
[] = {
2317 { "inputs", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, {
2318 BT_VALUE_TYPE_ARRAY
,
2321 .max_length
= BT_PARAM_VALIDATION_INFINITE
,
2322 .element_type
= &inputs_elem_descr
,
2325 { "trace-name", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_STRING
} },
2326 { "clock-class-offset-s", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_SIGNED_INTEGER
} },
2327 { "clock-class-offset-ns", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_SIGNED_INTEGER
} },
2328 { "force-clock-class-origin-unix-epoch", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_BOOL
} },
2329 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
2333 bool read_src_fs_parameters(const bt_value
*params
,
2334 const bt_value
**inputs
,
2335 const bt_value
**trace_name
,
2336 struct ctf_fs_component
*ctf_fs
,
2337 bt_self_component
*self_comp
,
2338 bt_self_component_class
*self_comp_class
) {
2340 const bt_value
*value
;
2341 bt_logging_level log_level
= ctf_fs
->log_level
;
2342 enum bt_param_validation_status validate_value_status
;
2343 gchar
*error
= NULL
;
2345 validate_value_status
= bt_param_validation_validate(params
,
2346 fs_params_entries_descr
, &error
);
2347 if (validate_value_status
!= BT_PARAM_VALIDATION_STATUS_OK
) {
2348 BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp
, self_comp_class
,
2354 /* inputs parameter */
2355 *inputs
= bt_value_map_borrow_entry_value_const(params
, "inputs");
2357 /* clock-class-offset-s parameter */
2358 value
= bt_value_map_borrow_entry_value_const(params
,
2359 "clock-class-offset-s");
2361 ctf_fs
->metadata_config
.clock_class_offset_s
=
2362 bt_value_integer_signed_get(value
);
2365 /* clock-class-offset-ns parameter */
2366 value
= bt_value_map_borrow_entry_value_const(params
,
2367 "clock-class-offset-ns");
2369 ctf_fs
->metadata_config
.clock_class_offset_ns
=
2370 bt_value_integer_signed_get(value
);
2373 /* force-clock-class-origin-unix-epoch parameter */
2374 value
= bt_value_map_borrow_entry_value_const(params
,
2375 "force-clock-class-origin-unix-epoch");
2377 ctf_fs
->metadata_config
.force_clock_class_origin_unix_epoch
=
2378 bt_value_bool_get(value
);
2381 /* trace-name parameter */
2382 *trace_name
= bt_value_map_borrow_entry_value_const(params
, "trace-name");
2392 struct ctf_fs_component
*ctf_fs_create(
2393 const bt_value
*params
,
2394 bt_self_component_source
*self_comp_src
)
2396 struct ctf_fs_component
*ctf_fs
= NULL
;
2397 const bt_value
*inputs_value
;
2398 const bt_value
*trace_name_value
;
2399 bt_self_component
*self_comp
=
2400 bt_self_component_source_as_self_component(self_comp_src
);
2402 ctf_fs
= ctf_fs_component_create(bt_component_get_logging_level(
2403 bt_self_component_as_component(self_comp
)), self_comp
);
2408 if (!read_src_fs_parameters(params
, &inputs_value
, &trace_name_value
,
2409 ctf_fs
, self_comp
, NULL
)) {
2413 bt_self_component_set_data(self_comp
, ctf_fs
);
2415 if (ctf_fs_component_create_ctf_fs_trace(ctf_fs
, inputs_value
,
2416 trace_name_value
, self_comp
, NULL
)) {
2420 if (create_streams_for_trace(ctf_fs
->trace
)) {
2424 if (create_ports_for_trace(ctf_fs
, ctf_fs
->trace
, self_comp_src
)) {
2431 ctf_fs_destroy(ctf_fs
);
2433 bt_self_component_set_data(self_comp
, NULL
);
2440 bt_component_class_initialize_method_status
ctf_fs_init(
2441 bt_self_component_source
*self_comp_src
,
2442 bt_self_component_source_configuration
*config
,
2443 const bt_value
*params
, __attribute__((unused
)) void *init_method_data
)
2445 struct ctf_fs_component
*ctf_fs
;
2446 bt_component_class_initialize_method_status ret
=
2447 BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
2449 ctf_fs
= ctf_fs_create(params
, self_comp_src
);
2451 ret
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
2458 bt_component_class_query_method_status
ctf_fs_query(
2459 bt_self_component_class_source
*comp_class
,
2460 bt_private_query_executor
*priv_query_exec
,
2461 const char *object
, const bt_value
*params
,
2462 __attribute__((unused
)) void *method_data
,
2463 const bt_value
**result
)
2465 bt_component_class_query_method_status status
=
2466 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
2467 bt_logging_level log_level
= bt_query_executor_get_logging_level(
2468 bt_private_query_executor_as_query_executor_const(
2471 if (strcmp(object
, "metadata-info") == 0) {
2472 status
= metadata_info_query(comp_class
, params
, log_level
,
2474 } else if (strcmp(object
, "babeltrace.trace-infos") == 0) {
2475 status
= trace_infos_query(comp_class
, params
, log_level
,
2477 } else if (!strcmp(object
, "babeltrace.support-info")) {
2478 status
= support_info_query(comp_class
, params
, log_level
, result
);
2480 BT_LOGE("Unknown query object `%s`", object
);
2481 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT
;