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_LOG_OUTPUT_LEVEL (dmesg_comp->log_level)
25 #define BT_LOG_TAG "PLUGIN/SRC.TEXT.DMESG"
26 #include "logging/log.h"
32 #include "common/common.h"
33 #include "common/assert.h"
34 #include <babeltrace2/babeltrace.h>
35 #include "compat/utc.h"
36 #include "compat/stdio.h"
39 #define NSEC_PER_USEC 1000UL
40 #define NSEC_PER_MSEC 1000000UL
41 #define NSEC_PER_SEC 1000000000ULL
42 #define USEC_PER_SEC 1000000UL
44 struct dmesg_component
;
46 struct dmesg_msg_iter
{
47 struct dmesg_component
*dmesg_comp
;
48 bt_self_message_iterator
*pc_msg_iter
; /* Weak */
52 bt_message
*tmp_event_msg
;
53 uint64_t last_clock_value
;
56 STATE_EMIT_STREAM_BEGINNING
,
57 STATE_EMIT_STREAM_ACTIVITY_BEGINNING
,
58 STATE_EMIT_PACKET_BEGINNING
,
60 STATE_EMIT_PACKET_END
,
61 STATE_EMIT_STREAM_ACTIVITY_END
,
62 STATE_EMIT_STREAM_END
,
67 struct dmesg_component
{
68 bt_logging_level log_level
;
72 bt_bool read_from_stdin
;
76 bt_self_component_source
*self_comp
;
77 bt_trace_class
*trace_class
;
78 bt_stream_class
*stream_class
;
79 bt_event_class
*event_class
;
83 bt_clock_class
*clock_class
;
87 bt_field_class
*create_event_payload_fc(struct dmesg_component
*dmesg_comp
,
88 bt_trace_class
*trace_class
)
90 bt_field_class
*root_fc
= NULL
;
91 bt_field_class
*fc
= NULL
;
94 root_fc
= bt_field_class_structure_create(trace_class
);
96 BT_LOGE_STR("Cannot create an empty structure field class object.");
100 fc
= bt_field_class_string_create(trace_class
);
102 BT_LOGE_STR("Cannot create a string field class object.");
106 ret
= bt_field_class_structure_append_member(root_fc
,
109 BT_LOGE("Cannot add `str` member to structure field class: "
117 BT_FIELD_CLASS_PUT_REF_AND_RESET(root_fc
);
120 bt_field_class_put_ref(fc
);
125 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
127 bt_field_class
*fc
= NULL
;
130 dmesg_comp
->trace_class
= bt_trace_class_create(
131 bt_self_component_source_as_self_component(
132 dmesg_comp
->self_comp
));
133 if (!dmesg_comp
->trace_class
) {
134 BT_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_LOGE_STR("Cannot create a stream class object.");
146 dmesg_comp
->clock_class
= bt_clock_class_create(
147 bt_self_component_source_as_self_component(
148 dmesg_comp
->self_comp
));
149 if (!dmesg_comp
->clock_class
) {
150 BT_LOGE_STR("Cannot create clock class.");
155 * The `dmesg` timestamp's origin is not the Unix epoch,
156 * it's the boot time.
158 bt_clock_class_set_origin_is_unix_epoch(dmesg_comp
->clock_class
,
161 ret
= bt_stream_class_set_default_clock_class(
162 dmesg_comp
->stream_class
, dmesg_comp
->clock_class
);
164 BT_LOGE_STR("Cannot set stream class's default clock class.");
168 bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
169 dmesg_comp
->stream_class
, BT_TRUE
);
170 bt_stream_class_set_packets_have_end_default_clock_snapshot(
171 dmesg_comp
->stream_class
, BT_TRUE
);
174 dmesg_comp
->event_class
= bt_event_class_create(
175 dmesg_comp
->stream_class
);
176 if (!dmesg_comp
->event_class
) {
177 BT_LOGE_STR("Cannot create an event class object.");
181 ret
= bt_event_class_set_name(dmesg_comp
->event_class
, "string");
183 BT_LOGE_STR("Cannot set event class's name.");
187 fc
= create_event_payload_fc(dmesg_comp
, dmesg_comp
->trace_class
);
189 BT_LOGE_STR("Cannot create event payload field class.");
193 ret
= bt_event_class_set_payload_field_class(dmesg_comp
->event_class
, fc
);
195 BT_LOGE_STR("Cannot set event class's event payload field class.");
205 bt_field_class_put_ref(fc
);
210 int handle_params(struct dmesg_component
*dmesg_comp
,
211 const bt_value
*params
)
213 const bt_value
*no_timestamp
= NULL
;
214 const bt_value
*path
= NULL
;
215 const char *path_str
;
218 no_timestamp
= bt_value_map_borrow_entry_value_const(params
,
219 "no-extract-timestamp");
221 if (!bt_value_is_bool(no_timestamp
)) {
222 BT_LOGE("Expecting a boolean value for the `no-extract-timestamp` parameter: "
224 bt_common_value_type_string(
225 bt_value_get_type(no_timestamp
)));
229 dmesg_comp
->params
.no_timestamp
=
230 bt_value_bool_get(no_timestamp
);
233 path
= bt_value_map_borrow_entry_value_const(params
, "path");
235 if (dmesg_comp
->params
.read_from_stdin
) {
236 BT_LOGE_STR("Cannot specify both `read-from-stdin` and `path` parameters.");
240 if (!bt_value_is_string(path
)) {
241 BT_LOGE("Expecting a string value for the `path` parameter: "
243 bt_common_value_type_string(
244 bt_value_get_type(path
)));
248 path_str
= bt_value_string_get(path
);
249 g_string_assign(dmesg_comp
->params
.path
, path_str
);
251 dmesg_comp
->params
.read_from_stdin
= true;
264 int create_packet_and_stream_and_trace(struct dmesg_component
*dmesg_comp
)
267 const char *trace_name
= NULL
;
268 gchar
*basename
= NULL
;
270 dmesg_comp
->trace
= bt_trace_create(dmesg_comp
->trace_class
);
271 if (!dmesg_comp
->trace
) {
272 BT_LOGE_STR("Cannot create trace object.");
276 if (dmesg_comp
->params
.read_from_stdin
) {
277 trace_name
= "STDIN";
279 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
282 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
283 strcmp(basename
, ".") != 0) {
284 trace_name
= basename
;
289 ret
= bt_trace_set_name(dmesg_comp
->trace
, trace_name
);
291 BT_LOGE("Cannot set trace's name: name=\"%s\"",
297 dmesg_comp
->stream
= bt_stream_create(dmesg_comp
->stream_class
,
299 if (!dmesg_comp
->stream
) {
300 BT_LOGE_STR("Cannot create stream object.");
304 dmesg_comp
->packet
= bt_packet_create(dmesg_comp
->stream
);
305 if (!dmesg_comp
->packet
) {
306 BT_LOGE_STR("Cannot create packet object.");
324 int try_create_meta_stream_packet(struct dmesg_component
*dmesg_comp
,
329 if (dmesg_comp
->trace
) {
330 /* Already created */
334 ret
= create_meta(dmesg_comp
, has_ts
);
336 BT_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
341 ret
= create_packet_and_stream_and_trace(dmesg_comp
);
343 BT_LOGE("Cannot create packet and stream objects: "
344 "dmesg-comp-addr=%p", dmesg_comp
);
358 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
364 if (dmesg_comp
->params
.path
) {
365 g_string_free(dmesg_comp
->params
.path
, TRUE
);
368 bt_packet_put_ref(dmesg_comp
->packet
);
369 bt_trace_put_ref(dmesg_comp
->trace
);
370 bt_stream_class_put_ref(dmesg_comp
->stream_class
);
371 bt_event_class_put_ref(dmesg_comp
->event_class
);
372 bt_stream_put_ref(dmesg_comp
->stream
);
373 bt_clock_class_put_ref(dmesg_comp
->clock_class
);
374 bt_trace_class_put_ref(dmesg_comp
->trace_class
);
379 bt_self_component_status
create_port(
380 bt_self_component_source
*self_comp
)
382 return bt_self_component_source_add_output_port(self_comp
,
387 bt_self_component_status
dmesg_init(
388 bt_self_component_source
*self_comp
,
389 bt_value
*params
, void *init_method_data
)
392 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
393 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
394 const bt_component
*comp
= bt_self_component_as_component(
395 bt_self_component_source_as_self_component(self_comp
));
396 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
399 /* Implicit log level is not available here */
400 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
401 "Failed to allocate one dmesg component structure.");
405 dmesg_comp
->log_level
= log_level
;
406 dmesg_comp
->self_comp
= self_comp
;
407 dmesg_comp
->params
.path
= g_string_new(NULL
);
408 if (!dmesg_comp
->params
.path
) {
409 BT_LOGE_STR("Failed to allocate a GString.");
413 ret
= handle_params(dmesg_comp
, params
);
415 BT_LOGE("Invalid parameters: comp-addr=%p", self_comp
);
419 if (!dmesg_comp
->params
.read_from_stdin
&&
420 !g_file_test(dmesg_comp
->params
.path
->str
,
421 G_FILE_TEST_IS_REGULAR
)) {
422 BT_LOGE("Input path is not a regular file: "
423 "comp-addr=%p, path=\"%s\"", self_comp
,
424 dmesg_comp
->params
.path
->str
);
428 status
= create_port(self_comp
);
429 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
433 bt_self_component_set_data(
434 bt_self_component_source_as_self_component(self_comp
),
436 BT_LOGI("`src.text.dmesg` component initialized: name=\"%s\"",
437 bt_component_get_name(comp
));
441 destroy_dmesg_component(dmesg_comp
);
442 bt_self_component_set_data(
443 bt_self_component_source_as_self_component(self_comp
),
447 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
455 void dmesg_finalize(bt_self_component_source
*self_comp
)
457 destroy_dmesg_component(bt_self_component_get_data(
458 bt_self_component_source_as_self_component(self_comp
)));
462 bt_message
*create_init_event_msg_from_line(
463 struct dmesg_msg_iter
*msg_iter
,
464 const char *line
, const char **new_start
)
467 bt_message
*msg
= NULL
;
468 bool has_timestamp
= false;
469 unsigned long sec
, usec
, msec
;
470 unsigned int year
, mon
, mday
, hour
, min
;
473 struct dmesg_component
*dmesg_comp
= msg_iter
->dmesg_comp
;
477 if (dmesg_comp
->params
.no_timestamp
) {
481 /* Extract time from input line */
482 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
483 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
486 * The clock class we use has a 1 GHz frequency: convert
490 has_timestamp
= true;
491 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
492 &year
, &mon
, &mday
, &hour
, &min
,
497 memset(&ti
, 0, sizeof(ti
));
498 ti
.tm_year
= year
- 1900; /* From 1900 */
499 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
505 ep_sec
= bt_timegm(&ti
);
506 if (ep_sec
!= (time_t) -1) {
507 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
508 + (uint64_t) msec
* NSEC_PER_MSEC
;
511 has_timestamp
= true;
515 /* Set new start for the message portion of the line */
516 *new_start
= strchr(line
, ']');
517 BT_ASSERT(*new_start
);
520 if ((*new_start
)[0] == ' ') {
527 * At this point, we know if the stream class's event header
528 * field class should have a timestamp or not, so we can lazily
529 * create the metadata, stream, and packet objects.
531 ret
= try_create_meta_stream_packet(dmesg_comp
, has_timestamp
);
533 /* try_create_meta_stream_packet() logs errors */
537 if (dmesg_comp
->clock_class
) {
538 msg
= bt_message_event_create_with_default_clock_snapshot(
539 msg_iter
->pc_msg_iter
,
540 dmesg_comp
->event_class
, dmesg_comp
->packet
, ts
);
541 msg_iter
->last_clock_value
= ts
;
543 msg
= bt_message_event_create(msg_iter
->pc_msg_iter
,
544 dmesg_comp
->event_class
, dmesg_comp
->packet
);
548 BT_LOGE_STR("Cannot create event message.");
552 event
= bt_message_event_borrow_event(msg
);
557 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
564 int fill_event_payload_from_line(struct dmesg_component
*dmesg_comp
,
565 const char *line
, bt_event
*event
)
567 bt_field
*ep_field
= NULL
;
568 bt_field
*str_field
= NULL
;
572 ep_field
= bt_event_borrow_payload_field(event
);
574 str_field
= bt_field_structure_borrow_member_field_by_index(
577 BT_LOGE_STR("Cannot borrow `timestamp` field from event payload structure field.");
582 if (line
[len
- 1] == '\n') {
583 /* Do not include the newline character in the payload */
587 ret
= bt_field_string_clear(str_field
);
589 BT_LOGE_STR("Cannot clear string field object.");
593 ret
= bt_field_string_append_with_length(str_field
, line
, len
);
595 BT_LOGE("Cannot append value to string field object: "
610 bt_message
*create_msg_from_line(
611 struct dmesg_msg_iter
*dmesg_msg_iter
, const char *line
)
613 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
614 bt_event
*event
= NULL
;
615 bt_message
*msg
= NULL
;
616 const char *new_start
;
619 msg
= create_init_event_msg_from_line(dmesg_msg_iter
,
622 BT_LOGE_STR("Cannot create and initialize event message from line.");
626 event
= bt_message_event_borrow_event(msg
);
628 ret
= fill_event_payload_from_line(dmesg_comp
, new_start
, event
);
630 BT_LOGE("Cannot fill event payload field from line: "
638 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
645 void destroy_dmesg_msg_iter(struct dmesg_msg_iter
*dmesg_msg_iter
)
647 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
649 if (!dmesg_msg_iter
) {
653 if (dmesg_msg_iter
->fp
&& dmesg_msg_iter
->fp
!= stdin
) {
654 if (fclose(dmesg_msg_iter
->fp
)) {
655 BT_LOGE_ERRNO("Cannot close input file", ".");
659 bt_message_put_ref(dmesg_msg_iter
->tmp_event_msg
);
660 free(dmesg_msg_iter
->linebuf
);
661 g_free(dmesg_msg_iter
);
667 bt_self_message_iterator_status
dmesg_msg_iter_init(
668 bt_self_message_iterator
*self_msg_iter
,
669 bt_self_component_source
*self_comp
,
670 bt_self_component_port_output
*self_port
)
672 struct dmesg_component
*dmesg_comp
= bt_self_component_get_data(
673 bt_self_component_source_as_self_component(self_comp
));
674 struct dmesg_msg_iter
*dmesg_msg_iter
=
675 g_new0(struct dmesg_msg_iter
, 1);
676 bt_self_message_iterator_status status
=
677 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
679 if (!dmesg_msg_iter
) {
680 BT_LOGE_STR("Failed to allocate on dmesg message iterator structure.");
684 BT_ASSERT(dmesg_comp
);
685 dmesg_msg_iter
->dmesg_comp
= dmesg_comp
;
686 dmesg_msg_iter
->pc_msg_iter
= self_msg_iter
;
688 if (dmesg_comp
->params
.read_from_stdin
) {
689 dmesg_msg_iter
->fp
= stdin
;
691 dmesg_msg_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
692 if (!dmesg_msg_iter
->fp
) {
693 BT_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
694 dmesg_comp
->params
.path
->str
);
699 bt_self_message_iterator_set_data(self_msg_iter
,
704 destroy_dmesg_msg_iter(dmesg_msg_iter
);
705 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
707 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
715 void dmesg_msg_iter_finalize(
716 bt_self_message_iterator
*priv_msg_iter
)
718 destroy_dmesg_msg_iter(bt_self_message_iterator_get_data(
723 bt_self_message_iterator_status
dmesg_msg_iter_next_one(
724 struct dmesg_msg_iter
*dmesg_msg_iter
,
728 struct dmesg_component
*dmesg_comp
;
729 bt_self_message_iterator_status status
=
730 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
732 BT_ASSERT(dmesg_msg_iter
);
733 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
734 BT_ASSERT(dmesg_comp
);
736 if (dmesg_msg_iter
->state
== STATE_DONE
) {
737 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_END
;
741 if (dmesg_msg_iter
->tmp_event_msg
||
742 dmesg_msg_iter
->state
== STATE_EMIT_PACKET_END
||
743 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_ACTIVITY_END
||
744 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_END
) {
750 bool only_spaces
= true;
752 len
= bt_getline(&dmesg_msg_iter
->linebuf
,
753 &dmesg_msg_iter
->linebuf_len
, dmesg_msg_iter
->fp
);
755 if (errno
== EINVAL
) {
756 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
757 } else if (errno
== ENOMEM
) {
759 BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
761 if (dmesg_msg_iter
->state
== STATE_EMIT_STREAM_BEGINNING
) {
762 /* Stream did not even begin */
763 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_END
;
766 /* End current packet now */
767 dmesg_msg_iter
->state
=
768 STATE_EMIT_PACKET_END
;
776 BT_ASSERT(dmesg_msg_iter
->linebuf
);
778 /* Ignore empty lines, once trimmed */
779 for (ch
= dmesg_msg_iter
->linebuf
; *ch
!= '\0'; ch
++) {
791 dmesg_msg_iter
->tmp_event_msg
= create_msg_from_line(
792 dmesg_msg_iter
, dmesg_msg_iter
->linebuf
);
793 if (!dmesg_msg_iter
->tmp_event_msg
) {
794 BT_LOGE("Cannot create event message from line: "
795 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
796 dmesg_msg_iter
->linebuf
);
801 BT_ASSERT(dmesg_comp
->trace
);
803 switch (dmesg_msg_iter
->state
) {
804 case STATE_EMIT_STREAM_BEGINNING
:
805 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
806 *msg
= bt_message_stream_beginning_create(
807 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
808 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_ACTIVITY_BEGINNING
;
810 case STATE_EMIT_STREAM_ACTIVITY_BEGINNING
:
811 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
812 *msg
= bt_message_stream_activity_beginning_create(
813 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
814 dmesg_msg_iter
->state
= STATE_EMIT_PACKET_BEGINNING
;
816 case STATE_EMIT_PACKET_BEGINNING
:
817 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
819 if (dmesg_comp
->clock_class
) {
820 *msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
821 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
,
822 dmesg_msg_iter
->last_clock_value
);
824 *msg
= bt_message_packet_beginning_create(
825 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
);
828 dmesg_msg_iter
->state
= STATE_EMIT_EVENT
;
830 case STATE_EMIT_EVENT
:
831 BT_ASSERT(dmesg_msg_iter
->tmp_event_msg
);
832 *msg
= dmesg_msg_iter
->tmp_event_msg
;
833 dmesg_msg_iter
->tmp_event_msg
= NULL
;
835 case STATE_EMIT_PACKET_END
:
836 if (dmesg_comp
->clock_class
) {
837 *msg
= bt_message_packet_end_create_with_default_clock_snapshot(
838 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
,
839 dmesg_msg_iter
->last_clock_value
);
841 *msg
= bt_message_packet_end_create(
842 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->packet
);
845 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_ACTIVITY_END
;
847 case STATE_EMIT_STREAM_ACTIVITY_END
:
848 *msg
= bt_message_stream_activity_end_create(
849 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
850 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_END
;
852 case STATE_EMIT_STREAM_END
:
853 *msg
= bt_message_stream_end_create(
854 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
855 dmesg_msg_iter
->state
= STATE_DONE
;
862 BT_LOGE("Cannot create message: dmesg-comp-addr=%p",
864 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
872 bt_self_message_iterator_status
dmesg_msg_iter_next(
873 bt_self_message_iterator
*self_msg_iter
,
874 bt_message_array_const msgs
, uint64_t capacity
,
877 struct dmesg_msg_iter
*dmesg_msg_iter
=
878 bt_self_message_iterator_get_data(
880 bt_self_message_iterator_status status
=
881 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
884 while (i
< capacity
&&
885 status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
886 bt_message
*priv_msg
= NULL
;
888 status
= dmesg_msg_iter_next_one(dmesg_msg_iter
,
891 if (status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
898 * Even if dmesg_msg_iter_next_one() returned
899 * something else than
900 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
901 * accumulated message objects in the output
902 * message array, so we need to return
903 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they
904 * are transfered to downstream. This other status
905 * occurs again the next time muxer_msg_iter_do_next()
906 * is called, possibly without any accumulated
907 * message, in which case we'll return it.
910 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
917 bt_bool
dmesg_msg_iter_can_seek_beginning(
918 bt_self_message_iterator
*self_msg_iter
)
920 struct dmesg_msg_iter
*dmesg_msg_iter
=
921 bt_self_message_iterator_get_data(self_msg_iter
);
923 /* Can't seek the beginning of the standard input stream */
924 return !dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
;
928 bt_self_message_iterator_status
dmesg_msg_iter_seek_beginning(
929 bt_self_message_iterator
*self_msg_iter
)
931 struct dmesg_msg_iter
*dmesg_msg_iter
=
932 bt_self_message_iterator_get_data(self_msg_iter
);
934 BT_ASSERT(!dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
);
936 BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter
->tmp_event_msg
);
937 dmesg_msg_iter
->last_clock_value
= 0;
938 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_BEGINNING
;
939 return BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;