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 #include "common/common.h"
29 #include <babeltrace2/babeltrace.h>
30 #include "compat/uuid.h"
32 #include "common/assert.h"
37 #include "data-stream-file.h"
39 #include "../common/metadata/decoder.h"
40 #include "../common/msg-iter/msg-iter.h"
41 #include "../common/utils/utils.h"
44 #define BT_LOG_TAG "PLUGIN-CTF-FS-SRC"
48 int msg_iter_data_set_current_ds_file(struct ctf_fs_msg_iter_data
*msg_iter_data
)
50 struct ctf_fs_ds_file_info
*ds_file_info
;
53 BT_ASSERT(msg_iter_data
->ds_file_info_index
<
54 msg_iter_data
->ds_file_group
->ds_file_infos
->len
);
55 ds_file_info
= g_ptr_array_index(
56 msg_iter_data
->ds_file_group
->ds_file_infos
,
57 msg_iter_data
->ds_file_info_index
);
59 ctf_fs_ds_file_destroy(msg_iter_data
->ds_file
);
60 msg_iter_data
->ds_file
= ctf_fs_ds_file_create(
61 msg_iter_data
->ds_file_group
->ctf_fs_trace
,
62 msg_iter_data
->pc_msg_iter
,
63 msg_iter_data
->msg_iter
,
64 msg_iter_data
->ds_file_group
->stream
,
65 ds_file_info
->path
->str
);
66 if (!msg_iter_data
->ds_file
) {
74 void ctf_fs_msg_iter_data_destroy(
75 struct ctf_fs_msg_iter_data
*msg_iter_data
)
81 ctf_fs_ds_file_destroy(msg_iter_data
->ds_file
);
83 if (msg_iter_data
->msg_iter
) {
84 bt_msg_iter_destroy(msg_iter_data
->msg_iter
);
87 g_free(msg_iter_data
);
91 void set_msg_iter_emits_stream_beginning_end_messages(
92 struct ctf_fs_msg_iter_data
*msg_iter_data
)
94 bt_msg_iter_set_emit_stream_beginning_message(
95 msg_iter_data
->ds_file
->msg_iter
,
96 msg_iter_data
->ds_file_info_index
== 0);
97 bt_msg_iter_set_emit_stream_end_message(
98 msg_iter_data
->ds_file
->msg_iter
,
99 msg_iter_data
->ds_file_info_index
==
100 msg_iter_data
->ds_file_group
->ds_file_infos
->len
- 1);
104 bt_self_message_iterator_status
ctf_fs_iterator_next_one(
105 struct ctf_fs_msg_iter_data
*msg_iter_data
,
106 const bt_message
**out_msg
)
108 bt_self_message_iterator_status status
;
110 BT_ASSERT(msg_iter_data
->ds_file
);
115 status
= ctf_fs_ds_file_next(msg_iter_data
->ds_file
, &msg
);
117 case BT_SELF_MESSAGE_ITERATOR_STATUS_OK
:
121 case BT_SELF_MESSAGE_ITERATOR_STATUS_END
:
125 if (msg_iter_data
->ds_file_info_index
==
126 msg_iter_data
->ds_file_group
->ds_file_infos
->len
- 1) {
127 /* End of all group's stream files */
131 msg_iter_data
->ds_file_info_index
++;
132 bt_msg_iter_reset_for_next_stream_file(
133 msg_iter_data
->msg_iter
);
134 set_msg_iter_emits_stream_beginning_end_messages(
138 * Open and start reading the next stream file
139 * within our stream file group.
141 ret
= msg_iter_data_set_current_ds_file(msg_iter_data
);
143 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
147 /* Continue the loop to get the next message */
160 bt_self_message_iterator_status
ctf_fs_iterator_next(
161 bt_self_message_iterator
*iterator
,
162 bt_message_array_const msgs
, uint64_t capacity
,
165 bt_self_message_iterator_status status
=
166 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
167 struct ctf_fs_msg_iter_data
*msg_iter_data
=
168 bt_self_message_iterator_get_data(iterator
);
171 while (i
< capacity
&& status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
172 status
= ctf_fs_iterator_next_one(msg_iter_data
, &msgs
[i
]);
173 if (status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
180 * Even if ctf_fs_iterator_next_one() returned something
181 * else than BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
182 * accumulated message objects in the output
183 * message array, so we need to return
184 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they are
185 * transfered to downstream. This other status occurs
186 * again the next time muxer_msg_iter_do_next() is
187 * called, possibly without any accumulated
188 * message, in which case we'll return it.
191 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
198 int ctf_fs_iterator_reset(struct ctf_fs_msg_iter_data
*msg_iter_data
)
202 msg_iter_data
->ds_file_info_index
= 0;
203 ret
= msg_iter_data_set_current_ds_file(msg_iter_data
);
208 bt_msg_iter_reset(msg_iter_data
->msg_iter
);
209 set_msg_iter_emits_stream_beginning_end_messages(msg_iter_data
);
216 bt_self_message_iterator_status
ctf_fs_iterator_seek_beginning(
217 bt_self_message_iterator
*it
)
219 struct ctf_fs_msg_iter_data
*msg_iter_data
=
220 bt_self_message_iterator_get_data(it
);
221 bt_self_message_iterator_status status
=
222 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
224 BT_ASSERT(msg_iter_data
);
225 if (ctf_fs_iterator_reset(msg_iter_data
)) {
226 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
233 void ctf_fs_iterator_finalize(bt_self_message_iterator
*it
)
235 ctf_fs_msg_iter_data_destroy(
236 bt_self_message_iterator_get_data(it
));
240 bt_self_message_iterator_status
ctf_fs_iterator_init(
241 bt_self_message_iterator
*self_msg_iter
,
242 bt_self_component_source
*self_comp
,
243 bt_self_component_port_output
*self_port
)
245 struct ctf_fs_port_data
*port_data
;
246 struct ctf_fs_msg_iter_data
*msg_iter_data
= NULL
;
247 bt_self_message_iterator_status ret
=
248 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
250 port_data
= bt_self_component_port_get_data(
251 bt_self_component_port_output_as_self_component_port(
253 BT_ASSERT(port_data
);
254 msg_iter_data
= g_new0(struct ctf_fs_msg_iter_data
, 1);
255 if (!msg_iter_data
) {
256 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
260 msg_iter_data
->pc_msg_iter
= self_msg_iter
;
261 msg_iter_data
->msg_iter
= bt_msg_iter_create(
262 port_data
->ds_file_group
->ctf_fs_trace
->metadata
->tc
,
263 bt_common_get_page_size() * 8,
264 ctf_fs_ds_file_medops
, NULL
);
265 if (!msg_iter_data
->msg_iter
) {
266 BT_LOGE_STR("Cannot create a CTF message iterator.");
267 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
271 msg_iter_data
->ds_file_group
= port_data
->ds_file_group
;
272 if (ctf_fs_iterator_reset(msg_iter_data
)) {
273 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
277 bt_self_message_iterator_set_data(self_msg_iter
,
279 if (ret
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
283 msg_iter_data
= NULL
;
287 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
290 ctf_fs_msg_iter_data_destroy(msg_iter_data
);
295 void ctf_fs_destroy(struct ctf_fs_component
*ctf_fs
)
301 if (ctf_fs
->traces
) {
302 g_ptr_array_free(ctf_fs
->traces
, TRUE
);
305 if (ctf_fs
->port_data
) {
306 g_ptr_array_free(ctf_fs
->port_data
, TRUE
);
313 void port_data_destroy(struct ctf_fs_port_data
*port_data
)
323 void port_data_destroy_notifier(void *data
) {
324 port_data_destroy(data
);
328 void ctf_fs_trace_destroy(struct ctf_fs_trace
*ctf_fs_trace
)
334 if (ctf_fs_trace
->ds_file_groups
) {
335 g_ptr_array_free(ctf_fs_trace
->ds_file_groups
, TRUE
);
338 BT_TRACE_PUT_REF_AND_RESET(ctf_fs_trace
->trace
);
340 if (ctf_fs_trace
->path
) {
341 g_string_free(ctf_fs_trace
->path
, TRUE
);
344 if (ctf_fs_trace
->name
) {
345 g_string_free(ctf_fs_trace
->name
, TRUE
);
348 if (ctf_fs_trace
->metadata
) {
349 ctf_fs_metadata_fini(ctf_fs_trace
->metadata
);
350 g_free(ctf_fs_trace
->metadata
);
353 g_free(ctf_fs_trace
);
357 void ctf_fs_trace_destroy_notifier(void *data
)
359 struct ctf_fs_trace
*trace
= data
;
360 ctf_fs_trace_destroy(trace
);
363 struct ctf_fs_component
*ctf_fs_component_create(void)
365 struct ctf_fs_component
*ctf_fs
;
367 ctf_fs
= g_new0(struct ctf_fs_component
, 1);
373 g_ptr_array_new_with_free_func(port_data_destroy_notifier
);
374 if (!ctf_fs
->port_data
) {
379 g_ptr_array_new_with_free_func(ctf_fs_trace_destroy_notifier
);
380 if (!ctf_fs
->traces
) {
388 ctf_fs_destroy(ctf_fs
);
395 void ctf_fs_finalize(bt_self_component_source
*component
)
397 ctf_fs_destroy(bt_self_component_get_data(
398 bt_self_component_source_as_self_component(component
)));
401 gchar
*ctf_fs_make_port_name(struct ctf_fs_ds_file_group
*ds_file_group
)
403 GString
*name
= g_string_new(NULL
);
406 * The unique port name is generated by concatenating unique identifiers
414 /* For the trace, use the uuid if present, else the path. */
415 if (ds_file_group
->ctf_fs_trace
->metadata
->tc
->is_uuid_set
) {
416 char uuid_str
[BABELTRACE_UUID_STR_LEN
];
418 bt_uuid_unparse(ds_file_group
->ctf_fs_trace
->metadata
->tc
->uuid
, uuid_str
);
419 g_string_assign(name
, uuid_str
);
421 g_string_assign(name
, ds_file_group
->ctf_fs_trace
->path
->str
);
425 * For the stream class, use the id if present. We can omit this field
426 * otherwise, as there will only be a single stream class.
428 if (ds_file_group
->sc
->id
!= UINT64_C(-1)) {
429 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->sc
->id
);
432 /* For the stream, use the id if present, else, use the path. */
433 if (ds_file_group
->stream_id
!= UINT64_C(-1)) {
434 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->stream_id
);
436 BT_ASSERT(ds_file_group
->ds_file_infos
->len
== 1);
437 struct ctf_fs_ds_file_info
*ds_file_info
=
438 g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
439 g_string_append_printf(name
, " | %s", ds_file_info
->path
->str
);
442 return g_string_free(name
, FALSE
);
446 int create_one_port_for_trace(struct ctf_fs_component
*ctf_fs
,
447 struct ctf_fs_trace
*ctf_fs_trace
,
448 struct ctf_fs_ds_file_group
*ds_file_group
)
451 struct ctf_fs_port_data
*port_data
= NULL
;
454 port_name
= ctf_fs_make_port_name(ds_file_group
);
459 BT_LOGI("Creating one port named `%s`", port_name
);
461 /* Create output port for this file */
462 port_data
= g_new0(struct ctf_fs_port_data
, 1);
467 port_data
->ctf_fs
= ctf_fs
;
468 port_data
->ds_file_group
= ds_file_group
;
469 ret
= bt_self_component_source_add_output_port(
470 ctf_fs
->self_comp
, port_name
, port_data
, NULL
);
475 g_ptr_array_add(ctf_fs
->port_data
, port_data
);
487 port_data_destroy(port_data
);
492 int create_ports_for_trace(struct ctf_fs_component
*ctf_fs
,
493 struct ctf_fs_trace
*ctf_fs_trace
)
498 /* Create one output port for each stream file group */
499 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
500 struct ctf_fs_ds_file_group
*ds_file_group
=
501 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
503 ret
= create_one_port_for_trace(ctf_fs
, ctf_fs_trace
,
506 BT_LOGE("Cannot create output port.");
516 void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info
*ds_file_info
)
522 if (ds_file_info
->path
) {
523 g_string_free(ds_file_info
->path
, TRUE
);
526 g_free(ds_file_info
);
530 struct ctf_fs_ds_file_info
*ctf_fs_ds_file_info_create(const char *path
,
533 struct ctf_fs_ds_file_info
*ds_file_info
;
535 ds_file_info
= g_new0(struct ctf_fs_ds_file_info
, 1);
540 ds_file_info
->path
= g_string_new(path
);
541 if (!ds_file_info
->path
) {
542 ctf_fs_ds_file_info_destroy(ds_file_info
);
547 ds_file_info
->begin_ns
= begin_ns
;
554 void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group
*ds_file_group
)
556 if (!ds_file_group
) {
560 if (ds_file_group
->ds_file_infos
) {
561 g_ptr_array_free(ds_file_group
->ds_file_infos
, TRUE
);
564 if (ds_file_group
->index
) {
565 if (ds_file_group
->index
->entries
) {
566 g_ptr_array_free(ds_file_group
->index
->entries
, TRUE
);
568 g_free(ds_file_group
->index
);
571 bt_stream_put_ref(ds_file_group
->stream
);
572 g_free(ds_file_group
);
576 struct ctf_fs_ds_file_group
*ctf_fs_ds_file_group_create(
577 struct ctf_fs_trace
*ctf_fs_trace
,
578 struct ctf_stream_class
*sc
,
579 uint64_t stream_instance_id
,
580 struct ctf_fs_ds_index
*index
)
582 struct ctf_fs_ds_file_group
*ds_file_group
;
584 ds_file_group
= g_new0(struct ctf_fs_ds_file_group
, 1);
585 if (!ds_file_group
) {
589 ds_file_group
->ds_file_infos
= g_ptr_array_new_with_free_func(
590 (GDestroyNotify
) ctf_fs_ds_file_info_destroy
);
591 if (!ds_file_group
->ds_file_infos
) {
595 ds_file_group
->index
= index
;
597 ds_file_group
->stream_id
= stream_instance_id
;
599 ds_file_group
->sc
= sc
;
600 ds_file_group
->ctf_fs_trace
= ctf_fs_trace
;
604 ctf_fs_ds_file_group_destroy(ds_file_group
);
605 ctf_fs_ds_index_destroy(index
);
606 ds_file_group
= NULL
;
609 return ds_file_group
;
612 /* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */
614 void array_insert(GPtrArray
*array
, gpointer element
, size_t pos
)
616 size_t original_array_len
= array
->len
;
618 /* Allocate an unused element at the end of the array. */
619 g_ptr_array_add(array
, NULL
);
621 /* If we are not inserting at the end, move the elements by one. */
622 if (pos
< original_array_len
) {
623 memmove(&(array
->pdata
[pos
+ 1]),
624 &(array
->pdata
[pos
]),
625 (original_array_len
- pos
) * sizeof(gpointer
));
628 /* Insert the value. */
629 array
->pdata
[pos
] = element
;
633 * Insert ds_file_info in ds_file_group's list of ds_file_infos at the right
634 * place to keep it sorted.
638 void ds_file_group_insert_ds_file_info_sorted(
639 struct ctf_fs_ds_file_group
*ds_file_group
,
640 struct ctf_fs_ds_file_info
*ds_file_info
)
644 /* Find the spot where to insert this ds_file_info. */
645 for (i
= 0; i
< ds_file_group
->ds_file_infos
->len
; i
++) {
646 struct ctf_fs_ds_file_info
*other_ds_file_info
=
647 g_ptr_array_index(ds_file_group
->ds_file_infos
, i
);
649 if (ds_file_info
->begin_ns
< other_ds_file_info
->begin_ns
) {
654 array_insert(ds_file_group
->ds_file_infos
, ds_file_info
, i
);
658 void ds_file_group_insert_ds_index_entry_sorted(
659 struct ctf_fs_ds_file_group
*ds_file_group
,
660 struct ctf_fs_ds_index_entry
*entry
)
664 /* Find the spot where to insert this index entry. */
665 for (i
= 0; i
< ds_file_group
->index
->entries
->len
; i
++) {
666 struct ctf_fs_ds_index_entry
*other_entry
= g_ptr_array_index(
667 ds_file_group
->index
->entries
, i
);
669 if (entry
->timestamp_begin_ns
< other_entry
->timestamp_begin_ns
) {
674 array_insert(ds_file_group
->index
->entries
, entry
, i
);
678 * Create a new ds_file_info using the provided path, begin_ns and index, then
679 * add it to ds_file_group's list of ds_file_infos.
683 int ctf_fs_ds_file_group_add_ds_file_info(
684 struct ctf_fs_ds_file_group
*ds_file_group
,
685 const char *path
, int64_t begin_ns
)
687 struct ctf_fs_ds_file_info
*ds_file_info
;
690 ds_file_info
= ctf_fs_ds_file_info_create(path
, begin_ns
);
695 ds_file_group_insert_ds_file_info_sorted(ds_file_group
, ds_file_info
);
701 ctf_fs_ds_file_info_destroy(ds_file_info
);
708 int add_ds_file_to_ds_file_group(struct ctf_fs_trace
*ctf_fs_trace
,
711 int64_t stream_instance_id
= -1;
712 int64_t begin_ns
= -1;
713 struct ctf_fs_ds_file_group
*ds_file_group
= NULL
;
714 bool add_group
= false;
717 struct ctf_fs_ds_file
*ds_file
= NULL
;
718 struct ctf_fs_ds_index
*index
= NULL
;
719 struct bt_msg_iter
*msg_iter
= NULL
;
720 struct ctf_stream_class
*sc
= NULL
;
721 struct bt_msg_iter_packet_properties props
;
723 msg_iter
= bt_msg_iter_create(ctf_fs_trace
->metadata
->tc
,
724 bt_common_get_page_size() * 8, ctf_fs_ds_file_medops
, NULL
);
726 BT_LOGE_STR("Cannot create a CTF message iterator.");
730 ds_file
= ctf_fs_ds_file_create(ctf_fs_trace
, NULL
, msg_iter
,
736 ret
= bt_msg_iter_get_packet_properties(ds_file
->msg_iter
, &props
);
738 BT_LOGE("Cannot get stream file's first packet's header and context fields (`%s`).",
743 sc
= ctf_trace_class_borrow_stream_class_by_id(ds_file
->metadata
->tc
,
744 props
.stream_class_id
);
746 stream_instance_id
= props
.data_stream_id
;
748 if (props
.snapshots
.beginning_clock
!= UINT64_C(-1)) {
749 BT_ASSERT(sc
->default_clock_class
);
750 ret
= bt_util_clock_cycles_to_ns_from_origin(
751 props
.snapshots
.beginning_clock
,
752 sc
->default_clock_class
->frequency
,
753 sc
->default_clock_class
->offset_seconds
,
754 sc
->default_clock_class
->offset_cycles
, &begin_ns
);
756 BT_LOGE("Cannot convert clock cycles to nanoseconds from origin (`%s`).",
762 index
= ctf_fs_ds_file_build_index(ds_file
);
764 BT_LOGW("Failed to index CTF stream file \'%s\'",
765 ds_file
->file
->path
->str
);
768 if (begin_ns
== -1) {
770 * No beggining timestamp to sort the stream files
771 * within a stream file group, so consider that this
772 * file must be the only one within its group.
774 stream_instance_id
= -1;
777 if (stream_instance_id
== -1) {
779 * No stream instance ID or no beginning timestamp:
780 * create a unique stream file group for this stream
781 * file because, even if there's a stream instance ID,
782 * there's no timestamp to order the file within its
785 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
786 sc
, UINT64_C(-1), index
);
787 /* Ownership of index is transferred. */
790 if (!ds_file_group
) {
794 ret
= ctf_fs_ds_file_group_add_ds_file_info(ds_file_group
,
804 BT_ASSERT(stream_instance_id
!= -1);
805 BT_ASSERT(begin_ns
!= -1);
807 /* Find an existing stream file group with this ID */
808 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
809 ds_file_group
= g_ptr_array_index(
810 ctf_fs_trace
->ds_file_groups
, i
);
812 if (ds_file_group
->sc
== sc
&&
813 ds_file_group
->stream_id
==
814 stream_instance_id
) {
818 ds_file_group
= NULL
;
821 if (!ds_file_group
) {
822 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
823 sc
, stream_instance_id
, index
);
824 /* Ownership of index is transferred. */
826 if (!ds_file_group
) {
833 ret
= ctf_fs_ds_file_group_add_ds_file_info(ds_file_group
, path
,
842 ctf_fs_ds_file_group_destroy(ds_file_group
);
843 ds_file_group
= NULL
;
847 if (add_group
&& ds_file_group
) {
848 g_ptr_array_add(ctf_fs_trace
->ds_file_groups
, ds_file_group
);
851 ctf_fs_ds_file_destroy(ds_file
);
854 bt_msg_iter_destroy(msg_iter
);
857 ctf_fs_ds_index_destroy(index
);
862 int create_ds_file_groups(struct ctf_fs_trace
*ctf_fs_trace
)
865 const char *basename
;
866 GError
*error
= NULL
;
869 /* Check each file in the path directory, except specific ones */
870 dir
= g_dir_open(ctf_fs_trace
->path
->str
, 0, &error
);
872 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
873 ctf_fs_trace
->path
->str
, error
->message
,
878 while ((basename
= g_dir_read_name(dir
))) {
879 struct ctf_fs_file
*file
;
881 if (!strcmp(basename
, CTF_FS_METADATA_FILENAME
)) {
882 /* Ignore the metadata stream. */
883 BT_LOGI("Ignoring metadata file `%s" G_DIR_SEPARATOR_S
"%s`",
884 ctf_fs_trace
->path
->str
, basename
);
888 if (basename
[0] == '.') {
889 BT_LOGI("Ignoring hidden file `%s" G_DIR_SEPARATOR_S
"%s`",
890 ctf_fs_trace
->path
->str
, basename
);
894 /* Create the file. */
895 file
= ctf_fs_file_create();
897 BT_LOGE("Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S
"%s`",
898 ctf_fs_trace
->path
->str
, basename
);
902 /* Create full path string. */
903 g_string_append_printf(file
->path
, "%s" G_DIR_SEPARATOR_S
"%s",
904 ctf_fs_trace
->path
->str
, basename
);
905 if (!g_file_test(file
->path
->str
, G_FILE_TEST_IS_REGULAR
)) {
906 BT_LOGI("Ignoring non-regular file `%s`",
908 ctf_fs_file_destroy(file
);
913 ret
= ctf_fs_file_open(file
, "rb");
915 BT_LOGE("Cannot open stream file `%s`", file
->path
->str
);
919 if (file
->size
== 0) {
920 /* Skip empty stream. */
921 BT_LOGI("Ignoring empty file `%s`", file
->path
->str
);
922 ctf_fs_file_destroy(file
);
926 ret
= add_ds_file_to_ds_file_group(ctf_fs_trace
,
929 BT_LOGE("Cannot add stream file `%s` to stream file group",
931 ctf_fs_file_destroy(file
);
935 ctf_fs_file_destroy(file
);
957 int set_trace_name(bt_trace
*trace
, const char *name_suffix
)
960 const bt_trace_class
*tc
= bt_trace_borrow_class_const(trace
);
964 name
= g_string_new(NULL
);
966 BT_LOGE_STR("Failed to allocate a GString.");
972 * Check if we have a trace environment string value named `hostname`.
973 * If so, use it as the trace name's prefix.
975 val
= bt_trace_class_borrow_environment_entry_value_by_name_const(
977 if (val
&& bt_value_is_string(val
)) {
978 g_string_append(name
, bt_value_string_get(val
));
981 g_string_append_c(name
, G_DIR_SEPARATOR
);
986 g_string_append(name
, name_suffix
);
989 ret
= bt_trace_set_name(trace
, name
->str
);
998 g_string_free(name
, TRUE
);
1005 struct ctf_fs_trace
*ctf_fs_trace_create(bt_self_component_source
*self_comp
,
1006 const char *path
, const char *name
,
1007 struct ctf_fs_metadata_config
*metadata_config
)
1009 struct ctf_fs_trace
*ctf_fs_trace
;
1012 ctf_fs_trace
= g_new0(struct ctf_fs_trace
, 1);
1013 if (!ctf_fs_trace
) {
1017 ctf_fs_trace
->path
= g_string_new(path
);
1018 if (!ctf_fs_trace
->path
) {
1022 ctf_fs_trace
->name
= g_string_new(name
);
1023 if (!ctf_fs_trace
->name
) {
1027 ctf_fs_trace
->metadata
= g_new0(struct ctf_fs_metadata
, 1);
1028 if (!ctf_fs_trace
->metadata
) {
1032 ctf_fs_metadata_init(ctf_fs_trace
->metadata
);
1033 ctf_fs_trace
->ds_file_groups
= g_ptr_array_new_with_free_func(
1034 (GDestroyNotify
) ctf_fs_ds_file_group_destroy
);
1035 if (!ctf_fs_trace
->ds_file_groups
) {
1039 ret
= ctf_fs_metadata_set_trace_class(self_comp
,
1040 ctf_fs_trace
, metadata_config
);
1045 if (ctf_fs_trace
->metadata
->trace_class
) {
1046 ctf_fs_trace
->trace
=
1047 bt_trace_create(ctf_fs_trace
->metadata
->trace_class
);
1048 if (!ctf_fs_trace
->trace
) {
1053 if (ctf_fs_trace
->trace
) {
1054 ret
= set_trace_name(ctf_fs_trace
->trace
, name
);
1060 ret
= create_ds_file_groups(ctf_fs_trace
);
1068 ctf_fs_trace_destroy(ctf_fs_trace
);
1069 ctf_fs_trace
= NULL
;
1072 return ctf_fs_trace
;
1076 int path_is_ctf_trace(const char *path
)
1078 GString
*metadata_path
= g_string_new(NULL
);
1081 if (!metadata_path
) {
1086 g_string_printf(metadata_path
, "%s" G_DIR_SEPARATOR_S
"%s", path
, CTF_FS_METADATA_FILENAME
);
1088 if (g_file_test(metadata_path
->str
, G_FILE_TEST_IS_REGULAR
)) {
1094 g_string_free(metadata_path
, TRUE
);
1099 int add_trace_path(GList
**trace_paths
, const char *path
)
1101 GString
*norm_path
= NULL
;
1104 norm_path
= bt_common_normalize_path(path
, NULL
);
1106 BT_LOGE("Failed to normalize path `%s`.", path
);
1111 // FIXME: Remove or ifdef for __MINGW32__
1112 if (strcmp(norm_path
->str
, "/") == 0) {
1113 BT_LOGE("Opening a trace in `/` is not supported.");
1118 *trace_paths
= g_list_prepend(*trace_paths
, norm_path
);
1119 BT_ASSERT(*trace_paths
);
1124 g_string_free(norm_path
, TRUE
);
1131 int ctf_fs_find_traces(GList
**trace_paths
, const char *start_path
)
1134 GError
*error
= NULL
;
1136 const char *basename
= NULL
;
1138 /* Check if the starting path is a CTF trace itself */
1139 ret
= path_is_ctf_trace(start_path
);
1146 * Stop recursion: a CTF trace cannot contain another
1149 ret
= add_trace_path(trace_paths
, start_path
);
1153 /* Look for subdirectories */
1154 if (!g_file_test(start_path
, G_FILE_TEST_IS_DIR
)) {
1155 /* Starting path is not a directory: end of recursion */
1159 dir
= g_dir_open(start_path
, 0, &error
);
1161 if (error
->code
== G_FILE_ERROR_ACCES
) {
1162 BT_LOGI("Cannot open directory `%s`: %s (code %d): continuing",
1163 start_path
, error
->message
, error
->code
);
1167 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
1168 start_path
, error
->message
, error
->code
);
1173 while ((basename
= g_dir_read_name(dir
))) {
1174 GString
*sub_path
= g_string_new(NULL
);
1181 g_string_printf(sub_path
, "%s" G_DIR_SEPARATOR_S
"%s", start_path
, basename
);
1182 ret
= ctf_fs_find_traces(trace_paths
, sub_path
->str
);
1183 g_string_free(sub_path
, TRUE
);
1195 g_error_free(error
);
1202 GList
*ctf_fs_create_trace_names(GList
*trace_paths
, const char *base_path
) {
1203 GList
*trace_names
= NULL
;
1205 const char *last_sep
;
1209 * At this point we know that all the trace paths are
1210 * normalized, and so is the base path. This means that
1211 * they are absolute and they don't end with a separator.
1212 * We can simply find the location of the last separator
1213 * in the base path, which gives us the name of the actual
1214 * directory to look into, and use this location as the
1215 * start of each trace name within each trace path.
1219 * Base path: /home/user/my-traces/some-trace
1221 * - /home/user/my-traces/some-trace/host1/trace1
1222 * - /home/user/my-traces/some-trace/host1/trace2
1223 * - /home/user/my-traces/some-trace/host2/trace
1224 * - /home/user/my-traces/some-trace/other-trace
1226 * In this case the trace names are:
1228 * - some-trace/host1/trace1
1229 * - some-trace/host1/trace2
1230 * - some-trace/host2/trace
1231 * - some-trace/other-trace
1233 last_sep
= strrchr(base_path
, G_DIR_SEPARATOR
);
1235 /* We know there's at least one separator */
1236 BT_ASSERT(last_sep
);
1238 /* Distance to base */
1239 base_dist
= last_sep
- base_path
+ 1;
1241 /* Create the trace names */
1242 for (node
= trace_paths
; node
; node
= g_list_next(node
)) {
1243 GString
*trace_name
= g_string_new(NULL
);
1244 GString
*trace_path
= node
->data
;
1246 BT_ASSERT(trace_name
);
1247 g_string_assign(trace_name
, &trace_path
->str
[base_dist
]);
1248 trace_names
= g_list_append(trace_names
, trace_name
);
1254 /* Helper for ctf_fs_component_create_ctf_fs_traces, to handle a single path/root. */
1257 int ctf_fs_component_create_ctf_fs_traces_one_root(bt_self_component_source
*self_comp
,
1258 struct ctf_fs_component
*ctf_fs
,
1259 const char *path_param
)
1261 struct ctf_fs_trace
*ctf_fs_trace
= NULL
;
1263 GString
*norm_path
= NULL
;
1264 GList
*trace_paths
= NULL
;
1265 GList
*trace_names
= NULL
;
1269 norm_path
= bt_common_normalize_path(path_param
, NULL
);
1271 BT_LOGE("Failed to normalize path: `%s`.",
1276 ret
= ctf_fs_find_traces(&trace_paths
, norm_path
->str
);
1282 BT_LOGE("No CTF traces recursively found in `%s`.",
1287 trace_names
= ctf_fs_create_trace_names(trace_paths
, norm_path
->str
);
1289 BT_LOGE("Cannot create trace names from trace paths.");
1293 for (tp_node
= trace_paths
, tn_node
= trace_names
; tp_node
;
1294 tp_node
= g_list_next(tp_node
),
1295 tn_node
= g_list_next(tn_node
)) {
1296 GString
*trace_path
= tp_node
->data
;
1297 GString
*trace_name
= tn_node
->data
;
1299 ctf_fs_trace
= ctf_fs_trace_create(self_comp
,
1300 trace_path
->str
, trace_name
->str
,
1301 &ctf_fs
->metadata_config
);
1302 if (!ctf_fs_trace
) {
1303 BT_LOGE("Cannot create trace for `%s`.",
1308 g_ptr_array_add(ctf_fs
->traces
, ctf_fs_trace
);
1309 ctf_fs_trace
= NULL
;
1316 ctf_fs_trace_destroy(ctf_fs_trace
);
1319 for (tp_node
= trace_paths
; tp_node
; tp_node
= g_list_next(tp_node
)) {
1320 if (tp_node
->data
) {
1321 g_string_free(tp_node
->data
, TRUE
);
1325 for (tn_node
= trace_names
; tn_node
; tn_node
= g_list_next(tn_node
)) {
1326 if (tn_node
->data
) {
1327 g_string_free(tn_node
->data
, TRUE
);
1332 g_list_free(trace_paths
);
1336 g_list_free(trace_names
);
1340 g_string_free(norm_path
, TRUE
);
1346 /* GCompareFunc to sort traces by UUID. */
1349 gint
sort_traces_by_uuid(gconstpointer a
, gconstpointer b
)
1351 const struct ctf_fs_trace
*trace_a
= *((const struct ctf_fs_trace
**) a
);
1352 const struct ctf_fs_trace
*trace_b
= *((const struct ctf_fs_trace
**) b
);
1354 bool trace_a_has_uuid
= trace_a
->metadata
->tc
->is_uuid_set
;
1355 bool trace_b_has_uuid
= trace_b
->metadata
->tc
->is_uuid_set
;
1358 /* Order traces without uuid first. */
1359 if (!trace_a_has_uuid
&& trace_b_has_uuid
) {
1361 } else if (trace_a_has_uuid
&& !trace_b_has_uuid
) {
1363 } else if (!trace_a_has_uuid
&& !trace_b_has_uuid
) {
1366 ret
= bt_uuid_compare(trace_a
->metadata
->tc
->uuid
, trace_b
->metadata
->tc
->uuid
);
1373 * Count the number of stream and event classes defined by this trace's metadata.
1375 * This is used to determine which metadata is the "latest", out of multiple
1376 * traces sharing the same UUID. It is assumed that amongst all these metadatas,
1377 * a bigger metadata is a superset of a smaller metadata. Therefore, it is
1378 * enough to just count the classes.
1382 unsigned int metadata_count_stream_and_event_classes(struct ctf_fs_trace
*trace
)
1384 unsigned int num
= trace
->metadata
->tc
->stream_classes
->len
;
1387 for (i
= 0; i
< trace
->metadata
->tc
->stream_classes
->len
; i
++) {
1388 struct ctf_stream_class
*sc
= trace
->metadata
->tc
->stream_classes
->pdata
[i
];
1389 num
+= sc
->event_classes
->len
;
1396 * Merge the src ds_file_group into dest. This consists of merging their
1397 * ds_file_infos, making sure to keep the result sorted.
1401 void merge_ctf_fs_ds_file_groups(struct ctf_fs_ds_file_group
*dest
, struct ctf_fs_ds_file_group
*src
)
1405 for (i
= 0; i
< src
->ds_file_infos
->len
; i
++) {
1406 struct ctf_fs_ds_file_info
*ds_file_info
=
1407 g_ptr_array_index(src
->ds_file_infos
, i
);
1409 /* Ownership of the ds_file_info is transferred to dest. */
1410 g_ptr_array_index(src
->ds_file_infos
, i
) = NULL
;
1412 ds_file_group_insert_ds_file_info_sorted(dest
, ds_file_info
);
1415 /* Merge both indexes. */
1416 for (i
= 0; i
< src
->index
->entries
->len
; i
++) {
1417 struct ctf_fs_ds_index_entry
*entry
= g_ptr_array_index(
1418 src
->index
->entries
, i
);
1421 * Ownership of the ctf_fs_ds_index_entry is transferred to
1424 g_ptr_array_index(src
->index
->entries
, i
) = NULL
;
1426 ds_file_group_insert_ds_index_entry_sorted(dest
, entry
);
1429 /* Merge src_trace's data stream file groups into dest_trace's. */
1432 int merge_matching_ctf_fs_ds_file_groups(
1433 struct ctf_fs_trace
*dest_trace
,
1434 struct ctf_fs_trace
*src_trace
)
1437 GPtrArray
*dest
= dest_trace
->ds_file_groups
;
1438 GPtrArray
*src
= src_trace
->ds_file_groups
;
1443 * Save the initial length of dest: we only want to check against the
1444 * original elements in the inner loop.
1446 const guint dest_len
= dest
->len
;
1448 for (s_i
= 0; s_i
< src
->len
; s_i
++) {
1449 struct ctf_fs_ds_file_group
*src_group
= g_ptr_array_index(src
, s_i
);
1450 struct ctf_fs_ds_file_group
*dest_group
= NULL
;
1452 /* A stream instance without ID can't match a stream in the other trace. */
1453 if (src_group
->stream_id
!= -1) {
1456 /* Let's search for a matching ds_file_group in the destination. */
1457 for (d_i
= 0; d_i
< dest_len
; d_i
++) {
1458 struct ctf_fs_ds_file_group
*candidate_dest
= g_ptr_array_index(dest
, d_i
);
1460 /* Can't match a stream instance without ID. */
1461 if (candidate_dest
->stream_id
== -1) {
1466 * If the two groups have the same stream instance id
1467 * and belong to the same stream class (stream instance
1468 * ids are per-stream class), they represent the same
1471 if (candidate_dest
->stream_id
!= src_group
->stream_id
||
1472 candidate_dest
->sc
->id
!= src_group
->sc
->id
) {
1476 dest_group
= candidate_dest
;
1482 * Didn't find a friend in dest to merge our src_group into?
1483 * Create a new empty one. This can happen if a stream was
1484 * active in the source trace chunk but not in the destination
1488 struct ctf_stream_class
*sc
;
1489 struct ctf_fs_ds_index
*index
;
1491 sc
= ctf_trace_class_borrow_stream_class_by_id(
1492 dest_trace
->metadata
->tc
, src_group
->sc
->id
);
1495 index
= ctf_fs_ds_index_create();
1501 dest_group
= ctf_fs_ds_file_group_create(dest_trace
, sc
,
1502 src_group
->stream_id
, index
);
1503 /* Ownership of index is transferred. */
1510 g_ptr_array_add(dest_trace
->ds_file_groups
, dest_group
);
1513 BT_ASSERT(dest_group
);
1514 merge_ctf_fs_ds_file_groups(dest_group
, src_group
);
1522 * Collapse the given traces, which must all share the same UUID, in a single
1525 * The trace with the most expansive metadata is chosen and all other traces
1526 * are merged into that one. The array slots of all the traces that get merged
1527 * in the chosen one are set to NULL, so only the slot of the chosen trace
1532 int merge_ctf_fs_traces(struct ctf_fs_trace
**traces
, unsigned int num_traces
)
1534 unsigned int winner_count
;
1535 struct ctf_fs_trace
*winner
;
1538 char uuid_str
[BABELTRACE_UUID_STR_LEN
];
1540 BT_ASSERT(num_traces
>= 2);
1542 winner_count
= metadata_count_stream_and_event_classes(traces
[0]);
1545 /* Find the trace with the largest metadata. */
1546 for (i
= 1; i
< num_traces
; i
++) {
1547 struct ctf_fs_trace
*candidate
;
1548 unsigned int candidate_count
;
1550 candidate
= traces
[i
];
1552 /* A bit of sanity check. */
1553 BT_ASSERT(bt_uuid_compare(winner
->metadata
->tc
->uuid
, candidate
->metadata
->tc
->uuid
) == 0);
1555 candidate_count
= metadata_count_stream_and_event_classes(candidate
);
1557 if (candidate_count
> winner_count
) {
1558 winner_count
= candidate_count
;
1563 /* Merge all the other traces in the winning trace. */
1564 for (i
= 0; i
< num_traces
; i
++) {
1565 struct ctf_fs_trace
*trace
= traces
[i
];
1567 /* Don't merge the winner into itself. */
1568 if (trace
== winner
) {
1572 /* Merge trace's data stream file groups into winner's. */
1573 ret
= merge_matching_ctf_fs_ds_file_groups(winner
, trace
);
1578 /* Free the trace that got merged into winner, clear the slot in the array. */
1579 ctf_fs_trace_destroy(trace
);
1583 /* Use the string representation of the UUID as the trace name. */
1584 bt_uuid_unparse(winner
->metadata
->tc
->uuid
, uuid_str
);
1585 g_string_printf(winner
->name
, "%s", uuid_str
);
1592 * Merge all traces of `ctf_fs` that share the same UUID in a single trace.
1593 * Traces with no UUID are not merged.
1597 int merge_traces_with_same_uuid(struct ctf_fs_component
*ctf_fs
)
1599 GPtrArray
*traces
= ctf_fs
->traces
;
1600 guint range_start_idx
= 0;
1601 unsigned int num_traces
= 0;
1605 /* Sort the traces by uuid, then collapse traces with the same uuid in a single one. */
1606 g_ptr_array_sort(traces
, sort_traces_by_uuid
);
1608 /* Find ranges of consecutive traces that share the same UUID. */
1609 while (range_start_idx
< traces
->len
) {
1611 struct ctf_fs_trace
*range_start_trace
= g_ptr_array_index(traces
, range_start_idx
);
1613 /* Exclusive end of range. */
1614 guint range_end_exc_idx
= range_start_idx
+ 1;
1616 while (range_end_exc_idx
< traces
->len
) {
1617 struct ctf_fs_trace
*this_trace
= g_ptr_array_index(traces
, range_end_exc_idx
);
1619 if (!range_start_trace
->metadata
->tc
->is_uuid_set
||
1620 (bt_uuid_compare(range_start_trace
->metadata
->tc
->uuid
, this_trace
->metadata
->tc
->uuid
) != 0)) {
1624 range_end_exc_idx
++;
1627 /* If we have two or more traces with matching UUIDs, merge them. */
1628 range_len
= range_end_exc_idx
- range_start_idx
;
1629 if (range_len
> 1) {
1630 struct ctf_fs_trace
**range_start
= (struct ctf_fs_trace
**) &traces
->pdata
[range_start_idx
];
1631 ret
= merge_ctf_fs_traces(range_start
, range_len
);
1638 range_start_idx
= range_end_exc_idx
;
1641 /* Clear any NULL slot (traces that got merged in another one) in the array. */
1642 for (i
= 0; i
< traces
->len
;) {
1643 if (g_ptr_array_index(traces
, i
) == NULL
) {
1644 g_ptr_array_remove_index_fast(traces
, i
);
1650 BT_ASSERT(num_traces
== traces
->len
);
1656 int ctf_fs_component_create_ctf_fs_traces(bt_self_component_source
*self_comp
,
1657 struct ctf_fs_component
*ctf_fs
,
1658 const bt_value
*paths_value
)
1663 for (i
= 0; i
< bt_value_array_get_size(paths_value
); i
++) {
1664 const bt_value
*path_value
= bt_value_array_borrow_element_by_index_const(paths_value
, i
);
1665 const char *path
= bt_value_string_get(path_value
);
1667 ret
= ctf_fs_component_create_ctf_fs_traces_one_root(self_comp
, ctf_fs
, path
);
1673 ret
= merge_traces_with_same_uuid(ctf_fs
);
1680 GString
*get_stream_instance_unique_name(
1681 struct ctf_fs_ds_file_group
*ds_file_group
)
1684 struct ctf_fs_ds_file_info
*ds_file_info
;
1686 name
= g_string_new(NULL
);
1692 * If there's more than one stream file in the stream file
1693 * group, the first (earliest) stream file's path is used as
1694 * the stream's unique name.
1696 BT_ASSERT(ds_file_group
->ds_file_infos
->len
> 0);
1697 ds_file_info
= g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
1698 g_string_assign(name
, ds_file_info
->path
->str
);
1704 /* Create the IR stream objects for ctf_fs_trace. */
1707 int create_streams_for_trace(struct ctf_fs_trace
*ctf_fs_trace
)
1710 GString
*name
= NULL
;
1713 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
1714 struct ctf_fs_ds_file_group
*ds_file_group
=
1715 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
1716 name
= get_stream_instance_unique_name(ds_file_group
);
1722 if (ds_file_group
->sc
->ir_sc
) {
1723 BT_ASSERT(ctf_fs_trace
->trace
);
1725 if (ds_file_group
->stream_id
== UINT64_C(-1)) {
1726 /* No stream ID: use 0 */
1727 ds_file_group
->stream
= bt_stream_create_with_id(
1728 ds_file_group
->sc
->ir_sc
,
1729 ctf_fs_trace
->trace
,
1730 ctf_fs_trace
->next_stream_id
);
1731 ctf_fs_trace
->next_stream_id
++;
1733 /* Specific stream ID */
1734 ds_file_group
->stream
= bt_stream_create_with_id(
1735 ds_file_group
->sc
->ir_sc
,
1736 ctf_fs_trace
->trace
,
1737 (uint64_t) ds_file_group
->stream_id
);
1740 ds_file_group
->stream
= NULL
;
1743 if (!ds_file_group
->stream
) {
1744 BT_LOGE("Cannot create stream for DS file group: "
1745 "addr=%p, stream-name=\"%s\"",
1746 ds_file_group
, name
->str
);
1750 ret
= bt_stream_set_name(ds_file_group
->stream
,
1753 BT_LOGE("Cannot set stream's name: "
1754 "addr=%p, stream-name=\"%s\"",
1755 ds_file_group
->stream
, name
->str
);
1759 g_string_free(name
, TRUE
);
1772 g_string_free(name
, TRUE
);
1778 * Validate the "paths" parameter passed to this component. It must be
1779 * present, and it must be an array of strings.
1783 bool validate_paths_parameter(const bt_value
*paths
)
1790 BT_LOGE("missing \"paths\" parameter");
1794 type
= bt_value_get_type(paths
);
1795 if (type
!= BT_VALUE_TYPE_ARRAY
) {
1796 BT_LOGE("`paths` parameter: expecting array value: type=%s",
1797 bt_common_value_type_string(type
));
1801 for (i
= 0; i
< bt_value_array_get_size(paths
); i
++) {
1802 const bt_value
*elem
;
1804 elem
= bt_value_array_borrow_element_by_index_const(paths
, i
);
1805 type
= bt_value_get_type(elem
);
1806 if (type
!= BT_VALUE_TYPE_STRING
) {
1807 BT_LOGE("`paths` parameter: expecting string value: index=%" PRIu64
", type=%s",
1808 i
, bt_common_value_type_string(type
));
1823 bool read_src_fs_parameters(const bt_value
*params
,
1824 const bt_value
**paths
, struct ctf_fs_component
*ctf_fs
) {
1826 const bt_value
*value
;
1828 /* paths parameter */
1829 *paths
= bt_value_map_borrow_entry_value_const(params
, "paths");
1830 if (!validate_paths_parameter(*paths
)) {
1834 /* clock-class-offset-s parameter */
1835 value
= bt_value_map_borrow_entry_value_const(params
,
1836 "clock-class-offset-s");
1838 if (!bt_value_is_signed_integer(value
)) {
1839 BT_LOGE("clock-class-offset-s must be an integer");
1842 ctf_fs
->metadata_config
.clock_class_offset_s
=
1843 bt_value_signed_integer_get(value
);
1846 /* clock-class-offset-ns parameter */
1847 value
= bt_value_map_borrow_entry_value_const(params
,
1848 "clock-class-offset-ns");
1850 if (!bt_value_is_signed_integer(value
)) {
1851 BT_LOGE("clock-class-offset-ns must be an integer");
1854 ctf_fs
->metadata_config
.clock_class_offset_ns
=
1855 bt_value_signed_integer_get(value
);
1870 struct ctf_fs_component
*ctf_fs_create(
1871 bt_self_component_source
*self_comp
,
1872 const bt_value
*params
)
1874 struct ctf_fs_component
*ctf_fs
= NULL
;
1876 const bt_value
*paths_value
;
1878 ctf_fs
= ctf_fs_component_create();
1883 if (!read_src_fs_parameters(params
, &paths_value
, ctf_fs
)) {
1887 bt_self_component_set_data(
1888 bt_self_component_source_as_self_component(self_comp
),
1892 * We don't need to get a new reference here because as long as
1893 * our private ctf_fs_component object exists, the containing
1894 * private component should also exist.
1896 ctf_fs
->self_comp
= self_comp
;
1898 if (ctf_fs_component_create_ctf_fs_traces(self_comp
, ctf_fs
, paths_value
)) {
1902 for (i
= 0; i
< ctf_fs
->traces
->len
; i
++) {
1903 struct ctf_fs_trace
*trace
= g_ptr_array_index(ctf_fs
->traces
, i
);
1905 if (create_streams_for_trace(trace
)) {
1909 if (create_ports_for_trace(ctf_fs
, trace
)) {
1917 ctf_fs_destroy(ctf_fs
);
1919 bt_self_component_set_data(
1920 bt_self_component_source_as_self_component(self_comp
),
1928 bt_self_component_status
ctf_fs_init(
1929 bt_self_component_source
*self_comp
,
1930 const bt_value
*params
, __attribute__((unused
)) void *init_method_data
)
1932 struct ctf_fs_component
*ctf_fs
;
1933 bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
1935 ctf_fs
= ctf_fs_create(self_comp
, params
);
1937 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
1944 bt_query_status
ctf_fs_query(
1945 bt_self_component_class_source
*comp_class
,
1946 const bt_query_executor
*query_exec
,
1947 const char *object
, const bt_value
*params
,
1948 const bt_value
**result
)
1950 bt_query_status status
= BT_QUERY_STATUS_OK
;
1952 if (!strcmp(object
, "metadata-info")) {
1953 status
= metadata_info_query(comp_class
, params
, result
);
1954 } else if (!strcmp(object
, "trace-info")) {
1955 status
= trace_info_query(comp_class
, params
, result
);
1957 BT_LOGE("Unknown query object `%s`", object
);
1958 status
= BT_QUERY_STATUS_INVALID_OBJECT
;