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"
31 #include "plugins/plugins-common.h"
33 #include "common/assert.h"
38 #include "data-stream-file.h"
40 #include "../common/metadata/decoder.h"
41 #include "../common/msg-iter/msg-iter.h"
42 #include "../common/utils/utils.h"
45 #define BT_LOG_TAG "PLUGIN-CTF-FS-SRC"
49 int msg_iter_data_set_current_ds_file(struct ctf_fs_msg_iter_data
*msg_iter_data
)
51 struct ctf_fs_ds_file_info
*ds_file_info
;
54 BT_ASSERT(msg_iter_data
->ds_file_info_index
<
55 msg_iter_data
->ds_file_group
->ds_file_infos
->len
);
56 ds_file_info
= g_ptr_array_index(
57 msg_iter_data
->ds_file_group
->ds_file_infos
,
58 msg_iter_data
->ds_file_info_index
);
60 ctf_fs_ds_file_destroy(msg_iter_data
->ds_file
);
61 msg_iter_data
->ds_file
= ctf_fs_ds_file_create(
62 msg_iter_data
->ds_file_group
->ctf_fs_trace
,
63 msg_iter_data
->pc_msg_iter
,
64 msg_iter_data
->msg_iter
,
65 msg_iter_data
->ds_file_group
->stream
,
66 ds_file_info
->path
->str
);
67 if (!msg_iter_data
->ds_file
) {
75 void ctf_fs_msg_iter_data_destroy(
76 struct ctf_fs_msg_iter_data
*msg_iter_data
)
82 ctf_fs_ds_file_destroy(msg_iter_data
->ds_file
);
84 if (msg_iter_data
->msg_iter
) {
85 bt_msg_iter_destroy(msg_iter_data
->msg_iter
);
88 g_free(msg_iter_data
);
92 void set_msg_iter_emits_stream_beginning_end_messages(
93 struct ctf_fs_msg_iter_data
*msg_iter_data
)
95 bt_msg_iter_set_emit_stream_beginning_message(
96 msg_iter_data
->ds_file
->msg_iter
,
97 msg_iter_data
->ds_file_info_index
== 0);
98 bt_msg_iter_set_emit_stream_end_message(
99 msg_iter_data
->ds_file
->msg_iter
,
100 msg_iter_data
->ds_file_info_index
==
101 msg_iter_data
->ds_file_group
->ds_file_infos
->len
- 1);
105 bt_self_message_iterator_status
ctf_fs_iterator_next_one(
106 struct ctf_fs_msg_iter_data
*msg_iter_data
,
107 const bt_message
**out_msg
)
109 bt_self_message_iterator_status status
;
111 BT_ASSERT(msg_iter_data
->ds_file
);
116 status
= ctf_fs_ds_file_next(msg_iter_data
->ds_file
, &msg
);
118 case BT_SELF_MESSAGE_ITERATOR_STATUS_OK
:
122 case BT_SELF_MESSAGE_ITERATOR_STATUS_END
:
126 if (msg_iter_data
->ds_file_info_index
==
127 msg_iter_data
->ds_file_group
->ds_file_infos
->len
- 1) {
128 /* End of all group's stream files */
132 msg_iter_data
->ds_file_info_index
++;
133 bt_msg_iter_reset_for_next_stream_file(
134 msg_iter_data
->msg_iter
);
135 set_msg_iter_emits_stream_beginning_end_messages(
139 * Open and start reading the next stream file
140 * within our stream file group.
142 ret
= msg_iter_data_set_current_ds_file(msg_iter_data
);
144 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
148 /* Continue the loop to get the next message */
161 bt_self_message_iterator_status
ctf_fs_iterator_next(
162 bt_self_message_iterator
*iterator
,
163 bt_message_array_const msgs
, uint64_t capacity
,
166 bt_self_message_iterator_status status
=
167 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
168 struct ctf_fs_msg_iter_data
*msg_iter_data
=
169 bt_self_message_iterator_get_data(iterator
);
172 while (i
< capacity
&& status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
173 status
= ctf_fs_iterator_next_one(msg_iter_data
, &msgs
[i
]);
174 if (status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
181 * Even if ctf_fs_iterator_next_one() returned something
182 * else than BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
183 * accumulated message objects in the output
184 * message array, so we need to return
185 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they are
186 * transfered to downstream. This other status occurs
187 * again the next time muxer_msg_iter_do_next() is
188 * called, possibly without any accumulated
189 * message, in which case we'll return it.
192 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
199 int ctf_fs_iterator_reset(struct ctf_fs_msg_iter_data
*msg_iter_data
)
203 msg_iter_data
->ds_file_info_index
= 0;
204 ret
= msg_iter_data_set_current_ds_file(msg_iter_data
);
209 bt_msg_iter_reset(msg_iter_data
->msg_iter
);
210 set_msg_iter_emits_stream_beginning_end_messages(msg_iter_data
);
217 bt_self_message_iterator_status
ctf_fs_iterator_seek_beginning(
218 bt_self_message_iterator
*it
)
220 struct ctf_fs_msg_iter_data
*msg_iter_data
=
221 bt_self_message_iterator_get_data(it
);
222 bt_self_message_iterator_status status
=
223 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
225 BT_ASSERT(msg_iter_data
);
226 if (ctf_fs_iterator_reset(msg_iter_data
)) {
227 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
234 void ctf_fs_iterator_finalize(bt_self_message_iterator
*it
)
236 ctf_fs_msg_iter_data_destroy(
237 bt_self_message_iterator_get_data(it
));
241 bt_self_message_iterator_status
ctf_fs_iterator_init(
242 bt_self_message_iterator
*self_msg_iter
,
243 bt_self_component_source
*self_comp
,
244 bt_self_component_port_output
*self_port
)
246 struct ctf_fs_port_data
*port_data
;
247 struct ctf_fs_msg_iter_data
*msg_iter_data
= NULL
;
248 bt_self_message_iterator_status ret
=
249 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
251 port_data
= bt_self_component_port_get_data(
252 bt_self_component_port_output_as_self_component_port(
254 BT_ASSERT(port_data
);
255 msg_iter_data
= g_new0(struct ctf_fs_msg_iter_data
, 1);
256 if (!msg_iter_data
) {
257 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
261 msg_iter_data
->pc_msg_iter
= self_msg_iter
;
262 msg_iter_data
->msg_iter
= bt_msg_iter_create(
263 port_data
->ds_file_group
->ctf_fs_trace
->metadata
->tc
,
264 bt_common_get_page_size() * 8,
265 ctf_fs_ds_file_medops
, NULL
);
266 if (!msg_iter_data
->msg_iter
) {
267 BT_LOGE_STR("Cannot create a CTF message iterator.");
268 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
272 msg_iter_data
->ds_file_group
= port_data
->ds_file_group
;
273 if (ctf_fs_iterator_reset(msg_iter_data
)) {
274 ret
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
278 bt_self_message_iterator_set_data(self_msg_iter
,
280 if (ret
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
284 msg_iter_data
= NULL
;
288 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
291 ctf_fs_msg_iter_data_destroy(msg_iter_data
);
296 void ctf_fs_destroy(struct ctf_fs_component
*ctf_fs
)
302 if (ctf_fs
->traces
) {
303 g_ptr_array_free(ctf_fs
->traces
, TRUE
);
306 if (ctf_fs
->port_data
) {
307 g_ptr_array_free(ctf_fs
->port_data
, TRUE
);
314 void port_data_destroy(struct ctf_fs_port_data
*port_data
)
324 void port_data_destroy_notifier(void *data
) {
325 port_data_destroy(data
);
329 void ctf_fs_trace_destroy(struct ctf_fs_trace
*ctf_fs_trace
)
335 if (ctf_fs_trace
->ds_file_groups
) {
336 g_ptr_array_free(ctf_fs_trace
->ds_file_groups
, TRUE
);
339 BT_TRACE_PUT_REF_AND_RESET(ctf_fs_trace
->trace
);
341 if (ctf_fs_trace
->path
) {
342 g_string_free(ctf_fs_trace
->path
, TRUE
);
345 if (ctf_fs_trace
->name
) {
346 g_string_free(ctf_fs_trace
->name
, TRUE
);
349 if (ctf_fs_trace
->metadata
) {
350 ctf_fs_metadata_fini(ctf_fs_trace
->metadata
);
351 g_free(ctf_fs_trace
->metadata
);
354 g_free(ctf_fs_trace
);
358 void ctf_fs_trace_destroy_notifier(void *data
)
360 struct ctf_fs_trace
*trace
= data
;
361 ctf_fs_trace_destroy(trace
);
364 struct ctf_fs_component
*ctf_fs_component_create(void)
366 struct ctf_fs_component
*ctf_fs
;
368 ctf_fs
= g_new0(struct ctf_fs_component
, 1);
374 g_ptr_array_new_with_free_func(port_data_destroy_notifier
);
375 if (!ctf_fs
->port_data
) {
380 g_ptr_array_new_with_free_func(ctf_fs_trace_destroy_notifier
);
381 if (!ctf_fs
->traces
) {
389 ctf_fs_destroy(ctf_fs
);
396 void ctf_fs_finalize(bt_self_component_source
*component
)
398 ctf_fs_destroy(bt_self_component_get_data(
399 bt_self_component_source_as_self_component(component
)));
402 gchar
*ctf_fs_make_port_name(struct ctf_fs_ds_file_group
*ds_file_group
)
404 GString
*name
= g_string_new(NULL
);
407 * The unique port name is generated by concatenating unique identifiers
415 /* For the trace, use the uuid if present, else the path. */
416 if (ds_file_group
->ctf_fs_trace
->metadata
->tc
->is_uuid_set
) {
417 char uuid_str
[BABELTRACE_UUID_STR_LEN
];
419 bt_uuid_unparse(ds_file_group
->ctf_fs_trace
->metadata
->tc
->uuid
, uuid_str
);
420 g_string_assign(name
, uuid_str
);
422 g_string_assign(name
, ds_file_group
->ctf_fs_trace
->path
->str
);
426 * For the stream class, use the id if present. We can omit this field
427 * otherwise, as there will only be a single stream class.
429 if (ds_file_group
->sc
->id
!= UINT64_C(-1)) {
430 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->sc
->id
);
433 /* For the stream, use the id if present, else, use the path. */
434 if (ds_file_group
->stream_id
!= UINT64_C(-1)) {
435 g_string_append_printf(name
, " | %" PRIu64
, ds_file_group
->stream_id
);
437 BT_ASSERT(ds_file_group
->ds_file_infos
->len
== 1);
438 struct ctf_fs_ds_file_info
*ds_file_info
=
439 g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
440 g_string_append_printf(name
, " | %s", ds_file_info
->path
->str
);
443 return g_string_free(name
, FALSE
);
447 int create_one_port_for_trace(struct ctf_fs_component
*ctf_fs
,
448 struct ctf_fs_trace
*ctf_fs_trace
,
449 struct ctf_fs_ds_file_group
*ds_file_group
)
452 struct ctf_fs_port_data
*port_data
= NULL
;
455 port_name
= ctf_fs_make_port_name(ds_file_group
);
460 BT_LOGD("Creating one port named `%s`", port_name
);
462 /* Create output port for this file */
463 port_data
= g_new0(struct ctf_fs_port_data
, 1);
468 port_data
->ctf_fs
= ctf_fs
;
469 port_data
->ds_file_group
= ds_file_group
;
470 ret
= bt_self_component_source_add_output_port(
471 ctf_fs
->self_comp
, port_name
, port_data
, NULL
);
476 g_ptr_array_add(ctf_fs
->port_data
, port_data
);
488 port_data_destroy(port_data
);
493 int create_ports_for_trace(struct ctf_fs_component
*ctf_fs
,
494 struct ctf_fs_trace
*ctf_fs_trace
)
499 /* Create one output port for each stream file group */
500 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
501 struct ctf_fs_ds_file_group
*ds_file_group
=
502 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
504 ret
= create_one_port_for_trace(ctf_fs
, ctf_fs_trace
,
507 BT_LOGE("Cannot create output port.");
517 void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info
*ds_file_info
)
523 if (ds_file_info
->path
) {
524 g_string_free(ds_file_info
->path
, TRUE
);
527 g_free(ds_file_info
);
531 struct ctf_fs_ds_file_info
*ctf_fs_ds_file_info_create(const char *path
,
534 struct ctf_fs_ds_file_info
*ds_file_info
;
536 ds_file_info
= g_new0(struct ctf_fs_ds_file_info
, 1);
541 ds_file_info
->path
= g_string_new(path
);
542 if (!ds_file_info
->path
) {
543 ctf_fs_ds_file_info_destroy(ds_file_info
);
548 ds_file_info
->begin_ns
= begin_ns
;
555 void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group
*ds_file_group
)
557 if (!ds_file_group
) {
561 if (ds_file_group
->ds_file_infos
) {
562 g_ptr_array_free(ds_file_group
->ds_file_infos
, TRUE
);
565 if (ds_file_group
->index
) {
566 if (ds_file_group
->index
->entries
) {
567 g_ptr_array_free(ds_file_group
->index
->entries
, TRUE
);
569 g_free(ds_file_group
->index
);
572 bt_stream_put_ref(ds_file_group
->stream
);
573 g_free(ds_file_group
);
577 struct ctf_fs_ds_file_group
*ctf_fs_ds_file_group_create(
578 struct ctf_fs_trace
*ctf_fs_trace
,
579 struct ctf_stream_class
*sc
,
580 uint64_t stream_instance_id
,
581 struct ctf_fs_ds_index
*index
)
583 struct ctf_fs_ds_file_group
*ds_file_group
;
585 ds_file_group
= g_new0(struct ctf_fs_ds_file_group
, 1);
586 if (!ds_file_group
) {
590 ds_file_group
->ds_file_infos
= g_ptr_array_new_with_free_func(
591 (GDestroyNotify
) ctf_fs_ds_file_info_destroy
);
592 if (!ds_file_group
->ds_file_infos
) {
596 ds_file_group
->index
= index
;
598 ds_file_group
->stream_id
= stream_instance_id
;
600 ds_file_group
->sc
= sc
;
601 ds_file_group
->ctf_fs_trace
= ctf_fs_trace
;
605 ctf_fs_ds_file_group_destroy(ds_file_group
);
606 ctf_fs_ds_index_destroy(index
);
607 ds_file_group
= NULL
;
610 return ds_file_group
;
613 /* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */
615 void array_insert(GPtrArray
*array
, gpointer element
, size_t pos
)
617 size_t original_array_len
= array
->len
;
619 /* Allocate an unused element at the end of the array. */
620 g_ptr_array_add(array
, NULL
);
622 /* If we are not inserting at the end, move the elements by one. */
623 if (pos
< original_array_len
) {
624 memmove(&(array
->pdata
[pos
+ 1]),
625 &(array
->pdata
[pos
]),
626 (original_array_len
- pos
) * sizeof(gpointer
));
629 /* Insert the value. */
630 array
->pdata
[pos
] = element
;
634 * Insert ds_file_info in ds_file_group's list of ds_file_infos at the right
635 * place to keep it sorted.
639 void ds_file_group_insert_ds_file_info_sorted(
640 struct ctf_fs_ds_file_group
*ds_file_group
,
641 struct ctf_fs_ds_file_info
*ds_file_info
)
645 /* Find the spot where to insert this ds_file_info. */
646 for (i
= 0; i
< ds_file_group
->ds_file_infos
->len
; i
++) {
647 struct ctf_fs_ds_file_info
*other_ds_file_info
=
648 g_ptr_array_index(ds_file_group
->ds_file_infos
, i
);
650 if (ds_file_info
->begin_ns
< other_ds_file_info
->begin_ns
) {
655 array_insert(ds_file_group
->ds_file_infos
, ds_file_info
, i
);
659 void ds_file_group_insert_ds_index_entry_sorted(
660 struct ctf_fs_ds_file_group
*ds_file_group
,
661 struct ctf_fs_ds_index_entry
*entry
)
665 /* Find the spot where to insert this index entry. */
666 for (i
= 0; i
< ds_file_group
->index
->entries
->len
; i
++) {
667 struct ctf_fs_ds_index_entry
*other_entry
= g_ptr_array_index(
668 ds_file_group
->index
->entries
, i
);
670 if (entry
->timestamp_begin_ns
< other_entry
->timestamp_begin_ns
) {
675 array_insert(ds_file_group
->index
->entries
, entry
, i
);
679 * Create a new ds_file_info using the provided path, begin_ns and index, then
680 * add it to ds_file_group's list of ds_file_infos.
684 int ctf_fs_ds_file_group_add_ds_file_info(
685 struct ctf_fs_ds_file_group
*ds_file_group
,
686 const char *path
, int64_t begin_ns
)
688 struct ctf_fs_ds_file_info
*ds_file_info
;
691 ds_file_info
= ctf_fs_ds_file_info_create(path
, begin_ns
);
696 ds_file_group_insert_ds_file_info_sorted(ds_file_group
, ds_file_info
);
702 ctf_fs_ds_file_info_destroy(ds_file_info
);
709 int add_ds_file_to_ds_file_group(struct ctf_fs_trace
*ctf_fs_trace
,
712 int64_t stream_instance_id
= -1;
713 int64_t begin_ns
= -1;
714 struct ctf_fs_ds_file_group
*ds_file_group
= NULL
;
715 bool add_group
= false;
718 struct ctf_fs_ds_file
*ds_file
= NULL
;
719 struct ctf_fs_ds_index
*index
= NULL
;
720 struct bt_msg_iter
*msg_iter
= NULL
;
721 struct ctf_stream_class
*sc
= NULL
;
722 struct bt_msg_iter_packet_properties props
;
724 msg_iter
= bt_msg_iter_create(ctf_fs_trace
->metadata
->tc
,
725 bt_common_get_page_size() * 8, ctf_fs_ds_file_medops
, NULL
);
727 BT_LOGE_STR("Cannot create a CTF message iterator.");
731 ds_file
= ctf_fs_ds_file_create(ctf_fs_trace
, NULL
, msg_iter
,
737 ret
= bt_msg_iter_get_packet_properties(ds_file
->msg_iter
, &props
);
739 BT_LOGE("Cannot get stream file's first packet's header and context fields (`%s`).",
744 sc
= ctf_trace_class_borrow_stream_class_by_id(ds_file
->metadata
->tc
,
745 props
.stream_class_id
);
747 stream_instance_id
= props
.data_stream_id
;
749 if (props
.snapshots
.beginning_clock
!= UINT64_C(-1)) {
750 BT_ASSERT(sc
->default_clock_class
);
751 ret
= bt_util_clock_cycles_to_ns_from_origin(
752 props
.snapshots
.beginning_clock
,
753 sc
->default_clock_class
->frequency
,
754 sc
->default_clock_class
->offset_seconds
,
755 sc
->default_clock_class
->offset_cycles
, &begin_ns
);
757 BT_LOGE("Cannot convert clock cycles to nanoseconds from origin (`%s`).",
763 index
= ctf_fs_ds_file_build_index(ds_file
);
765 BT_LOGW("Failed to index CTF stream file \'%s\'",
766 ds_file
->file
->path
->str
);
769 if (begin_ns
== -1) {
771 * No beggining timestamp to sort the stream files
772 * within a stream file group, so consider that this
773 * file must be the only one within its group.
775 stream_instance_id
= -1;
778 if (stream_instance_id
== -1) {
780 * No stream instance ID or no beginning timestamp:
781 * create a unique stream file group for this stream
782 * file because, even if there's a stream instance ID,
783 * there's no timestamp to order the file within its
786 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
787 sc
, UINT64_C(-1), index
);
788 /* Ownership of index is transferred. */
791 if (!ds_file_group
) {
795 ret
= ctf_fs_ds_file_group_add_ds_file_info(ds_file_group
,
805 BT_ASSERT(stream_instance_id
!= -1);
806 BT_ASSERT(begin_ns
!= -1);
808 /* Find an existing stream file group with this ID */
809 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
810 ds_file_group
= g_ptr_array_index(
811 ctf_fs_trace
->ds_file_groups
, i
);
813 if (ds_file_group
->sc
== sc
&&
814 ds_file_group
->stream_id
==
815 stream_instance_id
) {
819 ds_file_group
= NULL
;
822 if (!ds_file_group
) {
823 ds_file_group
= ctf_fs_ds_file_group_create(ctf_fs_trace
,
824 sc
, stream_instance_id
, index
);
825 /* Ownership of index is transferred. */
827 if (!ds_file_group
) {
834 ret
= ctf_fs_ds_file_group_add_ds_file_info(ds_file_group
, path
,
843 ctf_fs_ds_file_group_destroy(ds_file_group
);
844 ds_file_group
= NULL
;
848 if (add_group
&& ds_file_group
) {
849 g_ptr_array_add(ctf_fs_trace
->ds_file_groups
, ds_file_group
);
852 ctf_fs_ds_file_destroy(ds_file
);
855 bt_msg_iter_destroy(msg_iter
);
858 ctf_fs_ds_index_destroy(index
);
863 int create_ds_file_groups(struct ctf_fs_trace
*ctf_fs_trace
)
866 const char *basename
;
867 GError
*error
= NULL
;
870 /* Check each file in the path directory, except specific ones */
871 dir
= g_dir_open(ctf_fs_trace
->path
->str
, 0, &error
);
873 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
874 ctf_fs_trace
->path
->str
, error
->message
,
879 while ((basename
= g_dir_read_name(dir
))) {
880 struct ctf_fs_file
*file
;
882 if (!strcmp(basename
, CTF_FS_METADATA_FILENAME
)) {
883 /* Ignore the metadata stream. */
884 BT_LOGD("Ignoring metadata file `%s" G_DIR_SEPARATOR_S
"%s`",
885 ctf_fs_trace
->path
->str
, basename
);
889 if (basename
[0] == '.') {
890 BT_LOGD("Ignoring hidden file `%s" G_DIR_SEPARATOR_S
"%s`",
891 ctf_fs_trace
->path
->str
, basename
);
895 /* Create the file. */
896 file
= ctf_fs_file_create();
898 BT_LOGE("Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S
"%s`",
899 ctf_fs_trace
->path
->str
, basename
);
903 /* Create full path string. */
904 g_string_append_printf(file
->path
, "%s" G_DIR_SEPARATOR_S
"%s",
905 ctf_fs_trace
->path
->str
, basename
);
906 if (!g_file_test(file
->path
->str
, G_FILE_TEST_IS_REGULAR
)) {
907 BT_LOGD("Ignoring non-regular file `%s`",
909 ctf_fs_file_destroy(file
);
914 ret
= ctf_fs_file_open(file
, "rb");
916 BT_LOGE("Cannot open stream file `%s`", file
->path
->str
);
920 if (file
->size
== 0) {
921 /* Skip empty stream. */
922 BT_LOGD("Ignoring empty file `%s`", file
->path
->str
);
923 ctf_fs_file_destroy(file
);
927 ret
= add_ds_file_to_ds_file_group(ctf_fs_trace
,
930 BT_LOGE("Cannot add stream file `%s` to stream file group",
932 ctf_fs_file_destroy(file
);
936 ctf_fs_file_destroy(file
);
958 int set_trace_name(bt_trace
*trace
, const char *name_suffix
)
961 const bt_trace_class
*tc
= bt_trace_borrow_class_const(trace
);
965 name
= g_string_new(NULL
);
967 BT_LOGE_STR("Failed to allocate a GString.");
973 * Check if we have a trace environment string value named `hostname`.
974 * If so, use it as the trace name's prefix.
976 val
= bt_trace_class_borrow_environment_entry_value_by_name_const(
978 if (val
&& bt_value_is_string(val
)) {
979 g_string_append(name
, bt_value_string_get(val
));
982 g_string_append_c(name
, G_DIR_SEPARATOR
);
987 g_string_append(name
, name_suffix
);
990 ret
= bt_trace_set_name(trace
, name
->str
);
999 g_string_free(name
, TRUE
);
1006 struct ctf_fs_trace
*ctf_fs_trace_create(bt_self_component_source
*self_comp
,
1007 const char *path
, const char *name
,
1008 struct ctf_fs_metadata_config
*metadata_config
)
1010 struct ctf_fs_trace
*ctf_fs_trace
;
1013 ctf_fs_trace
= g_new0(struct ctf_fs_trace
, 1);
1014 if (!ctf_fs_trace
) {
1018 ctf_fs_trace
->path
= g_string_new(path
);
1019 if (!ctf_fs_trace
->path
) {
1023 ctf_fs_trace
->name
= g_string_new(name
);
1024 if (!ctf_fs_trace
->name
) {
1028 ctf_fs_trace
->metadata
= g_new0(struct ctf_fs_metadata
, 1);
1029 if (!ctf_fs_trace
->metadata
) {
1033 ctf_fs_metadata_init(ctf_fs_trace
->metadata
);
1034 ctf_fs_trace
->ds_file_groups
= g_ptr_array_new_with_free_func(
1035 (GDestroyNotify
) ctf_fs_ds_file_group_destroy
);
1036 if (!ctf_fs_trace
->ds_file_groups
) {
1040 ret
= ctf_fs_metadata_set_trace_class(self_comp
,
1041 ctf_fs_trace
, metadata_config
);
1046 if (ctf_fs_trace
->metadata
->trace_class
) {
1047 ctf_fs_trace
->trace
=
1048 bt_trace_create(ctf_fs_trace
->metadata
->trace_class
);
1049 if (!ctf_fs_trace
->trace
) {
1054 if (ctf_fs_trace
->trace
) {
1055 ret
= set_trace_name(ctf_fs_trace
->trace
, name
);
1061 ret
= create_ds_file_groups(ctf_fs_trace
);
1069 ctf_fs_trace_destroy(ctf_fs_trace
);
1070 ctf_fs_trace
= NULL
;
1073 return ctf_fs_trace
;
1077 int path_is_ctf_trace(const char *path
)
1079 GString
*metadata_path
= g_string_new(NULL
);
1082 if (!metadata_path
) {
1087 g_string_printf(metadata_path
, "%s" G_DIR_SEPARATOR_S
"%s", path
, CTF_FS_METADATA_FILENAME
);
1089 if (g_file_test(metadata_path
->str
, G_FILE_TEST_IS_REGULAR
)) {
1095 g_string_free(metadata_path
, TRUE
);
1100 int add_trace_path(GList
**trace_paths
, const char *path
)
1102 GString
*norm_path
= NULL
;
1105 norm_path
= bt_common_normalize_path(path
, NULL
);
1107 BT_LOGE("Failed to normalize path `%s`.", path
);
1112 // FIXME: Remove or ifdef for __MINGW32__
1113 if (strcmp(norm_path
->str
, "/") == 0) {
1114 BT_LOGE("Opening a trace in `/` is not supported.");
1119 *trace_paths
= g_list_prepend(*trace_paths
, norm_path
);
1120 BT_ASSERT(*trace_paths
);
1125 g_string_free(norm_path
, TRUE
);
1132 int ctf_fs_find_traces(GList
**trace_paths
, const char *start_path
)
1135 GError
*error
= NULL
;
1137 const char *basename
= NULL
;
1139 /* Check if the starting path is a CTF trace itself */
1140 ret
= path_is_ctf_trace(start_path
);
1147 * Stop recursion: a CTF trace cannot contain another
1150 ret
= add_trace_path(trace_paths
, start_path
);
1154 /* Look for subdirectories */
1155 if (!g_file_test(start_path
, G_FILE_TEST_IS_DIR
)) {
1156 /* Starting path is not a directory: end of recursion */
1160 dir
= g_dir_open(start_path
, 0, &error
);
1162 if (error
->code
== G_FILE_ERROR_ACCES
) {
1163 BT_LOGD("Cannot open directory `%s`: %s (code %d): continuing",
1164 start_path
, error
->message
, error
->code
);
1168 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
1169 start_path
, error
->message
, error
->code
);
1174 while ((basename
= g_dir_read_name(dir
))) {
1175 GString
*sub_path
= g_string_new(NULL
);
1182 g_string_printf(sub_path
, "%s" G_DIR_SEPARATOR_S
"%s", start_path
, basename
);
1183 ret
= ctf_fs_find_traces(trace_paths
, sub_path
->str
);
1184 g_string_free(sub_path
, TRUE
);
1196 g_error_free(error
);
1203 GList
*ctf_fs_create_trace_names(GList
*trace_paths
, const char *base_path
) {
1204 GList
*trace_names
= NULL
;
1206 const char *last_sep
;
1210 * At this point we know that all the trace paths are
1211 * normalized, and so is the base path. This means that
1212 * they are absolute and they don't end with a separator.
1213 * We can simply find the location of the last separator
1214 * in the base path, which gives us the name of the actual
1215 * directory to look into, and use this location as the
1216 * start of each trace name within each trace path.
1220 * Base path: /home/user/my-traces/some-trace
1222 * - /home/user/my-traces/some-trace/host1/trace1
1223 * - /home/user/my-traces/some-trace/host1/trace2
1224 * - /home/user/my-traces/some-trace/host2/trace
1225 * - /home/user/my-traces/some-trace/other-trace
1227 * In this case the trace names are:
1229 * - some-trace/host1/trace1
1230 * - some-trace/host1/trace2
1231 * - some-trace/host2/trace
1232 * - some-trace/other-trace
1234 last_sep
= strrchr(base_path
, G_DIR_SEPARATOR
);
1236 /* We know there's at least one separator */
1237 BT_ASSERT(last_sep
);
1239 /* Distance to base */
1240 base_dist
= last_sep
- base_path
+ 1;
1242 /* Create the trace names */
1243 for (node
= trace_paths
; node
; node
= g_list_next(node
)) {
1244 GString
*trace_name
= g_string_new(NULL
);
1245 GString
*trace_path
= node
->data
;
1247 BT_ASSERT(trace_name
);
1248 g_string_assign(trace_name
, &trace_path
->str
[base_dist
]);
1249 trace_names
= g_list_append(trace_names
, trace_name
);
1255 /* Helper for ctf_fs_component_create_ctf_fs_traces, to handle a single path/root. */
1258 int ctf_fs_component_create_ctf_fs_traces_one_root(bt_self_component_source
*self_comp
,
1259 struct ctf_fs_component
*ctf_fs
,
1260 const char *path_param
)
1262 struct ctf_fs_trace
*ctf_fs_trace
= NULL
;
1264 GString
*norm_path
= NULL
;
1265 GList
*trace_paths
= NULL
;
1266 GList
*trace_names
= NULL
;
1270 norm_path
= bt_common_normalize_path(path_param
, NULL
);
1272 BT_LOGE("Failed to normalize path: `%s`.",
1277 ret
= ctf_fs_find_traces(&trace_paths
, norm_path
->str
);
1283 BT_LOGE("No CTF traces recursively found in `%s`.",
1288 trace_names
= ctf_fs_create_trace_names(trace_paths
, norm_path
->str
);
1290 BT_LOGE("Cannot create trace names from trace paths.");
1294 for (tp_node
= trace_paths
, tn_node
= trace_names
; tp_node
;
1295 tp_node
= g_list_next(tp_node
),
1296 tn_node
= g_list_next(tn_node
)) {
1297 GString
*trace_path
= tp_node
->data
;
1298 GString
*trace_name
= tn_node
->data
;
1300 ctf_fs_trace
= ctf_fs_trace_create(self_comp
,
1301 trace_path
->str
, trace_name
->str
,
1302 &ctf_fs
->metadata_config
);
1303 if (!ctf_fs_trace
) {
1304 BT_LOGE("Cannot create trace for `%s`.",
1309 g_ptr_array_add(ctf_fs
->traces
, ctf_fs_trace
);
1310 ctf_fs_trace
= NULL
;
1317 ctf_fs_trace_destroy(ctf_fs_trace
);
1320 for (tp_node
= trace_paths
; tp_node
; tp_node
= g_list_next(tp_node
)) {
1321 if (tp_node
->data
) {
1322 g_string_free(tp_node
->data
, TRUE
);
1326 for (tn_node
= trace_names
; tn_node
; tn_node
= g_list_next(tn_node
)) {
1327 if (tn_node
->data
) {
1328 g_string_free(tn_node
->data
, TRUE
);
1333 g_list_free(trace_paths
);
1337 g_list_free(trace_names
);
1341 g_string_free(norm_path
, TRUE
);
1347 /* GCompareFunc to sort traces by UUID. */
1350 gint
sort_traces_by_uuid(gconstpointer a
, gconstpointer b
)
1352 const struct ctf_fs_trace
*trace_a
= *((const struct ctf_fs_trace
**) a
);
1353 const struct ctf_fs_trace
*trace_b
= *((const struct ctf_fs_trace
**) b
);
1355 bool trace_a_has_uuid
= trace_a
->metadata
->tc
->is_uuid_set
;
1356 bool trace_b_has_uuid
= trace_b
->metadata
->tc
->is_uuid_set
;
1359 /* Order traces without uuid first. */
1360 if (!trace_a_has_uuid
&& trace_b_has_uuid
) {
1362 } else if (trace_a_has_uuid
&& !trace_b_has_uuid
) {
1364 } else if (!trace_a_has_uuid
&& !trace_b_has_uuid
) {
1367 ret
= bt_uuid_compare(trace_a
->metadata
->tc
->uuid
, trace_b
->metadata
->tc
->uuid
);
1374 * Count the number of stream and event classes defined by this trace's metadata.
1376 * This is used to determine which metadata is the "latest", out of multiple
1377 * traces sharing the same UUID. It is assumed that amongst all these metadatas,
1378 * a bigger metadata is a superset of a smaller metadata. Therefore, it is
1379 * enough to just count the classes.
1383 unsigned int metadata_count_stream_and_event_classes(struct ctf_fs_trace
*trace
)
1385 unsigned int num
= trace
->metadata
->tc
->stream_classes
->len
;
1388 for (i
= 0; i
< trace
->metadata
->tc
->stream_classes
->len
; i
++) {
1389 struct ctf_stream_class
*sc
= trace
->metadata
->tc
->stream_classes
->pdata
[i
];
1390 num
+= sc
->event_classes
->len
;
1397 * Merge the src ds_file_group into dest. This consists of merging their
1398 * ds_file_infos, making sure to keep the result sorted.
1402 void merge_ctf_fs_ds_file_groups(struct ctf_fs_ds_file_group
*dest
, struct ctf_fs_ds_file_group
*src
)
1406 for (i
= 0; i
< src
->ds_file_infos
->len
; i
++) {
1407 struct ctf_fs_ds_file_info
*ds_file_info
=
1408 g_ptr_array_index(src
->ds_file_infos
, i
);
1410 /* Ownership of the ds_file_info is transferred to dest. */
1411 g_ptr_array_index(src
->ds_file_infos
, i
) = NULL
;
1413 ds_file_group_insert_ds_file_info_sorted(dest
, ds_file_info
);
1416 /* Merge both indexes. */
1417 for (i
= 0; i
< src
->index
->entries
->len
; i
++) {
1418 struct ctf_fs_ds_index_entry
*entry
= g_ptr_array_index(
1419 src
->index
->entries
, i
);
1422 * Ownership of the ctf_fs_ds_index_entry is transferred to
1425 g_ptr_array_index(src
->index
->entries
, i
) = NULL
;
1427 ds_file_group_insert_ds_index_entry_sorted(dest
, entry
);
1430 /* Merge src_trace's data stream file groups into dest_trace's. */
1433 int merge_matching_ctf_fs_ds_file_groups(
1434 struct ctf_fs_trace
*dest_trace
,
1435 struct ctf_fs_trace
*src_trace
)
1438 GPtrArray
*dest
= dest_trace
->ds_file_groups
;
1439 GPtrArray
*src
= src_trace
->ds_file_groups
;
1444 * Save the initial length of dest: we only want to check against the
1445 * original elements in the inner loop.
1447 const guint dest_len
= dest
->len
;
1449 for (s_i
= 0; s_i
< src
->len
; s_i
++) {
1450 struct ctf_fs_ds_file_group
*src_group
= g_ptr_array_index(src
, s_i
);
1451 struct ctf_fs_ds_file_group
*dest_group
= NULL
;
1453 /* A stream instance without ID can't match a stream in the other trace. */
1454 if (src_group
->stream_id
!= -1) {
1457 /* Let's search for a matching ds_file_group in the destination. */
1458 for (d_i
= 0; d_i
< dest_len
; d_i
++) {
1459 struct ctf_fs_ds_file_group
*candidate_dest
= g_ptr_array_index(dest
, d_i
);
1461 /* Can't match a stream instance without ID. */
1462 if (candidate_dest
->stream_id
== -1) {
1467 * If the two groups have the same stream instance id
1468 * and belong to the same stream class (stream instance
1469 * ids are per-stream class), they represent the same
1472 if (candidate_dest
->stream_id
!= src_group
->stream_id
||
1473 candidate_dest
->sc
->id
!= src_group
->sc
->id
) {
1477 dest_group
= candidate_dest
;
1483 * Didn't find a friend in dest to merge our src_group into?
1484 * Create a new empty one. This can happen if a stream was
1485 * active in the source trace chunk but not in the destination
1489 struct ctf_stream_class
*sc
;
1490 struct ctf_fs_ds_index
*index
;
1492 sc
= ctf_trace_class_borrow_stream_class_by_id(
1493 dest_trace
->metadata
->tc
, src_group
->sc
->id
);
1496 index
= ctf_fs_ds_index_create();
1502 dest_group
= ctf_fs_ds_file_group_create(dest_trace
, sc
,
1503 src_group
->stream_id
, index
);
1504 /* Ownership of index is transferred. */
1511 g_ptr_array_add(dest_trace
->ds_file_groups
, dest_group
);
1514 BT_ASSERT(dest_group
);
1515 merge_ctf_fs_ds_file_groups(dest_group
, src_group
);
1523 * Collapse the given traces, which must all share the same UUID, in a single
1526 * The trace with the most expansive metadata is chosen and all other traces
1527 * are merged into that one. The array slots of all the traces that get merged
1528 * in the chosen one are set to NULL, so only the slot of the chosen trace
1533 int merge_ctf_fs_traces(struct ctf_fs_trace
**traces
, unsigned int num_traces
)
1535 unsigned int winner_count
;
1536 struct ctf_fs_trace
*winner
;
1539 char uuid_str
[BABELTRACE_UUID_STR_LEN
];
1541 BT_ASSERT(num_traces
>= 2);
1543 winner_count
= metadata_count_stream_and_event_classes(traces
[0]);
1546 /* Find the trace with the largest metadata. */
1547 for (i
= 1; i
< num_traces
; i
++) {
1548 struct ctf_fs_trace
*candidate
;
1549 unsigned int candidate_count
;
1551 candidate
= traces
[i
];
1553 /* A bit of sanity check. */
1554 BT_ASSERT(bt_uuid_compare(winner
->metadata
->tc
->uuid
, candidate
->metadata
->tc
->uuid
) == 0);
1556 candidate_count
= metadata_count_stream_and_event_classes(candidate
);
1558 if (candidate_count
> winner_count
) {
1559 winner_count
= candidate_count
;
1564 /* Merge all the other traces in the winning trace. */
1565 for (i
= 0; i
< num_traces
; i
++) {
1566 struct ctf_fs_trace
*trace
= traces
[i
];
1568 /* Don't merge the winner into itself. */
1569 if (trace
== winner
) {
1573 /* Merge trace's data stream file groups into winner's. */
1574 ret
= merge_matching_ctf_fs_ds_file_groups(winner
, trace
);
1579 /* Free the trace that got merged into winner, clear the slot in the array. */
1580 ctf_fs_trace_destroy(trace
);
1584 /* Use the string representation of the UUID as the trace name. */
1585 bt_uuid_unparse(winner
->metadata
->tc
->uuid
, uuid_str
);
1586 g_string_printf(winner
->name
, "%s", uuid_str
);
1593 * Merge all traces of `ctf_fs` that share the same UUID in a single trace.
1594 * Traces with no UUID are not merged.
1598 int merge_traces_with_same_uuid(struct ctf_fs_component
*ctf_fs
)
1600 GPtrArray
*traces
= ctf_fs
->traces
;
1601 guint range_start_idx
= 0;
1602 unsigned int num_traces
= 0;
1606 /* Sort the traces by uuid, then collapse traces with the same uuid in a single one. */
1607 g_ptr_array_sort(traces
, sort_traces_by_uuid
);
1609 /* Find ranges of consecutive traces that share the same UUID. */
1610 while (range_start_idx
< traces
->len
) {
1612 struct ctf_fs_trace
*range_start_trace
= g_ptr_array_index(traces
, range_start_idx
);
1614 /* Exclusive end of range. */
1615 guint range_end_exc_idx
= range_start_idx
+ 1;
1617 while (range_end_exc_idx
< traces
->len
) {
1618 struct ctf_fs_trace
*this_trace
= g_ptr_array_index(traces
, range_end_exc_idx
);
1620 if (!range_start_trace
->metadata
->tc
->is_uuid_set
||
1621 (bt_uuid_compare(range_start_trace
->metadata
->tc
->uuid
, this_trace
->metadata
->tc
->uuid
) != 0)) {
1625 range_end_exc_idx
++;
1628 /* If we have two or more traces with matching UUIDs, merge them. */
1629 range_len
= range_end_exc_idx
- range_start_idx
;
1630 if (range_len
> 1) {
1631 struct ctf_fs_trace
**range_start
= (struct ctf_fs_trace
**) &traces
->pdata
[range_start_idx
];
1632 ret
= merge_ctf_fs_traces(range_start
, range_len
);
1639 range_start_idx
= range_end_exc_idx
;
1642 /* Clear any NULL slot (traces that got merged in another one) in the array. */
1643 for (i
= 0; i
< traces
->len
;) {
1644 if (g_ptr_array_index(traces
, i
) == NULL
) {
1645 g_ptr_array_remove_index_fast(traces
, i
);
1651 BT_ASSERT(num_traces
== traces
->len
);
1657 int ctf_fs_component_create_ctf_fs_traces(bt_self_component_source
*self_comp
,
1658 struct ctf_fs_component
*ctf_fs
,
1659 const bt_value
*paths_value
)
1664 for (i
= 0; i
< bt_value_array_get_size(paths_value
); i
++) {
1665 const bt_value
*path_value
= bt_value_array_borrow_element_by_index_const(paths_value
, i
);
1666 const char *path
= bt_value_string_get(path_value
);
1668 ret
= ctf_fs_component_create_ctf_fs_traces_one_root(self_comp
, ctf_fs
, path
);
1674 ret
= merge_traces_with_same_uuid(ctf_fs
);
1681 GString
*get_stream_instance_unique_name(
1682 struct ctf_fs_ds_file_group
*ds_file_group
)
1685 struct ctf_fs_ds_file_info
*ds_file_info
;
1687 name
= g_string_new(NULL
);
1693 * If there's more than one stream file in the stream file
1694 * group, the first (earliest) stream file's path is used as
1695 * the stream's unique name.
1697 BT_ASSERT(ds_file_group
->ds_file_infos
->len
> 0);
1698 ds_file_info
= g_ptr_array_index(ds_file_group
->ds_file_infos
, 0);
1699 g_string_assign(name
, ds_file_info
->path
->str
);
1705 /* Create the IR stream objects for ctf_fs_trace. */
1708 int create_streams_for_trace(struct ctf_fs_trace
*ctf_fs_trace
)
1711 GString
*name
= NULL
;
1714 for (i
= 0; i
< ctf_fs_trace
->ds_file_groups
->len
; i
++) {
1715 struct ctf_fs_ds_file_group
*ds_file_group
=
1716 g_ptr_array_index(ctf_fs_trace
->ds_file_groups
, i
);
1717 name
= get_stream_instance_unique_name(ds_file_group
);
1723 if (ds_file_group
->sc
->ir_sc
) {
1724 BT_ASSERT(ctf_fs_trace
->trace
);
1726 if (ds_file_group
->stream_id
== UINT64_C(-1)) {
1727 /* No stream ID: use 0 */
1728 ds_file_group
->stream
= bt_stream_create_with_id(
1729 ds_file_group
->sc
->ir_sc
,
1730 ctf_fs_trace
->trace
,
1731 ctf_fs_trace
->next_stream_id
);
1732 ctf_fs_trace
->next_stream_id
++;
1734 /* Specific stream ID */
1735 ds_file_group
->stream
= bt_stream_create_with_id(
1736 ds_file_group
->sc
->ir_sc
,
1737 ctf_fs_trace
->trace
,
1738 (uint64_t) ds_file_group
->stream_id
);
1741 ds_file_group
->stream
= NULL
;
1744 if (!ds_file_group
->stream
) {
1745 BT_LOGE("Cannot create stream for DS file group: "
1746 "addr=%p, stream-name=\"%s\"",
1747 ds_file_group
, name
->str
);
1751 ret
= bt_stream_set_name(ds_file_group
->stream
,
1754 BT_LOGE("Cannot set stream's name: "
1755 "addr=%p, stream-name=\"%s\"",
1756 ds_file_group
->stream
, name
->str
);
1760 g_string_free(name
, TRUE
);
1773 g_string_free(name
, TRUE
);
1779 * Validate the "paths" parameter passed to this component. It must be
1780 * present, and it must be an array of strings.
1784 bool validate_paths_parameter(const bt_value
*paths
)
1791 BT_LOGE("missing \"paths\" parameter");
1795 type
= bt_value_get_type(paths
);
1796 if (type
!= BT_VALUE_TYPE_ARRAY
) {
1797 BT_LOGE("`paths` parameter: expecting array value: type=%s",
1798 bt_common_value_type_string(type
));
1802 for (i
= 0; i
< bt_value_array_get_size(paths
); i
++) {
1803 const bt_value
*elem
;
1805 elem
= bt_value_array_borrow_element_by_index_const(paths
, i
);
1806 type
= bt_value_get_type(elem
);
1807 if (type
!= BT_VALUE_TYPE_STRING
) {
1808 BT_LOGE("`paths` parameter: expecting string value: index=%" PRIu64
", type=%s",
1809 i
, bt_common_value_type_string(type
));
1824 bool read_src_fs_parameters(const bt_value
*params
,
1825 const bt_value
**paths
, struct ctf_fs_component
*ctf_fs
) {
1827 const bt_value
*value
;
1829 /* paths parameter */
1830 *paths
= bt_value_map_borrow_entry_value_const(params
, "paths");
1831 if (!validate_paths_parameter(*paths
)) {
1835 /* clock-class-offset-s parameter */
1836 value
= bt_value_map_borrow_entry_value_const(params
,
1837 "clock-class-offset-s");
1839 if (!bt_value_is_signed_integer(value
)) {
1840 BT_LOGE("clock-class-offset-s must be an integer");
1843 ctf_fs
->metadata_config
.clock_class_offset_s
=
1844 bt_value_signed_integer_get(value
);
1847 /* clock-class-offset-ns parameter */
1848 value
= bt_value_map_borrow_entry_value_const(params
,
1849 "clock-class-offset-ns");
1851 if (!bt_value_is_signed_integer(value
)) {
1852 BT_LOGE("clock-class-offset-ns must be an integer");
1855 ctf_fs
->metadata_config
.clock_class_offset_ns
=
1856 bt_value_signed_integer_get(value
);
1871 struct ctf_fs_component
*ctf_fs_create(
1872 bt_self_component_source
*self_comp
,
1873 const bt_value
*params
)
1875 struct ctf_fs_component
*ctf_fs
= NULL
;
1877 const bt_value
*paths_value
;
1879 ctf_fs
= ctf_fs_component_create();
1884 if (!read_src_fs_parameters(params
, &paths_value
, ctf_fs
)) {
1888 bt_self_component_set_data(
1889 bt_self_component_source_as_self_component(self_comp
),
1893 * We don't need to get a new reference here because as long as
1894 * our private ctf_fs_component object exists, the containing
1895 * private component should also exist.
1897 ctf_fs
->self_comp
= self_comp
;
1899 if (ctf_fs_component_create_ctf_fs_traces(self_comp
, ctf_fs
, paths_value
)) {
1903 for (i
= 0; i
< ctf_fs
->traces
->len
; i
++) {
1904 struct ctf_fs_trace
*trace
= g_ptr_array_index(ctf_fs
->traces
, i
);
1906 if (create_streams_for_trace(trace
)) {
1910 if (create_ports_for_trace(ctf_fs
, trace
)) {
1918 ctf_fs_destroy(ctf_fs
);
1920 bt_self_component_set_data(
1921 bt_self_component_source_as_self_component(self_comp
),
1929 bt_self_component_status
ctf_fs_init(
1930 bt_self_component_source
*self_comp
,
1931 const bt_value
*params
, UNUSED_VAR
void *init_method_data
)
1933 struct ctf_fs_component
*ctf_fs
;
1934 bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
1936 ctf_fs
= ctf_fs_create(self_comp
, params
);
1938 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
1945 bt_query_status
ctf_fs_query(
1946 bt_self_component_class_source
*comp_class
,
1947 const bt_query_executor
*query_exec
,
1948 const char *object
, const bt_value
*params
,
1949 const bt_value
**result
)
1951 bt_query_status status
= BT_QUERY_STATUS_OK
;
1953 if (!strcmp(object
, "metadata-info")) {
1954 status
= metadata_info_query(comp_class
, params
, result
);
1955 } else if (!strcmp(object
, "trace-info")) {
1956 status
= trace_info_query(comp_class
, params
, result
);
1958 BT_LOGE("Unknown query object `%s`", object
);
1959 status
= BT_QUERY_STATUS_INVALID_OBJECT
;