4 * Babeltrace CTF Writer Output Plugin Event Handling
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-ir/event.h>
30 #include <babeltrace/ctf-ir/packet.h>
31 #include <babeltrace/ctf-ir/event-class.h>
32 #include <babeltrace/ctf-ir/stream.h>
33 #include <babeltrace/ctf-ir/stream-class.h>
34 #include <babeltrace/ctf-ir/clock-class.h>
35 #include <babeltrace/ctf-ir/fields.h>
36 #include <babeltrace/ctf-writer/stream-class.h>
37 #include <babeltrace/ctf-writer/stream.h>
41 #include <ctfcopytrace.h>
46 void unref_stream_class(struct bt_ctf_stream_class
*writer_stream_class
)
48 bt_put(writer_stream_class
);
52 void unref_stream(struct bt_ctf_stream_class
*writer_stream
)
54 bt_put(writer_stream
);
58 gboolean
empty_ht(gpointer key
, gpointer value
, gpointer user_data
)
64 gboolean
empty_streams_ht(gpointer key
, gpointer value
, gpointer user_data
)
66 struct bt_ctf_stream
*writer_stream
= value
;
68 bt_ctf_stream_flush(writer_stream
);
74 void destroy_stream_state_key(gpointer key
)
76 g_free((enum fs_writer_stream_state
*) key
);
80 void check_completed_trace(gpointer key
, gpointer value
, gpointer user_data
)
82 enum fs_writer_stream_state
*state
= value
;
83 int *trace_completed
= user_data
;
85 if (*state
!= FS_WRITER_COMPLETED_STREAM
) {
91 void trace_is_static_listener(struct bt_ctf_trace
*trace
, void *data
)
93 struct fs_writer
*fs_writer
= data
;
94 int trace_completed
= 1;
96 fs_writer
->trace_static
= 1;
98 g_hash_table_foreach(fs_writer
->stream_states
,
99 check_completed_trace
, &trace_completed
);
100 if (trace_completed
) {
101 writer_close(fs_writer
->writer_component
, fs_writer
);
102 g_hash_table_remove(fs_writer
->writer_component
->trace_map
,
108 struct bt_ctf_stream_class
*insert_new_stream_class(
109 struct writer_component
*writer_component
,
110 struct fs_writer
*fs_writer
,
111 struct bt_ctf_stream_class
*stream_class
)
113 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
114 struct bt_ctf_trace
*trace
= NULL
, *writer_trace
= NULL
;
115 struct bt_ctf_writer
*ctf_writer
= fs_writer
->writer
;
116 enum bt_component_status ret
;
118 trace
= bt_ctf_stream_class_get_trace(stream_class
);
120 fprintf(writer_component
->err
,
121 "[error] %s in %s:%d\n", __func__
, __FILE__
,
126 writer_trace
= bt_ctf_writer_get_trace(ctf_writer
);
128 fprintf(writer_component
->err
,
129 "[error] %s in %s:%d\n", __func__
, __FILE__
,
134 ret
= ctf_copy_clock_classes(writer_component
->err
, writer_trace
,
135 writer_stream_class
, trace
);
136 if (ret
!= BT_COMPONENT_STATUS_OK
) {
137 fprintf(writer_component
->err
,
138 "[error] %s in %s:%d\n", __func__
, __FILE__
,
143 writer_stream_class
= ctf_copy_stream_class(writer_component
->err
,
144 stream_class
, writer_trace
, true);
145 if (!writer_stream_class
) {
146 fprintf(writer_component
->err
, "[error] Failed to copy stream class\n");
147 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
148 __func__
, __FILE__
, __LINE__
);
152 ret
= bt_ctf_trace_add_stream_class(writer_trace
, writer_stream_class
);
154 fprintf(writer_component
->err
,
155 "[error] %s in %s:%d\n", __func__
, __FILE__
,
160 g_hash_table_insert(fs_writer
->stream_class_map
,
161 (gpointer
) stream_class
, writer_stream_class
);
166 BT_PUT(writer_stream_class
);
168 bt_put(writer_trace
);
170 return writer_stream_class
;
174 enum fs_writer_stream_state
*insert_new_stream_state(
175 struct writer_component
*writer_component
,
176 struct fs_writer
*fs_writer
, struct bt_ctf_stream
*stream
)
178 enum fs_writer_stream_state
*v
= NULL
;
180 v
= g_new0(enum fs_writer_stream_state
, 1);
182 fprintf(writer_component
->err
,
183 "[error] %s in %s:%d\n", __func__
,
186 *v
= FS_WRITER_UNKNOWN_STREAM
;
188 g_hash_table_insert(fs_writer
->stream_states
, stream
, v
);
194 * Make sure the output path is valid for a single trace: either it does
195 * not exists or it is empty.
197 * Return 0 if the path is valid, -1 otherwise.
200 bool valid_single_trace_path(const char *path
)
202 GError
*error
= NULL
;
206 dir
= g_dir_open(path
, 0, &error
);
208 /* Non-existent directory. */
210 /* For any other error, return an error */
211 if (error
->code
!= G_FILE_ERROR_NOENT
) {
217 /* g_dir_read_name skips "." and "..", error out on first result */
218 while (g_dir_read_name(dir
) != NULL
) {
235 int make_trace_path(struct writer_component
*writer_component
,
236 struct bt_ctf_trace
*trace
, char *trace_path
)
239 const char *trace_name
;
241 if (writer_component
->single_trace
) {
244 trace_name
= bt_ctf_trace_get_name(trace
);
246 trace_name
= writer_component
->trace_name_base
->str
;
250 /* Sanitize the trace name. */
251 if (strlen(trace_name
) == 2 && !strcmp(trace_name
, "..")) {
252 fprintf(writer_component
->err
, "[error] Trace name cannot "
257 if (strstr(trace_name
, "../")) {
258 fprintf(writer_component
->err
, "[error] Trace name cannot "
259 "contain \"../\", received \"%s\"\n",
265 snprintf(trace_path
, PATH_MAX
, "%s/%s",
266 writer_component
->base_path
->str
,
269 * Append a suffix if the trace_path exists and we are not in
272 if (writer_component
->single_trace
) {
273 if (valid_single_trace_path(trace_path
) != 0) {
274 fprintf(writer_component
->err
,
275 "[error] Invalid output directory\n");
279 if (g_file_test(trace_path
, G_FILE_TEST_EXISTS
)) {
283 snprintf(trace_path
, PATH_MAX
, "%s/%s-%d",
284 writer_component
->base_path
->str
,
286 } while (g_file_test(trace_path
, G_FILE_TEST_EXISTS
) && i
< INT_MAX
);
288 fprintf(writer_component
->err
, "[error] Unable to find "
289 "a unique trace path\n");
305 struct fs_writer
*insert_new_writer(
306 struct writer_component
*writer_component
,
307 struct bt_ctf_trace
*trace
)
309 struct bt_ctf_writer
*ctf_writer
= NULL
;
310 struct bt_ctf_trace
*writer_trace
= NULL
;
311 char trace_path
[PATH_MAX
];
312 enum bt_component_status ret
;
313 struct bt_ctf_stream
*stream
= NULL
;
314 struct fs_writer
*fs_writer
= NULL
;
317 if (writer_component
->single_trace
&& writer_component
->nr_traces
> 0) {
318 fprintf(writer_component
->err
, "[error] Trying to process more "
319 "than one trace but --single-trace mode "
324 ret
= make_trace_path(writer_component
, trace
, trace_path
);
326 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
327 __func__
, __FILE__
, __LINE__
);
331 printf("ctf.fs sink creating trace in %s\n", trace_path
);
333 ctf_writer
= bt_ctf_writer_create(trace_path
);
335 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
336 __func__
, __FILE__
, __LINE__
);
340 writer_trace
= bt_ctf_writer_get_trace(ctf_writer
);
342 fprintf(writer_component
->err
,
343 "[error] %s in %s:%d\n", __func__
, __FILE__
,
348 ret
= ctf_copy_trace(writer_component
->err
, trace
, writer_trace
);
349 if (ret
!= BT_COMPONENT_STATUS_OK
) {
350 fprintf(writer_component
->err
, "[error] Failed to copy trace\n");
351 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
352 __func__
, __FILE__
, __LINE__
);
357 fs_writer
= g_new0(struct fs_writer
, 1);
359 fprintf(writer_component
->err
,
360 "[error] %s in %s:%d\n", __func__
, __FILE__
,
364 fs_writer
->writer
= ctf_writer
;
365 fs_writer
->trace
= trace
;
366 fs_writer
->writer_trace
= writer_trace
;
367 fs_writer
->writer_component
= writer_component
;
368 BT_PUT(writer_trace
);
369 fs_writer
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
370 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream_class
);
371 fs_writer
->stream_map
= g_hash_table_new_full(g_direct_hash
,
372 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream
);
373 fs_writer
->stream_states
= g_hash_table_new_full(g_direct_hash
,
374 g_direct_equal
, NULL
, destroy_stream_state_key
);
376 /* Set all the existing streams in the unknown state. */
377 nr_stream
= bt_ctf_trace_get_stream_count(trace
);
378 for (i
= 0; i
< nr_stream
; i
++) {
379 stream
= bt_ctf_trace_get_stream_by_index(trace
, i
);
381 fprintf(writer_component
->err
,
382 "[error] %s in %s:%d\n", __func__
,
386 insert_new_stream_state(writer_component
, fs_writer
, stream
);
390 /* Check if the trace is already static or register a listener. */
391 if (bt_ctf_trace_is_static(trace
)) {
392 fs_writer
->trace_static
= 1;
393 fs_writer
->static_listener_id
= -1;
395 ret
= bt_ctf_trace_add_is_static_listener(trace
,
396 trace_is_static_listener
, fs_writer
);
398 fprintf(writer_component
->err
,
399 "[error] %s in %s:%d\n", __func__
, __FILE__
,
403 fs_writer
->static_listener_id
= ret
;
406 writer_component
->nr_traces
++;
407 g_hash_table_insert(writer_component
->trace_map
, (gpointer
) trace
,
415 bt_put(writer_trace
);
423 struct fs_writer
*get_fs_writer(struct writer_component
*writer_component
,
424 struct bt_ctf_stream_class
*stream_class
)
426 struct bt_ctf_trace
*trace
= NULL
;
427 struct fs_writer
*fs_writer
;
429 trace
= bt_ctf_stream_class_get_trace(stream_class
);
431 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
432 __func__
, __FILE__
, __LINE__
);
436 fs_writer
= g_hash_table_lookup(writer_component
->trace_map
,
439 fs_writer
= insert_new_writer(writer_component
, trace
);
451 struct fs_writer
*get_fs_writer_from_stream(
452 struct writer_component
*writer_component
,
453 struct bt_ctf_stream
*stream
)
455 struct bt_ctf_stream_class
*stream_class
= NULL
;
456 struct fs_writer
*fs_writer
;
458 stream_class
= bt_ctf_stream_get_class(stream
);
460 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
461 __func__
, __FILE__
, __LINE__
);
465 fs_writer
= get_fs_writer(writer_component
, stream_class
);
472 bt_put(stream_class
);
477 struct bt_ctf_stream_class
*lookup_stream_class(
478 struct writer_component
*writer_component
,
479 struct bt_ctf_stream_class
*stream_class
)
481 struct fs_writer
*fs_writer
= get_fs_writer(
482 writer_component
, stream_class
);
484 return (struct bt_ctf_stream_class
*) g_hash_table_lookup(
485 fs_writer
->stream_class_map
, (gpointer
) stream_class
);
489 struct bt_ctf_stream
*lookup_stream(struct writer_component
*writer_component
,
490 struct bt_ctf_stream
*stream
)
492 struct fs_writer
*fs_writer
= get_fs_writer_from_stream(
493 writer_component
, stream
);
495 return (struct bt_ctf_stream
*) g_hash_table_lookup(
496 fs_writer
->stream_map
, (gpointer
) stream
);
500 struct bt_ctf_stream
*insert_new_stream(
501 struct writer_component
*writer_component
,
502 struct fs_writer
*fs_writer
,
503 struct bt_ctf_stream_class
*stream_class
,
504 struct bt_ctf_stream
*stream
)
506 struct bt_ctf_stream
*writer_stream
= NULL
;
507 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
508 struct bt_ctf_writer
*ctf_writer
= bt_get(fs_writer
->writer
);
510 writer_stream_class
= lookup_stream_class(writer_component
,
512 if (!writer_stream_class
) {
513 writer_stream_class
= insert_new_stream_class(
514 writer_component
, fs_writer
, stream_class
);
515 if (!writer_stream_class
) {
516 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
517 __func__
, __FILE__
, __LINE__
);
521 bt_get(writer_stream_class
);
523 writer_stream
= bt_ctf_stream_create(writer_stream_class
,
524 bt_ctf_stream_get_name(stream
));
525 if (!writer_stream
) {
526 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
527 __func__
, __FILE__
, __LINE__
);
531 g_hash_table_insert(fs_writer
->stream_map
, (gpointer
) stream
,
537 BT_PUT(writer_stream
);
540 bt_put(writer_stream_class
);
541 return writer_stream
;
545 struct bt_ctf_event_class
*get_event_class(struct writer_component
*writer_component
,
546 struct bt_ctf_stream_class
*writer_stream_class
,
547 struct bt_ctf_event_class
*event_class
)
549 return bt_ctf_stream_class_get_event_class_by_id(writer_stream_class
,
550 bt_ctf_event_class_get_id(event_class
));
554 struct bt_ctf_stream
*get_writer_stream(
555 struct writer_component
*writer_component
,
556 struct bt_ctf_packet
*packet
, struct bt_ctf_stream
*stream
)
558 struct bt_ctf_stream
*writer_stream
= NULL
;
560 writer_stream
= lookup_stream(writer_component
, stream
);
561 if (!writer_stream
) {
562 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
563 __func__
, __FILE__
, __LINE__
);
566 bt_get(writer_stream
);
571 BT_PUT(writer_stream
);
573 return writer_stream
;
577 void writer_close(struct writer_component
*writer_component
,
578 struct fs_writer
*fs_writer
)
580 if (fs_writer
->static_listener_id
>= 0) {
581 bt_ctf_trace_remove_is_static_listener(fs_writer
->trace
,
582 fs_writer
->static_listener_id
);
585 /* Empty the stream class HT. */
586 g_hash_table_foreach_remove(fs_writer
->stream_class_map
,
588 g_hash_table_destroy(fs_writer
->stream_class_map
);
590 /* Empty the stream HT. */
591 g_hash_table_foreach_remove(fs_writer
->stream_map
,
592 empty_streams_ht
, NULL
);
593 g_hash_table_destroy(fs_writer
->stream_map
);
595 /* Empty the stream state HT. */
596 g_hash_table_foreach_remove(fs_writer
->stream_states
,
598 g_hash_table_destroy(fs_writer
->stream_states
);
602 enum bt_component_status
writer_stream_begin(
603 struct writer_component
*writer_component
,
604 struct bt_ctf_stream
*stream
)
606 struct bt_ctf_stream_class
*stream_class
= NULL
;
607 struct fs_writer
*fs_writer
;
608 struct bt_ctf_stream
*writer_stream
= NULL
;
609 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
610 enum fs_writer_stream_state
*state
;
612 stream_class
= bt_ctf_stream_get_class(stream
);
614 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
615 __func__
, __FILE__
, __LINE__
);
619 fs_writer
= get_fs_writer(writer_component
, stream_class
);
621 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
622 __func__
, __FILE__
, __LINE__
);
626 /* Set the stream as active */
627 state
= g_hash_table_lookup(fs_writer
->stream_states
, stream
);
629 if (fs_writer
->trace_static
) {
630 fprintf(writer_component
->err
, "[error] Adding a new "
631 "stream on a static trace\n");
634 state
= insert_new_stream_state(writer_component
, fs_writer
,
637 if (*state
!= FS_WRITER_UNKNOWN_STREAM
) {
638 fprintf(writer_component
->err
, "[error] Unexpected stream "
639 "state %d\n", *state
);
642 *state
= FS_WRITER_ACTIVE_STREAM
;
644 writer_stream
= insert_new_stream(writer_component
, fs_writer
,
645 stream_class
, stream
);
646 if (!writer_stream
) {
647 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
648 __func__
, __FILE__
, __LINE__
);
655 ret
= BT_COMPONENT_STATUS_ERROR
;
657 bt_put(stream_class
);
662 enum bt_component_status
writer_stream_end(
663 struct writer_component
*writer_component
,
664 struct bt_ctf_stream
*stream
)
666 struct bt_ctf_stream_class
*stream_class
= NULL
;
667 struct fs_writer
*fs_writer
;
668 struct bt_ctf_trace
*trace
= NULL
;
669 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
670 enum fs_writer_stream_state
*state
;
672 stream_class
= bt_ctf_stream_get_class(stream
);
674 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
675 __func__
, __FILE__
, __LINE__
);
679 fs_writer
= get_fs_writer(writer_component
, stream_class
);
681 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
682 __func__
, __FILE__
, __LINE__
);
686 state
= g_hash_table_lookup(fs_writer
->stream_states
, stream
);
687 if (*state
!= FS_WRITER_ACTIVE_STREAM
) {
688 fprintf(writer_component
->err
, "[error] Unexpected stream "
689 "state %d\n", *state
);
692 *state
= FS_WRITER_COMPLETED_STREAM
;
694 g_hash_table_remove(fs_writer
->stream_map
, stream
);
696 if (fs_writer
->trace_static
) {
697 int trace_completed
= 1;
699 g_hash_table_foreach(fs_writer
->stream_states
,
700 check_completed_trace
, &trace_completed
);
701 if (trace_completed
) {
702 writer_close(writer_component
, fs_writer
);
703 g_hash_table_remove(writer_component
->trace_map
,
711 ret
= BT_COMPONENT_STATUS_ERROR
;
714 BT_PUT(stream_class
);
719 enum bt_component_status
writer_new_packet(
720 struct writer_component
*writer_component
,
721 struct bt_ctf_packet
*packet
)
723 struct bt_ctf_stream
*stream
= NULL
, *writer_stream
= NULL
;
724 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
727 stream
= bt_ctf_packet_get_stream(packet
);
729 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
730 __func__
, __FILE__
, __LINE__
);
734 writer_stream
= get_writer_stream(writer_component
, packet
, stream
);
735 if (!writer_stream
) {
736 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
737 __func__
, __FILE__
, __LINE__
);
742 int_ret
= ctf_stream_copy_packet_context(
743 writer_component
->err
, packet
, writer_stream
);
745 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
746 __func__
, __FILE__
, __LINE__
);
750 ret
= ctf_stream_copy_packet_header(writer_component
->err
,
751 packet
, writer_stream
);
753 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
754 __func__
, __FILE__
, __LINE__
);
761 ret
= BT_COMPONENT_STATUS_ERROR
;
763 bt_put(writer_stream
);
769 enum bt_component_status
writer_close_packet(
770 struct writer_component
*writer_component
,
771 struct bt_ctf_packet
*packet
)
773 struct bt_ctf_stream
*stream
= NULL
, *writer_stream
= NULL
;
774 enum bt_component_status ret
;
776 stream
= bt_ctf_packet_get_stream(packet
);
778 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
779 __func__
, __FILE__
, __LINE__
);
783 writer_stream
= lookup_stream(writer_component
, stream
);
784 if (!writer_stream
) {
785 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
786 __func__
, __FILE__
, __LINE__
);
791 bt_get(writer_stream
);
793 ret
= bt_ctf_stream_flush(writer_stream
);
795 fprintf(writer_component
->err
,
796 "[error] Failed to flush packet\n");
799 BT_PUT(writer_stream
);
801 ret
= BT_COMPONENT_STATUS_OK
;
805 ret
= BT_COMPONENT_STATUS_ERROR
;
807 bt_put(writer_stream
);
813 enum bt_component_status
writer_output_event(
814 struct writer_component
*writer_component
,
815 struct bt_ctf_event
*event
)
817 enum bt_component_status ret
;
818 struct bt_ctf_event_class
*event_class
= NULL
, *writer_event_class
= NULL
;
819 struct bt_ctf_stream
*stream
= NULL
, *writer_stream
= NULL
;
820 struct bt_ctf_stream_class
*stream_class
= NULL
, *writer_stream_class
= NULL
;
821 struct bt_ctf_event
*writer_event
= NULL
;
822 const char *event_name
;
825 event_class
= bt_ctf_event_get_class(event
);
827 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
832 event_name
= bt_ctf_event_class_get_name(event_class
);
834 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
839 stream
= bt_ctf_event_get_stream(event
);
841 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
846 writer_stream
= lookup_stream(writer_component
, stream
);
847 if (!writer_stream
|| !bt_get(writer_stream
)) {
848 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
853 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
855 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
860 writer_stream_class
= lookup_stream_class(writer_component
, stream_class
);
861 if (!writer_stream_class
|| !bt_get(writer_stream_class
)) {
862 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
867 writer_event_class
= get_event_class(writer_component
,
868 writer_stream_class
, event_class
);
869 if (!writer_event_class
) {
870 writer_event_class
= ctf_copy_event_class(writer_component
->err
,
872 if (!writer_event_class
) {
873 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
874 __func__
, __FILE__
, __LINE__
);
877 int_ret
= bt_ctf_stream_class_add_event_class(
878 writer_stream_class
, writer_event_class
);
880 fprintf(writer_component
->err
, "[error] %s in %s:%d\n",
881 __func__
, __FILE__
, __LINE__
);
886 writer_event
= ctf_copy_event(writer_component
->err
, event
,
887 writer_event_class
, true);
889 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
891 fprintf(writer_component
->err
, "[error] Failed to copy event %s\n",
892 bt_ctf_event_class_get_name(writer_event_class
));
896 int_ret
= bt_ctf_stream_append_event(writer_stream
, writer_event
);
898 fprintf(writer_component
->err
, "[error] %s in %s:%d\n", __func__
,
900 fprintf(writer_component
->err
, "[error] Failed to append event %s\n",
901 bt_ctf_event_class_get_name(writer_event_class
));
905 ret
= BT_COMPONENT_STATUS_OK
;
909 ret
= BT_COMPONENT_STATUS_ERROR
;
911 bt_put(writer_event
);
912 bt_put(writer_event_class
);
913 bt_put(writer_stream_class
);
914 bt_put(stream_class
);
915 bt_put(writer_stream
);