2 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
3 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_COMP_LOG_SELF_COMP (dmesg_comp->self_comp)
25 #define BT_LOG_OUTPUT_LEVEL (dmesg_comp->log_level)
26 #define BT_LOG_TAG "PLUGIN/SRC.TEXT.DMESG"
27 #include "plugins/comp-logging.h"
33 #include "common/common.h"
34 #include "common/assert.h"
35 #include <babeltrace2/babeltrace.h>
36 #include "compat/utc.h"
37 #include "compat/stdio.h"
40 #define NSEC_PER_USEC 1000UL
41 #define NSEC_PER_MSEC 1000000UL
42 #define NSEC_PER_SEC 1000000000ULL
43 #define USEC_PER_SEC 1000000UL
45 struct dmesg_component
;
47 struct dmesg_msg_iter
{
48 struct dmesg_component
*dmesg_comp
;
49 bt_self_message_iterator
*pc_msg_iter
; /* Weak */
53 bt_message
*tmp_event_msg
;
54 uint64_t last_clock_value
;
57 STATE_EMIT_STREAM_BEGINNING
,
58 STATE_EMIT_STREAM_ACTIVITY_BEGINNING
,
59 STATE_EMIT_PACKET_BEGINNING
,
61 STATE_EMIT_PACKET_END
,
62 STATE_EMIT_STREAM_ACTIVITY_END
,
63 STATE_EMIT_STREAM_END
,
68 struct dmesg_component
{
69 bt_logging_level log_level
;
73 bt_bool read_from_stdin
;
77 bt_self_component_source
*self_comp_src
;
78 bt_self_component
*self_comp
;
79 bt_trace_class
*trace_class
;
80 bt_stream_class
*stream_class
;
81 bt_event_class
*event_class
;
85 bt_clock_class
*clock_class
;
89 bt_field_class
*create_event_payload_fc(struct dmesg_component
*dmesg_comp
,
90 bt_trace_class
*trace_class
)
92 bt_field_class
*root_fc
= NULL
;
93 bt_field_class
*fc
= NULL
;
96 root_fc
= bt_field_class_structure_create(trace_class
);
98 BT_COMP_LOGE_STR("Cannot create an empty structure field class object.");
102 fc
= bt_field_class_string_create(trace_class
);
104 BT_COMP_LOGE_STR("Cannot create a string field class object.");
108 ret
= bt_field_class_structure_append_member(root_fc
,
111 BT_COMP_LOGE("Cannot add `str` member to structure field class: "
119 BT_FIELD_CLASS_PUT_REF_AND_RESET(root_fc
);
122 bt_field_class_put_ref(fc
);
127 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
129 bt_field_class
*fc
= NULL
;
132 dmesg_comp
->trace_class
= bt_trace_class_create(dmesg_comp
->self_comp
);
133 if (!dmesg_comp
->trace_class
) {
134 BT_COMP_LOGE_STR("Cannot create an empty trace class object.");
138 dmesg_comp
->stream_class
= bt_stream_class_create(
139 dmesg_comp
->trace_class
);
140 if (!dmesg_comp
->stream_class
) {
141 BT_COMP_LOGE_STR("Cannot create a stream class object.");
146 dmesg_comp
->clock_class
= bt_clock_class_create(
147 dmesg_comp
->self_comp
);
148 if (!dmesg_comp
->clock_class
) {
149 BT_COMP_LOGE_STR("Cannot create clock class.");
154 * The `dmesg` timestamp's origin is not the Unix epoch,
155 * it's the boot time.
157 bt_clock_class_set_origin_is_unix_epoch(dmesg_comp
->clock_class
,
160 ret
= bt_stream_class_set_default_clock_class(
161 dmesg_comp
->stream_class
, dmesg_comp
->clock_class
);
163 BT_COMP_LOGE_STR("Cannot set stream class's default clock class.");
167 bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
168 dmesg_comp
->stream_class
, BT_TRUE
);
169 bt_stream_class_set_packets_have_end_default_clock_snapshot(
170 dmesg_comp
->stream_class
, BT_TRUE
);
173 dmesg_comp
->event_class
= bt_event_class_create(
174 dmesg_comp
->stream_class
);
175 if (!dmesg_comp
->event_class
) {
176 BT_COMP_LOGE_STR("Cannot create an event class object.");
180 ret
= bt_event_class_set_name(dmesg_comp
->event_class
, "string");
182 BT_COMP_LOGE_STR("Cannot set event class's name.");
186 fc
= create_event_payload_fc(dmesg_comp
, dmesg_comp
->trace_class
);
188 BT_COMP_LOGE_STR("Cannot create event payload field class.");
192 ret
= bt_event_class_set_payload_field_class(dmesg_comp
->event_class
, fc
);
194 BT_COMP_LOGE_STR("Cannot set event class's event payload field class.");
204 bt_field_class_put_ref(fc
);
209 int handle_params(struct dmesg_component
*dmesg_comp
,
210 const bt_value
*params
)
212 const bt_value
*no_timestamp
= NULL
;
213 const bt_value
*path
= NULL
;
214 const char *path_str
;
217 no_timestamp
= bt_value_map_borrow_entry_value_const(params
,
218 "no-extract-timestamp");
220 if (!bt_value_is_bool(no_timestamp
)) {
221 BT_COMP_LOGE("Expecting a boolean value for the `no-extract-timestamp` parameter: "
223 bt_common_value_type_string(
224 bt_value_get_type(no_timestamp
)));
228 dmesg_comp
->params
.no_timestamp
=
229 bt_value_bool_get(no_timestamp
);
232 path
= bt_value_map_borrow_entry_value_const(params
, "path");
234 if (dmesg_comp
->params
.read_from_stdin
) {
235 BT_COMP_LOGE_STR("Cannot specify both `read-from-stdin` and `path` parameters.");
239 if (!bt_value_is_string(path
)) {
240 BT_COMP_LOGE("Expecting a string value for the `path` parameter: "
242 bt_common_value_type_string(
243 bt_value_get_type(path
)));
247 path_str
= bt_value_string_get(path
);
248 g_string_assign(dmesg_comp
->params
.path
, path_str
);
250 dmesg_comp
->params
.read_from_stdin
= true;
263 int create_packet_and_stream_and_trace(struct dmesg_component
*dmesg_comp
)
266 const char *trace_name
= NULL
;
267 gchar
*basename
= NULL
;
269 dmesg_comp
->trace
= bt_trace_create(dmesg_comp
->trace_class
);
270 if (!dmesg_comp
->trace
) {
271 BT_COMP_LOGE_STR("Cannot create trace object.");
275 if (dmesg_comp
->params
.read_from_stdin
) {
276 trace_name
= "STDIN";
278 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
281 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
282 strcmp(basename
, ".") != 0) {
283 trace_name
= basename
;
288 ret
= bt_trace_set_name(dmesg_comp
->trace
, trace_name
);
290 BT_COMP_LOGE("Cannot set trace's name: name=\"%s\"",
296 dmesg_comp
->stream
= bt_stream_create(dmesg_comp
->stream_class
,
298 if (!dmesg_comp
->stream
) {
299 BT_COMP_LOGE_STR("Cannot create stream object.");
303 dmesg_comp
->packet
= bt_packet_create(dmesg_comp
->stream
);
304 if (!dmesg_comp
->packet
) {
305 BT_COMP_LOGE_STR("Cannot create packet object.");
323 int try_create_meta_stream_packet(struct dmesg_component
*dmesg_comp
,
328 if (dmesg_comp
->trace
) {
329 /* Already created */
333 ret
= create_meta(dmesg_comp
, has_ts
);
335 BT_COMP_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
340 ret
= create_packet_and_stream_and_trace(dmesg_comp
);
342 BT_COMP_LOGE("Cannot create packet and stream objects: "
343 "dmesg-comp-addr=%p", dmesg_comp
);
357 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
363 if (dmesg_comp
->params
.path
) {
364 g_string_free(dmesg_comp
->params
.path
, TRUE
);
367 bt_packet_put_ref(dmesg_comp
->packet
);
368 bt_trace_put_ref(dmesg_comp
->trace
);
369 bt_stream_class_put_ref(dmesg_comp
->stream_class
);
370 bt_event_class_put_ref(dmesg_comp
->event_class
);
371 bt_stream_put_ref(dmesg_comp
->stream
);
372 bt_clock_class_put_ref(dmesg_comp
->clock_class
);
373 bt_trace_class_put_ref(dmesg_comp
->trace_class
);
378 bt_component_class_init_method_status
create_port(
379 bt_self_component_source
*self_comp
)
381 bt_component_class_init_method_status status
;
382 bt_self_component_add_port_status add_port_status
;
384 add_port_status
= bt_self_component_source_add_output_port(self_comp
,
386 switch (add_port_status
) {
387 case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
:
388 status
= BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK
;
390 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR
:
391 status
= BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR
;
393 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR
:
394 status
= BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR
;
404 bt_component_class_init_method_status
dmesg_init(
405 bt_self_component_source
*self_comp_src
,
406 bt_value
*params
, void *init_method_data
)
409 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
410 bt_component_class_init_method_status status
=
411 BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK
;
412 bt_self_component
*self_comp
=
413 bt_self_component_source_as_self_component(self_comp_src
);
414 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
415 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
418 /* Implicit log level is not available here */
419 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
420 "Failed to allocate one dmesg component structure.");
424 dmesg_comp
->log_level
= log_level
;
425 dmesg_comp
->self_comp
= self_comp
;
426 dmesg_comp
->self_comp_src
= self_comp_src
;
427 dmesg_comp
->params
.path
= g_string_new(NULL
);
428 if (!dmesg_comp
->params
.path
) {
429 BT_COMP_LOGE_STR("Failed to allocate a GString.");
433 ret
= handle_params(dmesg_comp
, params
);
435 BT_COMP_LOGE("Invalid parameters: comp-addr=%p", self_comp
);
439 if (!dmesg_comp
->params
.read_from_stdin
&&
440 !g_file_test(dmesg_comp
->params
.path
->str
,
441 G_FILE_TEST_IS_REGULAR
)) {
442 BT_COMP_LOGE("Input path is not a regular file: "
443 "comp-addr=%p, path=\"%s\"", self_comp
,
444 dmesg_comp
->params
.path
->str
);
448 status
= create_port(self_comp_src
);
449 if (status
!= BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK
) {
453 bt_self_component_set_data(self_comp
, dmesg_comp
);
454 BT_COMP_LOGI_STR("Component initialized.");
458 destroy_dmesg_component(dmesg_comp
);
459 bt_self_component_set_data(self_comp
, NULL
);
462 status
= BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR
;
470 void dmesg_finalize(bt_self_component_source
*self_comp
)
472 destroy_dmesg_component(bt_self_component_get_data(
473 bt_self_component_source_as_self_component(self_comp
)));
477 bt_message
*create_init_event_msg_from_line(
478 struct dmesg_msg_iter
*msg_iter
,
479 const char *line
, const char **new_start
)
482 bt_message
*msg
= NULL
;
483 bool has_timestamp
= false;
484 unsigned long sec
, usec
, msec
;
485 unsigned int year
, mon
, mday
, hour
, min
;
488 struct dmesg_component
*dmesg_comp
= msg_iter
->dmesg_comp
;
492 if (dmesg_comp
->params
.no_timestamp
) {
496 /* Extract time from input line */
497 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
498 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
501 * The clock class we use has a 1 GHz frequency: convert
505 has_timestamp
= true;
506 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
507 &year
, &mon
, &mday
, &hour
, &min
,
512 memset(&ti
, 0, sizeof(ti
));
513 ti
.tm_year
= year
- 1900; /* From 1900 */
514 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
520 ep_sec
= bt_timegm(&ti
);
521 if (ep_sec
!= (time_t) -1) {
522 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
523 + (uint64_t) msec
* NSEC_PER_MSEC
;
526 has_timestamp
= true;
530 /* Set new start for the message portion of the line */
531 *new_start
= strchr(line
, ']');
532 BT_ASSERT(*new_start
);
535 if ((*new_start
)[0] == ' ') {
542 * At this point, we know if the stream class's event header
543 * field class should have a timestamp or not, so we can lazily
544 * create the metadata, stream, and packet objects.
546 ret
= try_create_meta_stream_packet(dmesg_comp
, has_timestamp
);
548 /* try_create_meta_stream_packet() logs errors */
552 if (dmesg_comp
->clock_class
) {
553 msg
= bt_message_event_create_with_default_clock_snapshot(
554 msg_iter
->pc_msg_iter
,
555 dmesg_comp
->event_class
, dmesg_comp
->packet
, ts
);
556 msg_iter
->last_clock_value
= ts
;
558 msg
= bt_message_event_create(msg_iter
->pc_msg_iter
,
559 dmesg_comp
->event_class
, dmesg_comp
->packet
);
563 BT_COMP_LOGE_STR("Cannot create event message.");
567 event
= bt_message_event_borrow_event(msg
);
572 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
579 int fill_event_payload_from_line(struct dmesg_component
*dmesg_comp
,
580 const char *line
, bt_event
*event
)
582 bt_field
*ep_field
= NULL
;
583 bt_field
*str_field
= NULL
;
587 ep_field
= bt_event_borrow_payload_field(event
);
589 str_field
= bt_field_structure_borrow_member_field_by_index(
592 BT_COMP_LOGE_STR("Cannot borrow `timestamp` field from event payload structure field.");
597 if (line
[len
- 1] == '\n') {
598 /* Do not include the newline character in the payload */
602 bt_field_string_clear(str_field
);
603 ret
= bt_field_string_append_with_length(str_field
, line
, len
);
605 BT_COMP_LOGE("Cannot append value to string field object: "
620 bt_message
*create_msg_from_line(
621 struct dmesg_msg_iter
*dmesg_msg_iter
, const char *line
)
623 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
624 bt_event
*event
= NULL
;
625 bt_message
*msg
= NULL
;
626 const char *new_start
;
629 msg
= create_init_event_msg_from_line(dmesg_msg_iter
,
632 BT_COMP_LOGE_STR("Cannot create and initialize event message from line.");
636 event
= bt_message_event_borrow_event(msg
);
638 ret
= fill_event_payload_from_line(dmesg_comp
, new_start
, event
);
640 BT_COMP_LOGE("Cannot fill event payload field from line: "
648 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
655 void destroy_dmesg_msg_iter(struct dmesg_msg_iter
*dmesg_msg_iter
)
657 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
659 if (!dmesg_msg_iter
) {
663 if (dmesg_msg_iter
->fp
&& dmesg_msg_iter
->fp
!= stdin
) {
664 if (fclose(dmesg_msg_iter
->fp
)) {
665 BT_COMP_LOGE_ERRNO("Cannot close input file", ".");
669 bt_message_put_ref(dmesg_msg_iter
->tmp_event_msg
);
670 free(dmesg_msg_iter
->linebuf
);
671 g_free(dmesg_msg_iter
);
677 bt_component_class_message_iterator_init_method_status
dmesg_msg_iter_init(
678 bt_self_message_iterator
*self_msg_iter
,
679 bt_self_component_source
*self_comp
,
680 bt_self_component_port_output
*self_port
)
682 struct dmesg_component
*dmesg_comp
= bt_self_component_get_data(
683 bt_self_component_source_as_self_component(self_comp
));
684 struct dmesg_msg_iter
*dmesg_msg_iter
=
685 g_new0(struct dmesg_msg_iter
, 1);
686 bt_component_class_message_iterator_init_method_status status
=
687 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK
;
689 if (!dmesg_msg_iter
) {
690 BT_COMP_LOGE_STR("Failed to allocate on dmesg message iterator structure.");
694 BT_ASSERT(dmesg_comp
);
695 dmesg_msg_iter
->dmesg_comp
= dmesg_comp
;
696 dmesg_msg_iter
->pc_msg_iter
= self_msg_iter
;
698 if (dmesg_comp
->params
.read_from_stdin
) {
699 dmesg_msg_iter
->fp
= stdin
;
701 dmesg_msg_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
702 if (!dmesg_msg_iter
->fp
) {
703 BT_COMP_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
704 dmesg_comp
->params
.path
->str
);
709 bt_self_message_iterator_set_data(self_msg_iter
,
714 destroy_dmesg_msg_iter(dmesg_msg_iter
);
715 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
717 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR
;
725 void dmesg_msg_iter_finalize(
726 bt_self_message_iterator
*priv_msg_iter
)
728 destroy_dmesg_msg_iter(bt_self_message_iterator_get_data(
733 bt_component_class_message_iterator_next_method_status
dmesg_msg_iter_next_one(
734 struct dmesg_msg_iter
*dmesg_msg_iter
,
738 struct dmesg_component
*dmesg_comp
;
739 bt_component_class_message_iterator_next_method_status status
=
740 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
742 BT_ASSERT(dmesg_msg_iter
);
743 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
744 BT_ASSERT(dmesg_comp
);
746 if (dmesg_msg_iter
->state
== STATE_DONE
) {
747 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
751 if (dmesg_msg_iter
->tmp_event_msg
||
752 dmesg_msg_iter
->state
== STATE_EMIT_PACKET_END
||
753 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_ACTIVITY_END
||
754 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_END
) {
760 bool only_spaces
= true;
762 len
= bt_getline(&dmesg_msg_iter
->linebuf
,
763 &dmesg_msg_iter
->linebuf_len
, dmesg_msg_iter
->fp
);
765 if (errno
== EINVAL
) {
766 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
767 } else if (errno
== ENOMEM
) {
768 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR
;
770 if (dmesg_msg_iter
->state
== STATE_EMIT_STREAM_BEGINNING
) {
771 /* Stream did not even begin */
772 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
775 /* End current packet now */
776 dmesg_msg_iter
->state
=
777 STATE_EMIT_PACKET_END
;
785 BT_ASSERT(dmesg_msg_iter
->linebuf
);
787 /* Ignore empty lines, once trimmed */
788 for (ch
= dmesg_msg_iter
->linebuf
; *ch
!= '\0'; ch
++) {
800 dmesg_msg_iter
->tmp_event_msg
= create_msg_from_line(
801 dmesg_msg_iter
, dmesg_msg_iter
->linebuf
);
802 if (!dmesg_msg_iter
->tmp_event_msg
) {
803 BT_COMP_LOGE("Cannot create event message from line: "
804 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
805 dmesg_msg_iter
->linebuf
);
810 BT_ASSERT(dmesg_comp
->trace
);
812 switch (dmesg_msg_iter
->state
) {
813 case STATE_EMIT_STREAM_BEGINNING
:
814 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
815 *msg
= bt_message_stream_beginning_create(
816 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
817 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_ACTIVITY_BEGINNING
;
819 case STATE_EMIT_STREAM_ACTIVITY_BEGINNING
:
820 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
821 *msg
= bt_message_stream_activity_beginning_create(
822 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
823 dmesg_msg_iter
->state
= STATE_EMIT_PACKET_BEGINNING
;
825 case STATE_EMIT_PACKET_BEGINNING
:
826 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
828 if (dmesg_comp
->clock_class
) {
829 *msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
830 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
,
831 dmesg_msg_iter
->last_clock_value
);
833 *msg
= bt_message_packet_beginning_create(
834 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
);
837 dmesg_msg_iter
->state
= STATE_EMIT_EVENT
;
839 case STATE_EMIT_EVENT
:
840 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
841 *msg
= dmesg_msg_iter
->tmp_event_msg
;
842 dmesg_msg_iter
->tmp_event_msg
= NULL
;
844 case STATE_EMIT_PACKET_END
:
845 if (dmesg_comp
->clock_class
) {
846 *msg
= bt_message_packet_end_create_with_default_clock_snapshot(
847 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
,
848 dmesg_msg_iter
->last_clock_value
);
850 *msg
= bt_message_packet_end_create(
851 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
);
854 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_ACTIVITY_END
;
856 case STATE_EMIT_STREAM_ACTIVITY_END
:
857 *msg
= bt_message_stream_activity_end_create(
858 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
859 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_END
;
861 case STATE_EMIT_STREAM_END
:
862 *msg
= bt_message_stream_end_create(
863 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
864 dmesg_msg_iter
->state
= STATE_DONE
;
871 BT_COMP_LOGE("Cannot create message: dmesg-comp-addr=%p",
873 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
881 bt_component_class_message_iterator_next_method_status
dmesg_msg_iter_next(
882 bt_self_message_iterator
*self_msg_iter
,
883 bt_message_array_const msgs
, uint64_t capacity
,
886 struct dmesg_msg_iter
*dmesg_msg_iter
=
887 bt_self_message_iterator_get_data(
889 bt_component_class_message_iterator_next_method_status status
=
890 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
893 while (i
< capacity
&&
894 status
== BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
) {
895 bt_message
*priv_msg
= NULL
;
897 status
= dmesg_msg_iter_next_one(dmesg_msg_iter
,
900 if (status
== BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
) {
907 * Even if dmesg_msg_iter_next_one() returned
908 * something else than
909 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
910 * accumulated message objects in the output
911 * message array, so we need to return
912 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they
913 * are transfered to downstream. This other status
914 * occurs again the next time muxer_msg_iter_do_next()
915 * is called, possibly without any accumulated
916 * message, in which case we'll return it.
919 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
926 bt_bool
dmesg_msg_iter_can_seek_beginning(
927 bt_self_message_iterator
*self_msg_iter
)
929 struct dmesg_msg_iter
*dmesg_msg_iter
=
930 bt_self_message_iterator_get_data(self_msg_iter
);
932 /* Can't seek the beginning of the standard input stream */
933 return !dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
;
937 bt_component_class_message_iterator_seek_beginning_method_status
938 dmesg_msg_iter_seek_beginning(
939 bt_self_message_iterator
*self_msg_iter
)
941 struct dmesg_msg_iter
*dmesg_msg_iter
=
942 bt_self_message_iterator_get_data(self_msg_iter
);
944 BT_ASSERT(!dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
);
946 BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter
->tmp_event_msg
);
947 dmesg_msg_iter
->last_clock_value
= 0;
948 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_BEGINNING
;
949 return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK
;