2 * Babeltrace - CTF message iterator
4 * Copyright (c) 2015-2018 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #define BT_COMP_LOG_SELF_COMP (notit->self_comp)
27 #define BT_LOG_OUTPUT_LEVEL (notit->log_level)
28 #define BT_LOG_TAG "PLUGIN/CTF/MSG-ITER"
29 #include "logging/comp-logging.h"
36 #include "common/assert.h"
38 #include <babeltrace2/babeltrace.h>
39 #include "common/common.h"
44 #include "../bfcr/bfcr.h"
48 /* A visit stack entry */
51 * Current base field, one of:
63 /* Index of next field to set */
71 struct bt_msg_iter
*notit
;
73 /* Entries (struct stack_entry) */
76 /* Number of active entries */
84 STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN
,
85 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE
,
86 STATE_AFTER_TRACE_PACKET_HEADER
,
87 STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN
,
88 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE
,
89 STATE_AFTER_STREAM_PACKET_CONTEXT
,
90 STATE_CHECK_EMIT_MSG_STREAM_BEGINNING
,
91 STATE_EMIT_MSG_STREAM_BEGINNING
,
92 STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
,
93 STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
,
94 STATE_EMIT_MSG_DISCARDED_EVENTS
,
95 STATE_EMIT_MSG_DISCARDED_PACKETS
,
96 STATE_EMIT_MSG_PACKET_BEGINNING
,
97 STATE_DSCOPE_EVENT_HEADER_BEGIN
,
98 STATE_DSCOPE_EVENT_HEADER_CONTINUE
,
99 STATE_AFTER_EVENT_HEADER
,
100 STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN
,
101 STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE
,
102 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
,
103 STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE
,
104 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
,
105 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE
,
106 STATE_EMIT_MSG_EVENT
,
107 STATE_SKIP_PACKET_PADDING
,
108 STATE_EMIT_MSG_PACKET_END_MULTI
,
109 STATE_EMIT_MSG_PACKET_END_SINGLE
,
110 STATE_CHECK_EMIT_MSG_STREAM_END
,
111 STATE_EMIT_MSG_STREAM_END
,
115 struct end_of_packet_snapshots
{
116 uint64_t discarded_events
;
118 uint64_t beginning_clock
;
122 /* CTF message iterator */
127 /* Current message iterator to create messages (weak) */
128 bt_self_message_iterator
*msg_iter
;
130 /* True to emit a stream beginning message. */
131 bool emit_stream_begin_msg
;
133 /* True to emit a stream end message. */
134 bool emit_stream_end_msg
;
136 /* True to set the stream */
140 * Current dynamic scope field pointer.
142 * This is set by read_dscope_begin_state() and contains the
143 * value of one of the pointers in `dscopes` below.
145 bt_field
*cur_dscope_field
;
148 * True if we're done filling a string field from a text
149 * array/sequence payload.
151 bool done_filling_string
;
153 /* Trace and classes */
154 /* True to set IR fields */
158 struct ctf_trace_class
*tc
;
159 struct ctf_stream_class
*sc
;
160 struct ctf_event_class
*ec
;
163 /* Current packet context field wrapper (NULL if not created yet) */
164 bt_packet_context_field
*packet_context_field
;
166 /* Current packet (NULL if not created yet) */
169 /* Current stream (NULL if not set yet) */
172 /* Current event (NULL if not created yet) */
175 /* Current event message (NULL if not created yet) */
176 bt_message
*event_msg
;
178 /* Database of current dynamic scopes */
180 bt_field
*stream_packet_context
;
181 bt_field
*event_common_context
;
182 bt_field
*event_spec_context
;
183 bt_field
*event_payload
;
189 /* Current medium buffer data */
191 /* Last address provided by medium */
194 /* Buffer size provided by medium (bytes) */
197 /* Offset within whole packet of addr (bits) */
198 size_t packet_offset
;
200 /* Current position from addr (bits) */
203 /* Position of the last event header from addr (bits) */
207 /* Binary type reader */
208 struct bt_bfcr
*bfcr
;
210 /* Current medium data */
212 struct bt_msg_iter_medium_ops medops
;
213 size_t max_request_sz
;
217 /* Current packet size (bits) (-1 if unknown) */
218 int64_t cur_exp_packet_total_size
;
220 /* Current content size (bits) (-1 if unknown) */
221 int64_t cur_exp_packet_content_size
;
223 /* Current stream class ID */
224 int64_t cur_stream_class_id
;
226 /* Current event class ID */
227 int64_t cur_event_class_id
;
229 /* Current data stream ID */
230 int64_t cur_data_stream_id
;
233 * Offset, in the underlying media, of the current packet's
234 * start (-1 if unknown).
236 off_t cur_packet_offset
;
238 /* Default clock's current value */
239 uint64_t default_clock_snapshot
;
241 /* End of current packet snapshots */
242 struct end_of_packet_snapshots snapshots
;
244 /* End of previous packet snapshots */
245 struct end_of_packet_snapshots prev_packet_snapshots
;
247 /* Stored values (for sequence lengths, variant tags) */
248 GArray
*stored_values
;
250 /* Iterator's current log level */
251 bt_logging_level log_level
;
253 /* Iterator's owning self component, or `NULL` if none (query) */
254 bt_self_component
*self_comp
;
258 const char *state_string(enum state state
)
263 case STATE_SWITCH_PACKET
:
264 return "SWITCH_PACKET";
265 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN
:
266 return "DSCOPE_TRACE_PACKET_HEADER_BEGIN";
267 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE
:
268 return "DSCOPE_TRACE_PACKET_HEADER_CONTINUE";
269 case STATE_AFTER_TRACE_PACKET_HEADER
:
270 return "AFTER_TRACE_PACKET_HEADER";
271 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN
:
272 return "DSCOPE_STREAM_PACKET_CONTEXT_BEGIN";
273 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE
:
274 return "DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE";
275 case STATE_AFTER_STREAM_PACKET_CONTEXT
:
276 return "AFTER_STREAM_PACKET_CONTEXT";
277 case STATE_EMIT_MSG_STREAM_BEGINNING
:
278 return "EMIT_MSG_STREAM_BEGINNING";
279 case STATE_EMIT_MSG_PACKET_BEGINNING
:
280 return "EMIT_MSG_PACKET_BEGINNING";
281 case STATE_EMIT_MSG_DISCARDED_EVENTS
:
282 return "EMIT_MSG_DISCARDED_EVENTS";
283 case STATE_EMIT_MSG_DISCARDED_PACKETS
:
284 return "EMIT_MSG_DISCARDED_PACKETS";
285 case STATE_DSCOPE_EVENT_HEADER_BEGIN
:
286 return "DSCOPE_EVENT_HEADER_BEGIN";
287 case STATE_DSCOPE_EVENT_HEADER_CONTINUE
:
288 return "DSCOPE_EVENT_HEADER_CONTINUE";
289 case STATE_AFTER_EVENT_HEADER
:
290 return "AFTER_EVENT_HEADER";
291 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN
:
292 return "DSCOPE_EVENT_COMMON_CONTEXT_BEGIN";
293 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE
:
294 return "DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE";
295 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
:
296 return "DSCOPE_EVENT_SPEC_CONTEXT_BEGIN";
297 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE
:
298 return "DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE";
299 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
:
300 return "DSCOPE_EVENT_PAYLOAD_BEGIN";
301 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE
:
302 return "DSCOPE_EVENT_PAYLOAD_CONTINUE";
303 case STATE_EMIT_MSG_EVENT
:
304 return "EMIT_MSG_EVENT";
305 case STATE_SKIP_PACKET_PADDING
:
306 return "SKIP_PACKET_PADDING";
307 case STATE_EMIT_MSG_PACKET_END_MULTI
:
308 return "EMIT_MSG_PACKET_END_MULTI";
309 case STATE_EMIT_MSG_PACKET_END_SINGLE
:
310 return "EMIT_MSG_PACKET_END_SINGLE";
311 case STATE_EMIT_MSG_STREAM_END
:
312 return "EMIT_MSG_STREAM_END";
321 struct stack
*stack_new(struct bt_msg_iter
*notit
)
323 struct stack
*stack
= NULL
;
325 stack
= g_new0(struct stack
, 1);
327 BT_COMP_LOGE_STR("Failed to allocate one stack.");
331 stack
->notit
= notit
;
332 stack
->entries
= g_array_new(FALSE
, TRUE
, sizeof(struct stack_entry
));
333 if (!stack
->entries
) {
334 BT_COMP_LOGE_STR("Failed to allocate a GArray.");
338 BT_COMP_LOGD("Created stack: notit-addr=%p, stack-addr=%p", notit
, stack
);
350 void stack_destroy(struct stack
*stack
)
352 struct bt_msg_iter
*notit
;
355 notit
= stack
->notit
;
356 BT_COMP_LOGD("Destroying stack: addr=%p", stack
);
358 if (stack
->entries
) {
359 g_array_free(stack
->entries
, TRUE
);
366 void stack_push(struct stack
*stack
, bt_field
*base
)
368 struct stack_entry
*entry
;
369 struct bt_msg_iter
*notit
;
372 notit
= stack
->notit
;
374 BT_COMP_LOGT("Pushing base field on stack: stack-addr=%p, "
375 "stack-size-before=%zu, stack-size-after=%zu",
376 stack
, stack
->size
, stack
->size
+ 1);
378 if (stack
->entries
->len
== stack
->size
) {
379 g_array_set_size(stack
->entries
, stack
->size
+ 1);
382 entry
= &g_array_index(stack
->entries
, struct stack_entry
, stack
->size
);
389 unsigned int stack_size(struct stack
*stack
)
396 void stack_pop(struct stack
*stack
)
398 struct bt_msg_iter
*notit
;
401 BT_ASSERT(stack_size(stack
));
402 notit
= stack
->notit
;
403 BT_COMP_LOGT("Popping from stack: "
404 "stack-addr=%p, stack-size-before=%zu, stack-size-after=%zu",
405 stack
, stack
->size
, stack
->size
- 1);
410 struct stack_entry
*stack_top(struct stack
*stack
)
413 BT_ASSERT(stack_size(stack
));
414 return &g_array_index(stack
->entries
, struct stack_entry
,
419 bool stack_empty(struct stack
*stack
)
421 return stack_size(stack
) == 0;
425 void stack_clear(struct stack
*stack
)
432 enum bt_msg_iter_status
msg_iter_status_from_m_status(
433 enum bt_msg_iter_medium_status m_status
)
435 /* They are the same */
436 return (int) m_status
;
440 size_t buf_size_bits(struct bt_msg_iter
*notit
)
442 return notit
->buf
.sz
* 8;
446 size_t buf_available_bits(struct bt_msg_iter
*notit
)
448 return buf_size_bits(notit
) - notit
->buf
.at
;
452 size_t packet_at(struct bt_msg_iter
*notit
)
454 return notit
->buf
.packet_offset
+ notit
->buf
.at
;
458 void buf_consume_bits(struct bt_msg_iter
*notit
, size_t incr
)
460 BT_COMP_LOGT("Advancing cursor: notit-addr=%p, cur-before=%zu, cur-after=%zu",
461 notit
, notit
->buf
.at
, notit
->buf
.at
+ incr
);
462 notit
->buf
.at
+= incr
;
466 enum bt_msg_iter_status
request_medium_bytes(
467 struct bt_msg_iter
*notit
)
469 uint8_t *buffer_addr
= NULL
;
470 size_t buffer_sz
= 0;
471 enum bt_msg_iter_medium_status m_status
;
473 BT_COMP_LOGD("Calling user function (request bytes): notit-addr=%p, "
474 "request-size=%zu", notit
, notit
->medium
.max_request_sz
);
475 m_status
= notit
->medium
.medops
.request_bytes(
476 notit
->medium
.max_request_sz
, &buffer_addr
,
477 &buffer_sz
, notit
->medium
.data
);
478 BT_COMP_LOGD("User function returned: status=%s, buf-addr=%p, buf-size=%zu",
479 bt_msg_iter_medium_status_string(m_status
),
480 buffer_addr
, buffer_sz
);
481 if (m_status
== BT_MSG_ITER_MEDIUM_STATUS_OK
) {
482 BT_ASSERT(buffer_sz
!= 0);
484 /* New packet offset is old one + old size (in bits) */
485 notit
->buf
.packet_offset
+= buf_size_bits(notit
);
487 /* Restart at the beginning of the new medium buffer */
489 notit
->buf
.last_eh_at
= SIZE_MAX
;
491 /* New medium buffer size */
492 notit
->buf
.sz
= buffer_sz
;
494 /* New medium buffer address */
495 notit
->buf
.addr
= buffer_addr
;
497 BT_COMP_LOGD("User function returned new bytes: "
498 "packet-offset=%zu, cur=%zu, size=%zu, addr=%p",
499 notit
->buf
.packet_offset
, notit
->buf
.at
,
500 notit
->buf
.sz
, notit
->buf
.addr
);
501 BT_COMP_LOGD_MEM(buffer_addr
, buffer_sz
, "Returned bytes at %p:",
503 } else if (m_status
== BT_MSG_ITER_MEDIUM_STATUS_EOF
) {
505 * User returned end of stream: validate that we're not
506 * in the middle of a packet header, packet context, or
509 if (notit
->cur_exp_packet_total_size
>= 0) {
510 if (packet_at(notit
) ==
511 notit
->cur_exp_packet_total_size
) {
515 if (packet_at(notit
) == 0) {
519 if (notit
->buf
.last_eh_at
!= SIZE_MAX
&&
520 notit
->buf
.at
== notit
->buf
.last_eh_at
) {
525 /* All other states are invalid */
526 BT_COMP_LOGW("User function returned %s, but message iterator is in an unexpected state: "
527 "state=%s, cur-packet-size=%" PRId64
", cur=%zu, "
528 "packet-cur=%zu, last-eh-at=%zu",
529 bt_msg_iter_medium_status_string(m_status
),
530 state_string(notit
->state
),
531 notit
->cur_exp_packet_total_size
,
532 notit
->buf
.at
, packet_at(notit
),
533 notit
->buf
.last_eh_at
);
534 m_status
= BT_MSG_ITER_MEDIUM_STATUS_ERROR
;
535 } else if (m_status
< 0) {
536 BT_COMP_LOGW("User function failed: status=%s",
537 bt_msg_iter_medium_status_string(m_status
));
541 return msg_iter_status_from_m_status(m_status
);
545 enum bt_msg_iter_status
buf_ensure_available_bits(
546 struct bt_msg_iter
*notit
)
548 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
550 if (G_UNLIKELY(buf_available_bits(notit
) == 0)) {
552 * This _cannot_ return BT_MSG_ITER_STATUS_OK
555 status
= request_medium_bytes(notit
);
562 enum bt_msg_iter_status
read_dscope_begin_state(
563 struct bt_msg_iter
*notit
,
564 struct ctf_field_class
*dscope_fc
,
565 enum state done_state
, enum state continue_state
,
566 bt_field
*dscope_field
)
568 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
569 enum bt_bfcr_status bfcr_status
;
570 size_t consumed_bits
;
572 notit
->cur_dscope_field
= dscope_field
;
573 BT_COMP_LOGT("Starting BFCR: notit-addr=%p, bfcr-addr=%p, fc-addr=%p",
574 notit
, notit
->bfcr
, dscope_fc
);
575 consumed_bits
= bt_bfcr_start(notit
->bfcr
, dscope_fc
,
576 notit
->buf
.addr
, notit
->buf
.at
, packet_at(notit
),
577 notit
->buf
.sz
, &bfcr_status
);
578 BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits
);
580 switch (bfcr_status
) {
581 case BT_BFCR_STATUS_OK
:
582 /* Field class was read completely */
583 BT_COMP_LOGT_STR("Field was completely decoded.");
584 notit
->state
= done_state
;
586 case BT_BFCR_STATUS_EOF
:
587 BT_COMP_LOGT_STR("BFCR needs more data to decode field completely.");
588 notit
->state
= continue_state
;
591 BT_COMP_LOGW("BFCR failed to start: notit-addr=%p, bfcr-addr=%p, "
592 "status=%s", notit
, notit
->bfcr
,
593 bt_bfcr_status_string(bfcr_status
));
594 status
= BT_MSG_ITER_STATUS_ERROR
;
598 /* Consume bits now since we know we're not in an error state */
599 buf_consume_bits(notit
, consumed_bits
);
606 enum bt_msg_iter_status
read_dscope_continue_state(
607 struct bt_msg_iter
*notit
, enum state done_state
)
609 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
610 enum bt_bfcr_status bfcr_status
;
611 size_t consumed_bits
;
613 BT_COMP_LOGT("Continuing BFCR: notit-addr=%p, bfcr-addr=%p",
616 status
= buf_ensure_available_bits(notit
);
617 if (status
!= BT_MSG_ITER_STATUS_OK
) {
619 BT_COMP_LOGW("Cannot ensure that buffer has at least one byte: "
620 "msg-addr=%p, status=%s",
621 notit
, bt_msg_iter_status_string(status
));
623 BT_COMP_LOGT("Cannot ensure that buffer has at least one byte: "
624 "msg-addr=%p, status=%s",
625 notit
, bt_msg_iter_status_string(status
));
631 consumed_bits
= bt_bfcr_continue(notit
->bfcr
, notit
->buf
.addr
,
632 notit
->buf
.sz
, &bfcr_status
);
633 BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits
);
635 switch (bfcr_status
) {
636 case BT_BFCR_STATUS_OK
:
637 /* Type was read completely. */
638 BT_COMP_LOGT_STR("Field was completely decoded.");
639 notit
->state
= done_state
;
641 case BT_BFCR_STATUS_EOF
:
642 /* Stay in this continue state. */
643 BT_COMP_LOGT_STR("BFCR needs more data to decode field completely.");
646 BT_COMP_LOGW("BFCR failed to continue: notit-addr=%p, bfcr-addr=%p, "
647 "status=%s", notit
, notit
->bfcr
,
648 bt_bfcr_status_string(bfcr_status
));
649 status
= BT_MSG_ITER_STATUS_ERROR
;
653 /* Consume bits now since we know we're not in an error state. */
654 buf_consume_bits(notit
, consumed_bits
);
660 void release_event_dscopes(struct bt_msg_iter
*notit
)
662 notit
->dscopes
.event_common_context
= NULL
;
663 notit
->dscopes
.event_spec_context
= NULL
;
664 notit
->dscopes
.event_payload
= NULL
;
668 void release_all_dscopes(struct bt_msg_iter
*notit
)
670 notit
->dscopes
.stream_packet_context
= NULL
;
672 if (notit
->packet_context_field
) {
673 bt_packet_context_field_release(notit
->packet_context_field
);
674 notit
->packet_context_field
= NULL
;
677 release_event_dscopes(notit
);
681 enum bt_msg_iter_status
switch_packet_state(struct bt_msg_iter
*notit
)
683 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
686 * We don't put the stream class here because we need to make
687 * sure that all the packets processed by the same message
688 * iterator refer to the same stream class (the first one).
692 if (notit
->cur_exp_packet_total_size
!= -1) {
693 notit
->cur_packet_offset
+= notit
->cur_exp_packet_total_size
;
696 BT_COMP_LOGD("Switching packet: notit-addr=%p, cur=%zu, "
697 "packet-offset=%" PRId64
, notit
, notit
->buf
.at
,
698 notit
->cur_packet_offset
);
699 stack_clear(notit
->stack
);
700 notit
->meta
.ec
= NULL
;
701 BT_PACKET_PUT_REF_AND_RESET(notit
->packet
);
702 BT_MESSAGE_PUT_REF_AND_RESET(notit
->event_msg
);
703 release_all_dscopes(notit
);
704 notit
->cur_dscope_field
= NULL
;
707 * Adjust current buffer so that addr points to the beginning of the new
710 if (notit
->buf
.addr
) {
711 size_t consumed_bytes
= (size_t) (notit
->buf
.at
/ CHAR_BIT
);
713 /* Packets are assumed to start on a byte frontier. */
714 if (notit
->buf
.at
% CHAR_BIT
) {
715 BT_COMP_LOGW("Cannot switch packet: current position is not a multiple of 8: "
716 "notit-addr=%p, cur=%zu", notit
, notit
->buf
.at
);
717 status
= BT_MSG_ITER_STATUS_ERROR
;
721 notit
->buf
.addr
+= consumed_bytes
;
722 notit
->buf
.sz
-= consumed_bytes
;
724 notit
->buf
.packet_offset
= 0;
725 BT_COMP_LOGD("Adjusted buffer: addr=%p, size=%zu",
726 notit
->buf
.addr
, notit
->buf
.sz
);
729 notit
->cur_exp_packet_content_size
= -1;
730 notit
->cur_exp_packet_total_size
= -1;
731 notit
->cur_stream_class_id
= -1;
732 notit
->cur_event_class_id
= -1;
733 notit
->cur_data_stream_id
= -1;
734 notit
->prev_packet_snapshots
= notit
->snapshots
;
735 notit
->snapshots
.discarded_events
= UINT64_C(-1);
736 notit
->snapshots
.packets
= UINT64_C(-1);
737 notit
->snapshots
.beginning_clock
= UINT64_C(-1);
738 notit
->snapshots
.end_clock
= UINT64_C(-1);
739 notit
->state
= STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN
;
746 enum bt_msg_iter_status
read_packet_header_begin_state(
747 struct bt_msg_iter
*notit
)
749 struct ctf_field_class
*packet_header_fc
= NULL
;
750 enum bt_msg_iter_status ret
= BT_MSG_ITER_STATUS_OK
;
753 * Make sure at least one bit is available for this packet. An
754 * empty packet is impossible. If we reach the end of the medium
755 * at this point, then it's considered the end of the stream.
757 ret
= buf_ensure_available_bits(notit
);
759 case BT_MSG_ITER_STATUS_OK
:
761 case BT_MSG_ITER_STATUS_EOF
:
762 ret
= BT_MSG_ITER_STATUS_OK
;
763 notit
->state
= STATE_CHECK_EMIT_MSG_STREAM_END
;
769 /* Packet header class is common to the whole trace class. */
770 packet_header_fc
= notit
->meta
.tc
->packet_header_fc
;
771 if (!packet_header_fc
) {
772 notit
->state
= STATE_AFTER_TRACE_PACKET_HEADER
;
776 notit
->cur_stream_class_id
= -1;
777 notit
->cur_event_class_id
= -1;
778 notit
->cur_data_stream_id
= -1;
779 BT_COMP_LOGD("Decoding packet header field:"
780 "notit-addr=%p, trace-class-addr=%p, fc-addr=%p",
781 notit
, notit
->meta
.tc
, packet_header_fc
);
782 ret
= read_dscope_begin_state(notit
, packet_header_fc
,
783 STATE_AFTER_TRACE_PACKET_HEADER
,
784 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE
, NULL
);
786 BT_COMP_LOGW("Cannot decode packet header field: "
787 "notit-addr=%p, trace-class-addr=%p, "
789 notit
, notit
->meta
.tc
, packet_header_fc
);
797 enum bt_msg_iter_status
read_packet_header_continue_state(
798 struct bt_msg_iter
*notit
)
800 return read_dscope_continue_state(notit
,
801 STATE_AFTER_TRACE_PACKET_HEADER
);
805 enum bt_msg_iter_status
set_current_stream_class(struct bt_msg_iter
*notit
)
807 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
808 struct ctf_stream_class
*new_stream_class
= NULL
;
810 if (notit
->cur_stream_class_id
== -1) {
812 * No current stream class ID field, therefore only one
815 if (notit
->meta
.tc
->stream_classes
->len
!= 1) {
816 BT_COMP_LOGW("Need exactly one stream class since there's "
817 "no stream class ID field: "
818 "notit-addr=%p", notit
);
819 status
= BT_MSG_ITER_STATUS_ERROR
;
823 new_stream_class
= notit
->meta
.tc
->stream_classes
->pdata
[0];
824 notit
->cur_stream_class_id
= new_stream_class
->id
;
827 new_stream_class
= ctf_trace_class_borrow_stream_class_by_id(
828 notit
->meta
.tc
, notit
->cur_stream_class_id
);
829 if (!new_stream_class
) {
830 BT_COMP_LOGW("No stream class with ID of stream class ID to use in trace class: "
831 "notit-addr=%p, stream-class-id=%" PRIu64
", "
832 "trace-class-addr=%p",
833 notit
, notit
->cur_stream_class_id
, notit
->meta
.tc
);
834 status
= BT_MSG_ITER_STATUS_ERROR
;
838 if (notit
->meta
.sc
) {
839 if (new_stream_class
!= notit
->meta
.sc
) {
840 BT_COMP_LOGW("Two packets refer to two different stream classes within the same packet sequence: "
841 "notit-addr=%p, prev-stream-class-addr=%p, "
842 "prev-stream-class-id=%" PRId64
", "
843 "next-stream-class-addr=%p, "
844 "next-stream-class-id=%" PRId64
", "
846 notit
, notit
->meta
.sc
,
849 new_stream_class
->id
,
851 status
= BT_MSG_ITER_STATUS_ERROR
;
855 notit
->meta
.sc
= new_stream_class
;
858 BT_COMP_LOGD("Set current stream class: "
859 "notit-addr=%p, stream-class-addr=%p, "
860 "stream-class-id=%" PRId64
,
861 notit
, notit
->meta
.sc
, notit
->meta
.sc
->id
);
868 enum bt_msg_iter_status
set_current_stream(struct bt_msg_iter
*notit
)
870 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
871 bt_stream
*stream
= NULL
;
873 BT_COMP_LOGD("Calling user function (get stream): notit-addr=%p, "
874 "stream-class-addr=%p, stream-class-id=%" PRId64
,
875 notit
, notit
->meta
.sc
,
877 stream
= notit
->medium
.medops
.borrow_stream(
878 notit
->meta
.sc
->ir_sc
, notit
->cur_data_stream_id
,
880 bt_stream_get_ref(stream
);
881 BT_COMP_LOGD("User function returned: stream-addr=%p", stream
);
883 BT_COMP_LOGW_STR("User function failed to return a stream object "
884 "for the given stream class.");
885 status
= BT_MSG_ITER_STATUS_ERROR
;
889 if (notit
->stream
&& stream
!= notit
->stream
) {
890 BT_COMP_LOGW("User function returned a different stream than the "
891 "previous one for the same sequence of packets.");
892 status
= BT_MSG_ITER_STATUS_ERROR
;
896 BT_STREAM_MOVE_REF(notit
->stream
, stream
);
899 bt_stream_put_ref(stream
);
904 enum bt_msg_iter_status
set_current_packet(struct bt_msg_iter
*notit
)
906 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
907 bt_packet
*packet
= NULL
;
909 BT_COMP_LOGD("Creating packet for packet message: "
910 "notit-addr=%p", notit
);
911 BT_COMP_LOGD("Creating packet from stream: "
912 "notit-addr=%p, stream-addr=%p, "
913 "stream-class-addr=%p, "
914 "stream-class-id=%" PRId64
,
915 notit
, notit
->stream
, notit
->meta
.sc
,
919 BT_ASSERT(notit
->stream
);
920 packet
= bt_packet_create(notit
->stream
);
922 BT_COMP_LOGE("Cannot create packet from stream: "
923 "notit-addr=%p, stream-addr=%p, "
924 "stream-class-addr=%p, "
925 "stream-class-id=%" PRId64
,
926 notit
, notit
->stream
, notit
->meta
.sc
,
934 BT_PACKET_PUT_REF_AND_RESET(packet
);
935 status
= BT_MSG_ITER_STATUS_ERROR
;
938 BT_PACKET_MOVE_REF(notit
->packet
, packet
);
943 enum bt_msg_iter_status
after_packet_header_state(
944 struct bt_msg_iter
*notit
)
946 enum bt_msg_iter_status status
;
948 status
= set_current_stream_class(notit
);
949 if (status
!= BT_MSG_ITER_STATUS_OK
) {
953 notit
->state
= STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN
;
960 enum bt_msg_iter_status
read_packet_context_begin_state(
961 struct bt_msg_iter
*notit
)
963 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
964 struct ctf_field_class
*packet_context_fc
;
966 BT_ASSERT(notit
->meta
.sc
);
967 packet_context_fc
= notit
->meta
.sc
->packet_context_fc
;
968 if (!packet_context_fc
) {
969 BT_COMP_LOGD("No packet packet context field class in stream class: continuing: "
970 "notit-addr=%p, stream-class-addr=%p, "
971 "stream-class-id=%" PRId64
,
972 notit
, notit
->meta
.sc
,
974 notit
->state
= STATE_AFTER_STREAM_PACKET_CONTEXT
;
978 BT_ASSERT(!notit
->packet_context_field
);
980 if (packet_context_fc
->in_ir
) {
982 * Create free packet context field from stream class.
983 * This field is going to be moved to the packet once we
984 * create it. We cannot create the packet now because a
985 * packet is created from a stream, and this API must be
986 * able to return the packet context properties without
988 * (bt_msg_iter_get_packet_properties()).
990 notit
->packet_context_field
=
991 bt_packet_context_field_create(
992 notit
->meta
.sc
->ir_sc
);
993 if (!notit
->packet_context_field
) {
994 BT_COMP_LOGE_STR("Cannot create packet context field wrapper from stream class.");
995 status
= BT_MSG_ITER_STATUS_ERROR
;
999 notit
->dscopes
.stream_packet_context
=
1000 bt_packet_context_field_borrow_field(
1001 notit
->packet_context_field
);
1002 BT_ASSERT(notit
->dscopes
.stream_packet_context
);
1005 BT_COMP_LOGD("Decoding packet context field: "
1006 "notit-addr=%p, stream-class-addr=%p, "
1007 "stream-class-id=%" PRId64
", fc-addr=%p",
1008 notit
, notit
->meta
.sc
,
1009 notit
->meta
.sc
->id
, packet_context_fc
);
1010 status
= read_dscope_begin_state(notit
, packet_context_fc
,
1011 STATE_AFTER_STREAM_PACKET_CONTEXT
,
1012 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE
,
1013 notit
->dscopes
.stream_packet_context
);
1015 BT_COMP_LOGW("Cannot decode packet context field: "
1016 "notit-addr=%p, stream-class-addr=%p, "
1017 "stream-class-id=%" PRId64
", fc-addr=%p",
1018 notit
, notit
->meta
.sc
,
1028 enum bt_msg_iter_status
read_packet_context_continue_state(
1029 struct bt_msg_iter
*notit
)
1031 return read_dscope_continue_state(notit
,
1032 STATE_AFTER_STREAM_PACKET_CONTEXT
);
1036 enum bt_msg_iter_status
set_current_packet_content_sizes(
1037 struct bt_msg_iter
*notit
)
1039 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1041 if (notit
->cur_exp_packet_total_size
== -1) {
1042 if (notit
->cur_exp_packet_content_size
!= -1) {
1043 notit
->cur_exp_packet_total_size
=
1044 notit
->cur_exp_packet_content_size
;
1047 if (notit
->cur_exp_packet_content_size
== -1) {
1048 notit
->cur_exp_packet_content_size
=
1049 notit
->cur_exp_packet_total_size
;
1053 BT_ASSERT((notit
->cur_exp_packet_total_size
>= 0 &&
1054 notit
->cur_exp_packet_content_size
>= 0) ||
1055 (notit
->cur_exp_packet_total_size
< 0 &&
1056 notit
->cur_exp_packet_content_size
< 0));
1058 if (notit
->cur_exp_packet_content_size
>
1059 notit
->cur_exp_packet_total_size
) {
1060 BT_COMP_LOGW("Invalid packet or content size: "
1061 "content size is greater than packet size: "
1062 "notit-addr=%p, packet-context-field-addr=%p, "
1063 "packet-size=%" PRId64
", content-size=%" PRId64
,
1064 notit
, notit
->dscopes
.stream_packet_context
,
1065 notit
->cur_exp_packet_total_size
,
1066 notit
->cur_exp_packet_content_size
);
1067 status
= BT_MSG_ITER_STATUS_ERROR
;
1071 BT_COMP_LOGD("Set current packet and content sizes: "
1072 "notit-addr=%p, packet-size=%" PRIu64
", content-size=%" PRIu64
,
1073 notit
, notit
->cur_exp_packet_total_size
,
1074 notit
->cur_exp_packet_content_size
);
1081 enum bt_msg_iter_status
after_packet_context_state(struct bt_msg_iter
*notit
)
1083 enum bt_msg_iter_status status
;
1085 status
= set_current_packet_content_sizes(notit
);
1086 if (status
!= BT_MSG_ITER_STATUS_OK
) {
1090 if (notit
->stream
) {
1092 * Stream exists, which means we already emitted at
1093 * least one packet beginning message, so the initial
1094 * stream beginning message was also emitted.
1096 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
;
1098 notit
->state
= STATE_CHECK_EMIT_MSG_STREAM_BEGINNING
;
1106 enum bt_msg_iter_status
read_event_header_begin_state(struct bt_msg_iter
*notit
)
1108 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1109 struct ctf_field_class
*event_header_fc
= NULL
;
1111 /* Reset the position of the last event header */
1112 notit
->buf
.last_eh_at
= notit
->buf
.at
;
1113 notit
->cur_event_class_id
= -1;
1115 /* Check if we have some content left */
1116 if (notit
->cur_exp_packet_content_size
>= 0) {
1117 if (G_UNLIKELY(packet_at(notit
) ==
1118 notit
->cur_exp_packet_content_size
)) {
1119 /* No more events! */
1120 BT_COMP_LOGD("Reached end of packet: notit-addr=%p, "
1121 "cur=%zu", notit
, packet_at(notit
));
1122 notit
->state
= STATE_EMIT_MSG_PACKET_END_MULTI
;
1124 } else if (G_UNLIKELY(packet_at(notit
) >
1125 notit
->cur_exp_packet_content_size
)) {
1126 /* That's not supposed to happen */
1127 BT_COMP_LOGD("Before decoding event header field: cursor is passed the packet's content: "
1128 "notit-addr=%p, content-size=%" PRId64
", "
1130 notit
->cur_exp_packet_content_size
,
1132 status
= BT_MSG_ITER_STATUS_ERROR
;
1137 * "Infinite" content: we're done when the medium has
1138 * nothing else for us.
1140 status
= buf_ensure_available_bits(notit
);
1142 case BT_MSG_ITER_STATUS_OK
:
1144 case BT_MSG_ITER_STATUS_EOF
:
1145 status
= BT_MSG_ITER_STATUS_OK
;
1146 notit
->state
= STATE_EMIT_MSG_PACKET_END_SINGLE
;
1153 release_event_dscopes(notit
);
1154 BT_ASSERT(notit
->meta
.sc
);
1155 event_header_fc
= notit
->meta
.sc
->event_header_fc
;
1156 if (!event_header_fc
) {
1157 notit
->state
= STATE_AFTER_EVENT_HEADER
;
1161 BT_COMP_LOGD("Decoding event header field: "
1162 "notit-addr=%p, stream-class-addr=%p, "
1163 "stream-class-id=%" PRId64
", "
1165 notit
, notit
->meta
.sc
,
1168 status
= read_dscope_begin_state(notit
, event_header_fc
,
1169 STATE_AFTER_EVENT_HEADER
,
1170 STATE_DSCOPE_EVENT_HEADER_CONTINUE
, NULL
);
1172 BT_COMP_LOGW("Cannot decode event header field: "
1173 "notit-addr=%p, stream-class-addr=%p, "
1174 "stream-class-id=%" PRId64
", fc-addr=%p",
1175 notit
, notit
->meta
.sc
,
1185 enum bt_msg_iter_status
read_event_header_continue_state(
1186 struct bt_msg_iter
*notit
)
1188 return read_dscope_continue_state(notit
,
1189 STATE_AFTER_EVENT_HEADER
);
1193 enum bt_msg_iter_status
set_current_event_class(struct bt_msg_iter
*notit
)
1195 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1197 struct ctf_event_class
*new_event_class
= NULL
;
1199 if (notit
->cur_event_class_id
== -1) {
1201 * No current event class ID field, therefore only one
1204 if (notit
->meta
.sc
->event_classes
->len
!= 1) {
1205 BT_COMP_LOGW("Need exactly one event class since there's "
1206 "no event class ID field: "
1207 "notit-addr=%p", notit
);
1208 status
= BT_MSG_ITER_STATUS_ERROR
;
1212 new_event_class
= notit
->meta
.sc
->event_classes
->pdata
[0];
1213 notit
->cur_event_class_id
= new_event_class
->id
;
1216 new_event_class
= ctf_stream_class_borrow_event_class_by_id(
1217 notit
->meta
.sc
, notit
->cur_event_class_id
);
1218 if (!new_event_class
) {
1219 BT_COMP_LOGW("No event class with ID of event class ID to use in stream class: "
1220 "notit-addr=%p, stream-class-id=%" PRIu64
", "
1221 "event-class-id=%" PRIu64
", "
1222 "trace-class-addr=%p",
1223 notit
, notit
->meta
.sc
->id
, notit
->cur_event_class_id
,
1225 status
= BT_MSG_ITER_STATUS_ERROR
;
1229 notit
->meta
.ec
= new_event_class
;
1230 BT_COMP_LOGD("Set current event class: "
1231 "notit-addr=%p, event-class-addr=%p, "
1232 "event-class-id=%" PRId64
", "
1233 "event-class-name=\"%s\"",
1234 notit
, notit
->meta
.ec
, notit
->meta
.ec
->id
,
1235 notit
->meta
.ec
->name
->str
);
1242 enum bt_msg_iter_status
set_current_event_message(
1243 struct bt_msg_iter
*notit
)
1245 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1246 bt_message
*msg
= NULL
;
1248 BT_ASSERT(notit
->meta
.ec
);
1249 BT_ASSERT(notit
->packet
);
1250 BT_COMP_LOGD("Creating event message from event class and packet: "
1251 "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", packet-addr=%p",
1252 notit
, notit
->meta
.ec
,
1253 notit
->meta
.ec
->name
->str
,
1255 BT_ASSERT(notit
->msg_iter
);
1256 BT_ASSERT(notit
->meta
.sc
);
1258 if (bt_stream_class_borrow_default_clock_class(notit
->meta
.sc
->ir_sc
)) {
1259 msg
= bt_message_event_create_with_packet_and_default_clock_snapshot(
1260 notit
->msg_iter
, notit
->meta
.ec
->ir_ec
,
1261 notit
->packet
, notit
->default_clock_snapshot
);
1263 msg
= bt_message_event_create_with_packet(notit
->msg_iter
,
1264 notit
->meta
.ec
->ir_ec
, notit
->packet
);
1268 BT_COMP_LOGE("Cannot create event message: "
1269 "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
1271 notit
, notit
->meta
.ec
,
1272 notit
->meta
.ec
->name
->str
,
1280 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
1281 status
= BT_MSG_ITER_STATUS_ERROR
;
1284 BT_MESSAGE_MOVE_REF(notit
->event_msg
, msg
);
1289 enum bt_msg_iter_status
after_event_header_state(
1290 struct bt_msg_iter
*notit
)
1292 enum bt_msg_iter_status status
;
1294 status
= set_current_event_class(notit
);
1295 if (status
!= BT_MSG_ITER_STATUS_OK
) {
1299 status
= set_current_event_message(notit
);
1300 if (status
!= BT_MSG_ITER_STATUS_OK
) {
1304 notit
->event
= bt_message_event_borrow_event(
1306 BT_ASSERT(notit
->event
);
1307 notit
->state
= STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN
;
1314 enum bt_msg_iter_status
read_event_common_context_begin_state(
1315 struct bt_msg_iter
*notit
)
1317 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1318 struct ctf_field_class
*event_common_context_fc
;
1320 event_common_context_fc
= notit
->meta
.sc
->event_common_context_fc
;
1321 if (!event_common_context_fc
) {
1322 notit
->state
= STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
;
1326 if (event_common_context_fc
->in_ir
) {
1327 BT_ASSERT(!notit
->dscopes
.event_common_context
);
1328 notit
->dscopes
.event_common_context
=
1329 bt_event_borrow_common_context_field(
1331 BT_ASSERT(notit
->dscopes
.event_common_context
);
1334 BT_COMP_LOGT("Decoding event common context field: "
1335 "notit-addr=%p, stream-class-addr=%p, "
1336 "stream-class-id=%" PRId64
", "
1338 notit
, notit
->meta
.sc
,
1340 event_common_context_fc
);
1341 status
= read_dscope_begin_state(notit
, event_common_context_fc
,
1342 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
,
1343 STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE
,
1344 notit
->dscopes
.event_common_context
);
1346 BT_COMP_LOGW("Cannot decode event common context field: "
1347 "notit-addr=%p, stream-class-addr=%p, "
1348 "stream-class-id=%" PRId64
", fc-addr=%p",
1349 notit
, notit
->meta
.sc
,
1351 event_common_context_fc
);
1359 enum bt_msg_iter_status
read_event_common_context_continue_state(
1360 struct bt_msg_iter
*notit
)
1362 return read_dscope_continue_state(notit
,
1363 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
);
1367 enum bt_msg_iter_status
read_event_spec_context_begin_state(
1368 struct bt_msg_iter
*notit
)
1370 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1371 struct ctf_field_class
*event_spec_context_fc
;
1373 event_spec_context_fc
= notit
->meta
.ec
->spec_context_fc
;
1374 if (!event_spec_context_fc
) {
1375 notit
->state
= STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
;
1379 if (event_spec_context_fc
->in_ir
) {
1380 BT_ASSERT(!notit
->dscopes
.event_spec_context
);
1381 notit
->dscopes
.event_spec_context
=
1382 bt_event_borrow_specific_context_field(
1384 BT_ASSERT(notit
->dscopes
.event_spec_context
);
1387 BT_COMP_LOGT("Decoding event specific context field: "
1388 "notit-addr=%p, event-class-addr=%p, "
1389 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
1391 notit
, notit
->meta
.ec
,
1392 notit
->meta
.ec
->name
->str
,
1394 event_spec_context_fc
);
1395 status
= read_dscope_begin_state(notit
, event_spec_context_fc
,
1396 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
,
1397 STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE
,
1398 notit
->dscopes
.event_spec_context
);
1400 BT_COMP_LOGW("Cannot decode event specific context field: "
1401 "notit-addr=%p, event-class-addr=%p, "
1402 "event-class-name=\"%s\", "
1403 "event-class-id=%" PRId64
", fc-addr=%p",
1404 notit
, notit
->meta
.ec
,
1405 notit
->meta
.ec
->name
->str
,
1407 event_spec_context_fc
);
1415 enum bt_msg_iter_status
read_event_spec_context_continue_state(
1416 struct bt_msg_iter
*notit
)
1418 return read_dscope_continue_state(notit
,
1419 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
);
1423 enum bt_msg_iter_status
read_event_payload_begin_state(
1424 struct bt_msg_iter
*notit
)
1426 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1427 struct ctf_field_class
*event_payload_fc
;
1429 event_payload_fc
= notit
->meta
.ec
->payload_fc
;
1430 if (!event_payload_fc
) {
1431 notit
->state
= STATE_EMIT_MSG_EVENT
;
1435 if (event_payload_fc
->in_ir
) {
1436 BT_ASSERT(!notit
->dscopes
.event_payload
);
1437 notit
->dscopes
.event_payload
=
1438 bt_event_borrow_payload_field(
1440 BT_ASSERT(notit
->dscopes
.event_payload
);
1443 BT_COMP_LOGT("Decoding event payload field: "
1444 "notit-addr=%p, event-class-addr=%p, "
1445 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
1447 notit
, notit
->meta
.ec
,
1448 notit
->meta
.ec
->name
->str
,
1451 status
= read_dscope_begin_state(notit
, event_payload_fc
,
1452 STATE_EMIT_MSG_EVENT
,
1453 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE
,
1454 notit
->dscopes
.event_payload
);
1456 BT_COMP_LOGW("Cannot decode event payload field: "
1457 "notit-addr=%p, event-class-addr=%p, "
1458 "event-class-name=\"%s\", "
1459 "event-class-id=%" PRId64
", fc-addr=%p",
1460 notit
, notit
->meta
.ec
,
1461 notit
->meta
.ec
->name
->str
,
1471 enum bt_msg_iter_status
read_event_payload_continue_state(
1472 struct bt_msg_iter
*notit
)
1474 return read_dscope_continue_state(notit
, STATE_EMIT_MSG_EVENT
);
1478 enum bt_msg_iter_status
skip_packet_padding_state(struct bt_msg_iter
*notit
)
1480 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1481 size_t bits_to_skip
;
1482 const enum state next_state
= STATE_SWITCH_PACKET
;
1484 BT_ASSERT(notit
->cur_exp_packet_total_size
> 0);
1485 bits_to_skip
= notit
->cur_exp_packet_total_size
- packet_at(notit
);
1486 if (bits_to_skip
== 0) {
1487 notit
->state
= next_state
;
1490 size_t bits_to_consume
;
1492 BT_COMP_LOGD("Trying to skip %zu bits of padding: notit-addr=%p, size=%zu",
1493 bits_to_skip
, notit
, bits_to_skip
);
1494 status
= buf_ensure_available_bits(notit
);
1495 if (status
!= BT_MSG_ITER_STATUS_OK
) {
1499 bits_to_consume
= MIN(buf_available_bits(notit
), bits_to_skip
);
1500 BT_COMP_LOGD("Skipping %zu bits of padding: notit-addr=%p, size=%zu",
1501 bits_to_consume
, notit
, bits_to_consume
);
1502 buf_consume_bits(notit
, bits_to_consume
);
1503 bits_to_skip
= notit
->cur_exp_packet_total_size
-
1505 if (bits_to_skip
== 0) {
1506 notit
->state
= next_state
;
1516 enum bt_msg_iter_status
check_emit_msg_stream_beginning_state(
1517 struct bt_msg_iter
*notit
)
1519 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1521 if (notit
->set_stream
) {
1522 status
= set_current_stream(notit
);
1523 if (status
!= BT_MSG_ITER_STATUS_OK
) {
1528 if (notit
->emit_stream_begin_msg
) {
1529 notit
->state
= STATE_EMIT_MSG_STREAM_BEGINNING
;
1531 /* Stream's first packet */
1532 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
;
1540 enum bt_msg_iter_status
check_emit_msg_discarded_events(
1541 struct bt_msg_iter
*notit
)
1543 notit
->state
= STATE_EMIT_MSG_DISCARDED_EVENTS
;
1545 if (!notit
->meta
.sc
->has_discarded_events
) {
1546 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
;
1550 if (notit
->prev_packet_snapshots
.discarded_events
== UINT64_C(-1)) {
1551 if (notit
->snapshots
.discarded_events
== 0 ||
1552 notit
->snapshots
.discarded_events
== UINT64_C(-1)) {
1554 * Stream's first packet with no discarded
1555 * events or no information about discarded
1556 * events: do not emit.
1558 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
;
1562 * If the previous packet has a value for this counter,
1563 * then this counter is defined for the whole stream.
1565 BT_ASSERT(notit
->snapshots
.discarded_events
!= UINT64_C(-1));
1567 if (notit
->snapshots
.discarded_events
-
1568 notit
->prev_packet_snapshots
.discarded_events
== 0) {
1570 * No discarded events since previous packet: do
1573 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
;
1578 return BT_MSG_ITER_STATUS_OK
;
1582 enum bt_msg_iter_status
check_emit_msg_discarded_packets(
1583 struct bt_msg_iter
*notit
)
1585 notit
->state
= STATE_EMIT_MSG_DISCARDED_PACKETS
;
1587 if (!notit
->meta
.sc
->has_discarded_packets
) {
1588 notit
->state
= STATE_EMIT_MSG_PACKET_BEGINNING
;
1592 if (notit
->prev_packet_snapshots
.packets
== UINT64_C(-1)) {
1594 * Stream's first packet or no information about
1595 * discarded packets: do not emit. In other words, if
1596 * this is the first packet and its sequence number is
1597 * not 0, do not consider that packets were previously
1598 * lost: we might be reading a partial stream (LTTng
1599 * snapshot for example).
1601 notit
->state
= STATE_EMIT_MSG_PACKET_BEGINNING
;
1604 * If the previous packet has a value for this counter,
1605 * then this counter is defined for the whole stream.
1607 BT_ASSERT(notit
->snapshots
.packets
!= UINT64_C(-1));
1609 if (notit
->snapshots
.packets
-
1610 notit
->prev_packet_snapshots
.packets
<= 1) {
1612 * No discarded packets since previous packet:
1615 notit
->state
= STATE_EMIT_MSG_PACKET_BEGINNING
;
1620 return BT_MSG_ITER_STATUS_OK
;
1624 enum bt_msg_iter_status
check_emit_msg_stream_end(
1625 struct bt_msg_iter
*notit
)
1627 if (notit
->emit_stream_end_msg
) {
1628 notit
->state
= STATE_EMIT_MSG_STREAM_END
;
1630 notit
->state
= STATE_DONE
;
1633 return BT_MSG_ITER_STATUS_OK
;
1637 enum bt_msg_iter_status
handle_state(struct bt_msg_iter
*notit
)
1639 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
1640 const enum state state
= notit
->state
;
1642 BT_COMP_LOGT("Handling state: notit-addr=%p, state=%s",
1643 notit
, state_string(state
));
1645 // TODO: optimalize!
1648 notit
->state
= STATE_SWITCH_PACKET
;
1650 case STATE_SWITCH_PACKET
:
1651 status
= switch_packet_state(notit
);
1653 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN
:
1654 status
= read_packet_header_begin_state(notit
);
1656 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE
:
1657 status
= read_packet_header_continue_state(notit
);
1659 case STATE_AFTER_TRACE_PACKET_HEADER
:
1660 status
= after_packet_header_state(notit
);
1662 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN
:
1663 status
= read_packet_context_begin_state(notit
);
1665 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE
:
1666 status
= read_packet_context_continue_state(notit
);
1668 case STATE_AFTER_STREAM_PACKET_CONTEXT
:
1669 status
= after_packet_context_state(notit
);
1671 case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING
:
1672 status
= check_emit_msg_stream_beginning_state(notit
);
1674 case STATE_EMIT_MSG_STREAM_BEGINNING
:
1675 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
;
1677 case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
:
1678 status
= check_emit_msg_discarded_events(notit
);
1680 case STATE_EMIT_MSG_DISCARDED_EVENTS
:
1681 notit
->state
= STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
;
1683 case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
:
1684 status
= check_emit_msg_discarded_packets(notit
);
1686 case STATE_EMIT_MSG_DISCARDED_PACKETS
:
1687 notit
->state
= STATE_EMIT_MSG_PACKET_BEGINNING
;
1689 case STATE_EMIT_MSG_PACKET_BEGINNING
:
1690 notit
->state
= STATE_DSCOPE_EVENT_HEADER_BEGIN
;
1692 case STATE_DSCOPE_EVENT_HEADER_BEGIN
:
1693 status
= read_event_header_begin_state(notit
);
1695 case STATE_DSCOPE_EVENT_HEADER_CONTINUE
:
1696 status
= read_event_header_continue_state(notit
);
1698 case STATE_AFTER_EVENT_HEADER
:
1699 status
= after_event_header_state(notit
);
1701 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN
:
1702 status
= read_event_common_context_begin_state(notit
);
1704 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE
:
1705 status
= read_event_common_context_continue_state(notit
);
1707 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN
:
1708 status
= read_event_spec_context_begin_state(notit
);
1710 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE
:
1711 status
= read_event_spec_context_continue_state(notit
);
1713 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN
:
1714 status
= read_event_payload_begin_state(notit
);
1716 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE
:
1717 status
= read_event_payload_continue_state(notit
);
1719 case STATE_EMIT_MSG_EVENT
:
1720 notit
->state
= STATE_DSCOPE_EVENT_HEADER_BEGIN
;
1722 case STATE_SKIP_PACKET_PADDING
:
1723 status
= skip_packet_padding_state(notit
);
1725 case STATE_EMIT_MSG_PACKET_END_MULTI
:
1726 notit
->state
= STATE_SKIP_PACKET_PADDING
;
1728 case STATE_EMIT_MSG_PACKET_END_SINGLE
:
1729 notit
->state
= STATE_CHECK_EMIT_MSG_STREAM_END
;
1731 case STATE_CHECK_EMIT_MSG_STREAM_END
:
1732 status
= check_emit_msg_stream_end(notit
);
1734 case STATE_EMIT_MSG_STREAM_END
:
1735 notit
->state
= STATE_DONE
;
1740 BT_COMP_LOGF("Unknown CTF plugin message iterator state: "
1741 "notit-addr=%p, state=%d", notit
, notit
->state
);
1745 BT_COMP_LOGT("Handled state: notit-addr=%p, status=%s, "
1746 "prev-state=%s, cur-state=%s",
1747 notit
, bt_msg_iter_status_string(status
),
1748 state_string(state
), state_string(notit
->state
));
1753 void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter
*notit
)
1756 BT_COMP_LOGD("Resetting message iterator: addr=%p", notit
);
1757 stack_clear(notit
->stack
);
1758 notit
->meta
.sc
= NULL
;
1759 notit
->meta
.ec
= NULL
;
1760 BT_PACKET_PUT_REF_AND_RESET(notit
->packet
);
1761 BT_STREAM_PUT_REF_AND_RESET(notit
->stream
);
1762 BT_MESSAGE_PUT_REF_AND_RESET(notit
->event_msg
);
1763 release_all_dscopes(notit
);
1764 notit
->cur_dscope_field
= NULL
;
1766 if (notit
->packet_context_field
) {
1767 bt_packet_context_field_release(notit
->packet_context_field
);
1768 notit
->packet_context_field
= NULL
;
1771 notit
->buf
.addr
= NULL
;
1774 notit
->buf
.last_eh_at
= SIZE_MAX
;
1775 notit
->buf
.packet_offset
= 0;
1776 notit
->state
= STATE_INIT
;
1777 notit
->cur_exp_packet_content_size
= -1;
1778 notit
->cur_exp_packet_total_size
= -1;
1779 notit
->cur_packet_offset
= -1;
1780 notit
->cur_event_class_id
= -1;
1781 notit
->snapshots
.beginning_clock
= UINT64_C(-1);
1782 notit
->snapshots
.end_clock
= UINT64_C(-1);
1786 * Resets the internal state of a CTF message iterator.
1789 void bt_msg_iter_reset(struct bt_msg_iter
*notit
)
1791 bt_msg_iter_reset_for_next_stream_file(notit
);
1792 notit
->cur_stream_class_id
= -1;
1793 notit
->cur_data_stream_id
= -1;
1794 notit
->snapshots
.discarded_events
= UINT64_C(-1);
1795 notit
->snapshots
.packets
= UINT64_C(-1);
1796 notit
->prev_packet_snapshots
.discarded_events
= UINT64_C(-1);
1797 notit
->prev_packet_snapshots
.packets
= UINT64_C(-1);
1798 notit
->prev_packet_snapshots
.beginning_clock
= UINT64_C(-1);
1799 notit
->prev_packet_snapshots
.end_clock
= UINT64_C(-1);
1803 bt_field
*borrow_next_field(struct bt_msg_iter
*notit
)
1805 bt_field
*next_field
= NULL
;
1806 bt_field
*base_field
;
1807 const bt_field_class
*base_fc
;
1810 BT_ASSERT(!stack_empty(notit
->stack
));
1811 index
= stack_top(notit
->stack
)->index
;
1812 base_field
= stack_top(notit
->stack
)->base
;
1813 BT_ASSERT(base_field
);
1814 base_fc
= bt_field_borrow_class_const(base_field
);
1817 switch (bt_field_class_get_type(base_fc
)) {
1818 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1821 bt_field_class_structure_get_member_count(
1822 bt_field_borrow_class_const(
1825 bt_field_structure_borrow_member_field_by_index(
1829 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1830 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1831 BT_ASSERT(index
< bt_field_array_get_length(base_field
));
1832 next_field
= bt_field_array_borrow_element_field_by_index(
1835 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
1836 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
1837 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
1838 BT_ASSERT(index
== 0);
1839 next_field
= bt_field_variant_borrow_selected_option_field(
1846 BT_ASSERT(next_field
);
1851 void update_default_clock(struct bt_msg_iter
*notit
, uint64_t new_val
,
1852 uint64_t new_val_size
)
1854 uint64_t new_val_mask
;
1855 uint64_t cur_value_masked
;
1857 BT_ASSERT(new_val_size
> 0);
1860 * Special case for a 64-bit new value, which is the limit
1861 * of a clock value as of this version: overwrite the
1862 * current value directly.
1864 if (new_val_size
== 64) {
1865 notit
->default_clock_snapshot
= new_val
;
1869 new_val_mask
= (1ULL << new_val_size
) - 1;
1870 cur_value_masked
= notit
->default_clock_snapshot
& new_val_mask
;
1872 if (new_val
< cur_value_masked
) {
1874 * It looks like a wrap happened on the number of bits
1875 * of the requested new value. Assume that the clock
1876 * value wrapped only one time.
1878 notit
->default_clock_snapshot
+= new_val_mask
+ 1;
1881 /* Clear the low bits of the current clock value. */
1882 notit
->default_clock_snapshot
&= ~new_val_mask
;
1884 /* Set the low bits of the current clock value. */
1885 notit
->default_clock_snapshot
|= new_val
;
1888 BT_COMP_LOGT("Updated default clock's value from integer field's value: "
1889 "value=%" PRIu64
, notit
->default_clock_snapshot
);
1893 enum bt_bfcr_status
bfcr_unsigned_int_cb(uint64_t value
,
1894 struct ctf_field_class
*fc
, void *data
)
1896 struct bt_msg_iter
*notit
= data
;
1897 enum bt_bfcr_status status
= BT_BFCR_STATUS_OK
;
1898 bt_field
*field
= NULL
;
1899 struct ctf_field_class_int
*int_fc
= (void *) fc
;
1901 BT_COMP_LOGT("Unsigned integer function called from BFCR: "
1902 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
1903 "fc-type=%d, fc-in-ir=%d, value=%" PRIu64
,
1904 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
, value
);
1906 if (G_LIKELY(int_fc
->meaning
== CTF_FIELD_CLASS_MEANING_NONE
)) {
1907 goto update_def_clock
;
1910 switch (int_fc
->meaning
) {
1911 case CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
:
1912 notit
->cur_event_class_id
= value
;
1914 case CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
:
1915 notit
->cur_data_stream_id
= value
;
1917 case CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
:
1918 notit
->snapshots
.beginning_clock
= value
;
1920 case CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
:
1921 notit
->snapshots
.end_clock
= value
;
1923 case CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
:
1924 notit
->cur_stream_class_id
= value
;
1926 case CTF_FIELD_CLASS_MEANING_MAGIC
:
1927 if (value
!= 0xc1fc1fc1) {
1928 BT_COMP_LOGW("Invalid CTF magic number: notit-addr=%p, "
1929 "magic=%" PRIx64
, notit
, value
);
1930 status
= BT_BFCR_STATUS_ERROR
;
1935 case CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
:
1936 notit
->snapshots
.packets
= value
;
1938 case CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
:
1939 notit
->snapshots
.discarded_events
= value
;
1941 case CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
:
1942 notit
->cur_exp_packet_total_size
= value
;
1944 case CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
:
1945 notit
->cur_exp_packet_content_size
= value
;
1952 if (G_UNLIKELY(int_fc
->mapped_clock_class
)) {
1953 update_default_clock(notit
, value
, int_fc
->base
.size
);
1956 if (G_UNLIKELY(int_fc
->storing_index
>= 0)) {
1957 g_array_index(notit
->stored_values
, uint64_t,
1958 (uint64_t) int_fc
->storing_index
) = value
;
1961 if (G_UNLIKELY(!fc
->in_ir
)) {
1965 field
= borrow_next_field(notit
);
1967 BT_ASSERT(bt_field_borrow_class_const(field
) == fc
->ir_fc
);
1968 BT_ASSERT(bt_field_get_class_type(field
) ==
1969 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
1970 bt_field_get_class_type(field
) ==
1971 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
1972 bt_field_integer_unsigned_set_value(field
, value
);
1973 stack_top(notit
->stack
)->index
++;
1980 enum bt_bfcr_status
bfcr_unsigned_int_char_cb(uint64_t value
,
1981 struct ctf_field_class
*fc
, void *data
)
1984 struct bt_msg_iter
*notit
= data
;
1985 enum bt_bfcr_status status
= BT_BFCR_STATUS_OK
;
1986 bt_field
*string_field
= NULL
;
1987 struct ctf_field_class_int
*int_fc
= (void *) fc
;
1988 char str
[2] = {'\0', '\0'};
1990 BT_COMP_LOGT("Unsigned integer character function called from BFCR: "
1991 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
1992 "fc-type=%d, fc-in-ir=%d, value=%" PRIu64
,
1993 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
, value
);
1994 BT_ASSERT(int_fc
->meaning
== CTF_FIELD_CLASS_MEANING_NONE
);
1995 BT_ASSERT(!int_fc
->mapped_clock_class
);
1996 BT_ASSERT(int_fc
->storing_index
< 0);
1998 if (G_UNLIKELY(!fc
->in_ir
)) {
2002 if (notit
->done_filling_string
) {
2007 notit
->done_filling_string
= true;
2011 string_field
= stack_top(notit
->stack
)->base
;
2012 BT_ASSERT(bt_field_get_class_type(string_field
) ==
2013 BT_FIELD_CLASS_TYPE_STRING
);
2015 /* Append character */
2016 str
[0] = (char) value
;
2017 ret
= bt_field_string_append_with_length(string_field
, str
, 1);
2019 BT_COMP_LOGE("Cannot append character to string field's value: "
2020 "notit-addr=%p, field-addr=%p, ret=%d",
2021 notit
, string_field
, ret
);
2022 status
= BT_BFCR_STATUS_ERROR
;
2031 enum bt_bfcr_status
bfcr_signed_int_cb(int64_t value
,
2032 struct ctf_field_class
*fc
, void *data
)
2034 enum bt_bfcr_status status
= BT_BFCR_STATUS_OK
;
2035 bt_field
*field
= NULL
;
2036 struct bt_msg_iter
*notit
= data
;
2037 struct ctf_field_class_int
*int_fc
= (void *) fc
;
2039 BT_COMP_LOGT("Signed integer function called from BFCR: "
2040 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2041 "fc-type=%d, fc-in-ir=%d, value=%" PRId64
,
2042 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
, value
);
2043 BT_ASSERT(int_fc
->meaning
== CTF_FIELD_CLASS_MEANING_NONE
);
2045 if (G_UNLIKELY(int_fc
->storing_index
>= 0)) {
2046 g_array_index(notit
->stored_values
, uint64_t,
2047 (uint64_t) int_fc
->storing_index
) = (uint64_t) value
;
2050 if (G_UNLIKELY(!fc
->in_ir
)) {
2054 field
= borrow_next_field(notit
);
2056 BT_ASSERT(bt_field_borrow_class_const(field
) == fc
->ir_fc
);
2057 BT_ASSERT(bt_field_get_class_type(field
) ==
2058 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
2059 bt_field_get_class_type(field
) ==
2060 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
2061 bt_field_integer_signed_set_value(field
, value
);
2062 stack_top(notit
->stack
)->index
++;
2069 enum bt_bfcr_status
bfcr_floating_point_cb(double value
,
2070 struct ctf_field_class
*fc
, void *data
)
2072 enum bt_bfcr_status status
= BT_BFCR_STATUS_OK
;
2073 bt_field
*field
= NULL
;
2074 struct bt_msg_iter
*notit
= data
;
2076 BT_COMP_LOGT("Floating point number function called from BFCR: "
2077 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2078 "fc-type=%d, fc-in-ir=%d, value=%f",
2079 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
, value
);
2081 if (G_UNLIKELY(!fc
->in_ir
)) {
2085 field
= borrow_next_field(notit
);
2087 BT_ASSERT(bt_field_borrow_class_const(field
) == fc
->ir_fc
);
2088 BT_ASSERT(bt_field_get_class_type(field
) ==
2089 BT_FIELD_CLASS_TYPE_REAL
);
2090 bt_field_real_set_value(field
, value
);
2091 stack_top(notit
->stack
)->index
++;
2098 enum bt_bfcr_status
bfcr_string_begin_cb(
2099 struct ctf_field_class
*fc
, void *data
)
2101 bt_field
*field
= NULL
;
2102 struct bt_msg_iter
*notit
= data
;
2104 BT_COMP_LOGT("String (beginning) function called from BFCR: "
2105 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2106 "fc-type=%d, fc-in-ir=%d",
2107 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
);
2109 if (G_UNLIKELY(!fc
->in_ir
)) {
2113 field
= borrow_next_field(notit
);
2115 BT_ASSERT(bt_field_borrow_class_const(field
) == fc
->ir_fc
);
2116 BT_ASSERT(bt_field_get_class_type(field
) ==
2117 BT_FIELD_CLASS_TYPE_STRING
);
2118 bt_field_string_clear(field
);
2121 * Push on stack. Not a compound class per se, but we know that
2122 * only bfcr_string_cb() may be called between this call and a
2123 * subsequent call to bfcr_string_end_cb().
2125 stack_push(notit
->stack
, field
);
2128 return BT_BFCR_STATUS_OK
;
2132 enum bt_bfcr_status
bfcr_string_cb(const char *value
,
2133 size_t len
, struct ctf_field_class
*fc
, void *data
)
2135 enum bt_bfcr_status status
= BT_BFCR_STATUS_OK
;
2136 bt_field
*field
= NULL
;
2137 struct bt_msg_iter
*notit
= data
;
2140 BT_COMP_LOGT("String (substring) function called from BFCR: "
2141 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2142 "fc-type=%d, fc-in-ir=%d, string-length=%zu",
2143 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
,
2146 if (G_UNLIKELY(!fc
->in_ir
)) {
2150 field
= stack_top(notit
->stack
)->base
;
2153 /* Append current substring */
2154 ret
= bt_field_string_append_with_length(field
, value
, len
);
2156 BT_COMP_LOGE("Cannot append substring to string field's value: "
2157 "notit-addr=%p, field-addr=%p, string-length=%zu, "
2158 "ret=%d", notit
, field
, len
, ret
);
2159 status
= BT_BFCR_STATUS_ERROR
;
2168 enum bt_bfcr_status
bfcr_string_end_cb(
2169 struct ctf_field_class
*fc
, void *data
)
2171 struct bt_msg_iter
*notit
= data
;
2173 BT_COMP_LOGT("String (end) function called from BFCR: "
2174 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2175 "fc-type=%d, fc-in-ir=%d",
2176 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
);
2178 if (G_UNLIKELY(!fc
->in_ir
)) {
2182 /* Pop string field */
2183 stack_pop(notit
->stack
);
2185 /* Go to next field */
2186 stack_top(notit
->stack
)->index
++;
2189 return BT_BFCR_STATUS_OK
;
2192 enum bt_bfcr_status
bfcr_compound_begin_cb(
2193 struct ctf_field_class
*fc
, void *data
)
2195 struct bt_msg_iter
*notit
= data
;
2198 BT_COMP_LOGT("Compound (beginning) function called from BFCR: "
2199 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2200 "fc-type=%d, fc-in-ir=%d",
2201 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
);
2208 if (stack_empty(notit
->stack
)) {
2209 /* Root: already set by read_dscope_begin_state() */
2210 field
= notit
->cur_dscope_field
;
2212 field
= borrow_next_field(notit
);
2218 BT_ASSERT(bt_field_borrow_class_const(field
) == fc
->ir_fc
);
2219 stack_push(notit
->stack
, field
);
2222 * Change BFCR "unsigned int" callback if it's a text
2225 if (fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
||
2226 fc
->type
== CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
2227 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
2229 if (array_fc
->is_text
) {
2230 BT_ASSERT(bt_field_get_class_type(field
) ==
2231 BT_FIELD_CLASS_TYPE_STRING
);
2232 notit
->done_filling_string
= false;
2233 bt_field_string_clear(field
);
2234 bt_bfcr_set_unsigned_int_cb(notit
->bfcr
,
2235 bfcr_unsigned_int_char_cb
);
2240 return BT_BFCR_STATUS_OK
;
2243 enum bt_bfcr_status
bfcr_compound_end_cb(
2244 struct ctf_field_class
*fc
, void *data
)
2246 struct bt_msg_iter
*notit
= data
;
2248 BT_COMP_LOGT("Compound (end) function called from BFCR: "
2249 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
2250 "fc-type=%d, fc-in-ir=%d",
2251 notit
, notit
->bfcr
, fc
, fc
->type
, fc
->in_ir
);
2257 BT_ASSERT(!stack_empty(notit
->stack
));
2258 BT_ASSERT(bt_field_borrow_class_const(stack_top(notit
->stack
)->base
) ==
2262 * Reset BFCR "unsigned int" callback if it's a text
2265 if (fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
||
2266 fc
->type
== CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
2267 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
2269 if (array_fc
->is_text
) {
2270 BT_ASSERT(bt_field_get_class_type(
2271 stack_top(notit
->stack
)->base
) ==
2272 BT_FIELD_CLASS_TYPE_STRING
);
2273 bt_bfcr_set_unsigned_int_cb(notit
->bfcr
,
2274 bfcr_unsigned_int_cb
);
2279 stack_pop(notit
->stack
);
2281 /* If the stack is not empty, increment the base's index */
2282 if (!stack_empty(notit
->stack
)) {
2283 stack_top(notit
->stack
)->index
++;
2287 return BT_BFCR_STATUS_OK
;
2291 int64_t bfcr_get_sequence_length_cb(struct ctf_field_class
*fc
, void *data
)
2293 bt_field
*seq_field
;
2294 struct bt_msg_iter
*notit
= data
;
2295 struct ctf_field_class_sequence
*seq_fc
= (void *) fc
;
2296 int64_t length
= -1;
2299 length
= (uint64_t) g_array_index(notit
->stored_values
, uint64_t,
2300 seq_fc
->stored_length_index
);
2301 seq_field
= stack_top(notit
->stack
)->base
;
2302 BT_ASSERT(seq_field
);
2305 * bfcr_get_sequence_length_cb() also gets called back for a
2306 * text sequence, but the destination field is a string field.
2307 * Only set the field's sequence length if the destination field
2308 * is a sequence field.
2310 if (!seq_fc
->base
.is_text
) {
2311 BT_ASSERT(bt_field_get_class_type(seq_field
) ==
2312 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
2313 ret
= bt_field_array_dynamic_set_length(seq_field
,
2316 BT_COMP_LOGE("Cannot set dynamic array field's length field: "
2317 "notit-addr=%p, field-addr=%p, "
2318 "length=%" PRIu64
, notit
, seq_field
, length
);
2326 struct ctf_field_class
*bfcr_borrow_variant_selected_field_class_cb(
2327 struct ctf_field_class
*fc
, void *data
)
2331 int64_t option_index
= -1;
2332 struct bt_msg_iter
*notit
= data
;
2333 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
2334 struct ctf_named_field_class
*selected_option
= NULL
;
2335 struct ctf_field_class
*ret_fc
= NULL
;
2341 /* Get variant's tag */
2342 tag
.u
= g_array_index(notit
->stored_values
, uint64_t,
2343 var_fc
->stored_tag_index
);
2346 * Check each range to find the selected option's index.
2348 if (var_fc
->tag_fc
->base
.is_signed
) {
2349 for (i
= 0; i
< var_fc
->ranges
->len
; i
++) {
2350 struct ctf_field_class_variant_range
*range
=
2351 ctf_field_class_variant_borrow_range_by_index(
2354 if (tag
.i
>= range
->range
.lower
.i
&&
2355 tag
.i
<= range
->range
.upper
.i
) {
2356 option_index
= (int64_t) range
->option_index
;
2361 for (i
= 0; i
< var_fc
->ranges
->len
; i
++) {
2362 struct ctf_field_class_variant_range
*range
=
2363 ctf_field_class_variant_borrow_range_by_index(
2366 if (tag
.u
>= range
->range
.lower
.u
&&
2367 tag
.u
<= range
->range
.upper
.u
) {
2368 option_index
= (int64_t) range
->option_index
;
2374 if (option_index
< 0) {
2375 BT_COMP_LOGW("Cannot find variant field class's option: "
2376 "notit-addr=%p, var-fc-addr=%p, u-tag=%" PRIu64
", "
2377 "i-tag=%" PRId64
, notit
, var_fc
, tag
.u
, tag
.i
);
2381 selected_option
= ctf_field_class_variant_borrow_option_by_index(
2382 var_fc
, (uint64_t) option_index
);
2384 if (selected_option
->fc
->in_ir
) {
2385 bt_field
*var_field
= stack_top(notit
->stack
)->base
;
2387 ret
= bt_field_variant_select_option_field_by_index(
2388 var_field
, option_index
);
2390 BT_COMP_LOGW("Cannot select variant field's option field: "
2391 "notit-addr=%p, var-field-addr=%p, "
2392 "opt-index=%" PRId64
, notit
, var_field
,
2398 ret_fc
= selected_option
->fc
;
2405 void create_msg_stream_beginning(struct bt_msg_iter
*notit
,
2406 bt_message
**message
)
2408 bt_message
*ret
= NULL
;
2410 BT_ASSERT(notit
->stream
);
2411 BT_ASSERT(notit
->msg_iter
);
2412 ret
= bt_message_stream_beginning_create(notit
->msg_iter
,
2415 BT_COMP_LOGE("Cannot create stream beginning message: "
2416 "notit-addr=%p, stream-addr=%p",
2417 notit
, notit
->stream
);
2425 void create_msg_stream_end(struct bt_msg_iter
*notit
, bt_message
**message
)
2429 if (!notit
->stream
) {
2430 BT_COMP_LOGE("Cannot create stream for stream message: "
2431 "notit-addr=%p", notit
);
2435 BT_ASSERT(notit
->msg_iter
);
2436 ret
= bt_message_stream_end_create(notit
->msg_iter
,
2439 BT_COMP_LOGE("Cannot create stream end message: "
2440 "notit-addr=%p, stream-addr=%p",
2441 notit
, notit
->stream
);
2449 void create_msg_packet_beginning(struct bt_msg_iter
*notit
,
2450 bt_message
**message
)
2453 enum bt_msg_iter_status status
;
2454 bt_message
*msg
= NULL
;
2455 const bt_stream_class
*sc
;
2457 status
= set_current_packet(notit
);
2458 if (status
!= BT_MSG_ITER_STATUS_OK
) {
2462 BT_ASSERT(notit
->packet
);
2463 sc
= notit
->meta
.sc
->ir_sc
;
2466 if (notit
->packet_context_field
) {
2467 ret
= bt_packet_move_context_field(
2468 notit
->packet
, notit
->packet_context_field
);
2473 notit
->packet_context_field
= NULL
;
2476 * At this point notit->dscopes.stream_packet_context
2477 * has the same value as the packet context field within
2480 BT_ASSERT(bt_packet_borrow_context_field(
2482 notit
->dscopes
.stream_packet_context
);
2485 BT_ASSERT(notit
->msg_iter
);
2487 if (notit
->meta
.sc
->packets_have_ts_begin
) {
2488 BT_ASSERT(notit
->snapshots
.beginning_clock
!= UINT64_C(-1));
2489 msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
2490 notit
->msg_iter
, notit
->packet
,
2491 notit
->snapshots
.beginning_clock
);
2493 msg
= bt_message_packet_beginning_create(notit
->msg_iter
,
2498 BT_COMP_LOGE("Cannot create packet beginning message: "
2499 "notit-addr=%p, packet-addr=%p",
2500 notit
, notit
->packet
);
2511 void create_msg_packet_end(struct bt_msg_iter
*notit
, bt_message
**message
)
2515 if (!notit
->packet
) {
2519 /* Update default clock from packet's end time */
2520 if (notit
->snapshots
.end_clock
!= UINT64_C(-1)) {
2521 notit
->default_clock_snapshot
= notit
->snapshots
.end_clock
;
2524 BT_ASSERT(notit
->msg_iter
);
2526 if (notit
->meta
.sc
->packets_have_ts_end
) {
2527 BT_ASSERT(notit
->snapshots
.end_clock
!= UINT64_C(-1));
2528 msg
= bt_message_packet_end_create_with_default_clock_snapshot(
2529 notit
->msg_iter
, notit
->packet
,
2530 notit
->snapshots
.end_clock
);
2532 msg
= bt_message_packet_end_create(notit
->msg_iter
,
2537 BT_COMP_LOGE("Cannot create packet end message: "
2538 "notit-addr=%p, packet-addr=%p",
2539 notit
, notit
->packet
);
2544 BT_PACKET_PUT_REF_AND_RESET(notit
->packet
);
2549 void create_msg_discarded_events(struct bt_msg_iter
*notit
,
2550 bt_message
**message
)
2553 uint64_t beginning_raw_value
= UINT64_C(-1);
2554 uint64_t end_raw_value
= UINT64_C(-1);
2556 BT_ASSERT(notit
->msg_iter
);
2557 BT_ASSERT(notit
->stream
);
2558 BT_ASSERT(notit
->meta
.sc
->has_discarded_events
);
2560 if (notit
->meta
.sc
->discarded_events_have_default_cs
) {
2561 if (notit
->prev_packet_snapshots
.discarded_events
== UINT64_C(-1)) {
2563 * We discarded events, but before (and possibly
2564 * including) the current packet: use this packet's time
2565 * range, and do not have a specific count.
2567 beginning_raw_value
= notit
->snapshots
.beginning_clock
;
2568 end_raw_value
= notit
->snapshots
.end_clock
;
2570 beginning_raw_value
= notit
->prev_packet_snapshots
.end_clock
;
2571 end_raw_value
= notit
->snapshots
.end_clock
;
2574 BT_ASSERT(beginning_raw_value
!= UINT64_C(-1));
2575 BT_ASSERT(end_raw_value
!= UINT64_C(-1));
2576 msg
= bt_message_discarded_events_create_with_default_clock_snapshots(
2577 notit
->msg_iter
, notit
->stream
, beginning_raw_value
,
2580 msg
= bt_message_discarded_events_create(notit
->msg_iter
,
2585 BT_COMP_LOGE("Cannot create discarded events message: "
2586 "notit-addr=%p, stream-addr=%p",
2587 notit
, notit
->stream
);
2591 if (notit
->prev_packet_snapshots
.discarded_events
!= UINT64_C(-1)) {
2592 bt_message_discarded_events_set_count(msg
,
2593 notit
->snapshots
.discarded_events
-
2594 notit
->prev_packet_snapshots
.discarded_events
);
2601 void create_msg_discarded_packets(struct bt_msg_iter
*notit
,
2602 bt_message
**message
)
2606 BT_ASSERT(notit
->msg_iter
);
2607 BT_ASSERT(notit
->stream
);
2608 BT_ASSERT(notit
->meta
.sc
->has_discarded_packets
);
2609 BT_ASSERT(notit
->prev_packet_snapshots
.packets
!=
2612 if (notit
->meta
.sc
->discarded_packets_have_default_cs
) {
2613 BT_ASSERT(notit
->prev_packet_snapshots
.end_clock
!= UINT64_C(-1));
2614 BT_ASSERT(notit
->snapshots
.beginning_clock
!= UINT64_C(-1));
2615 msg
= bt_message_discarded_packets_create_with_default_clock_snapshots(
2616 notit
->msg_iter
, notit
->stream
,
2617 notit
->prev_packet_snapshots
.end_clock
,
2618 notit
->snapshots
.beginning_clock
);
2620 msg
= bt_message_discarded_packets_create(notit
->msg_iter
,
2625 BT_COMP_LOGE("Cannot create discarded packets message: "
2626 "notit-addr=%p, stream-addr=%p",
2627 notit
, notit
->stream
);
2631 bt_message_discarded_packets_set_count(msg
,
2632 notit
->snapshots
.packets
-
2633 notit
->prev_packet_snapshots
.packets
- 1);
2638 struct bt_msg_iter
*bt_msg_iter_create(struct ctf_trace_class
*tc
,
2639 size_t max_request_sz
,
2640 struct bt_msg_iter_medium_ops medops
, void *data
,
2641 bt_logging_level log_level
, bt_self_component
*self_comp
)
2643 struct bt_msg_iter
*notit
= NULL
;
2644 struct bt_bfcr_cbs cbs
= {
2646 .signed_int
= bfcr_signed_int_cb
,
2647 .unsigned_int
= bfcr_unsigned_int_cb
,
2648 .floating_point
= bfcr_floating_point_cb
,
2649 .string_begin
= bfcr_string_begin_cb
,
2650 .string
= bfcr_string_cb
,
2651 .string_end
= bfcr_string_end_cb
,
2652 .compound_begin
= bfcr_compound_begin_cb
,
2653 .compound_end
= bfcr_compound_end_cb
,
2656 .get_sequence_length
= bfcr_get_sequence_length_cb
,
2657 .borrow_variant_selected_field_class
= bfcr_borrow_variant_selected_field_class_cb
,
2662 BT_ASSERT(medops
.request_bytes
);
2663 BT_ASSERT(medops
.borrow_stream
);
2664 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, log_level
, self_comp
,
2665 "Creating CTF plugin message iterator: "
2666 "trace-addr=%p, max-request-size=%zu, "
2667 "data=%p, log-level=%s", tc
, max_request_sz
, data
,
2668 bt_common_logging_level_string(log_level
));
2669 notit
= g_new0(struct bt_msg_iter
, 1);
2671 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
2672 "Failed to allocate one CTF plugin message iterator.");
2675 notit
->self_comp
= self_comp
;
2676 notit
->log_level
= log_level
;
2677 notit
->meta
.tc
= tc
;
2678 notit
->medium
.medops
= medops
;
2679 notit
->medium
.max_request_sz
= max_request_sz
;
2680 notit
->medium
.data
= data
;
2681 notit
->stack
= stack_new(notit
);
2682 notit
->stored_values
= g_array_new(FALSE
, TRUE
, sizeof(uint64_t));
2683 g_array_set_size(notit
->stored_values
, tc
->stored_value_count
);
2685 if (!notit
->stack
) {
2686 BT_COMP_LOGE_STR("Failed to create field stack.");
2690 notit
->bfcr
= bt_bfcr_create(cbs
, notit
, log_level
, NULL
);
2692 BT_COMP_LOGE_STR("Failed to create binary class reader (BFCR).");
2696 bt_msg_iter_reset(notit
);
2697 BT_COMP_LOGD("Created CTF plugin message iterator: "
2698 "trace-addr=%p, max-request-size=%zu, "
2699 "data=%p, notit-addr=%p, log-level=%s",
2700 tc
, max_request_sz
, data
, notit
,
2701 bt_common_logging_level_string(log_level
));
2702 notit
->cur_packet_offset
= 0;
2708 bt_msg_iter_destroy(notit
);
2713 void bt_msg_iter_destroy(struct bt_msg_iter
*notit
)
2715 BT_PACKET_PUT_REF_AND_RESET(notit
->packet
);
2716 BT_STREAM_PUT_REF_AND_RESET(notit
->stream
);
2717 release_all_dscopes(notit
);
2719 BT_COMP_LOGD("Destroying CTF plugin message iterator: addr=%p", notit
);
2722 BT_COMP_LOGD_STR("Destroying field stack.");
2723 stack_destroy(notit
->stack
);
2727 BT_COMP_LOGD("Destroying BFCR: bfcr-addr=%p", notit
->bfcr
);
2728 bt_bfcr_destroy(notit
->bfcr
);
2731 if (notit
->stored_values
) {
2732 g_array_free(notit
->stored_values
, TRUE
);
2738 enum bt_msg_iter_status
bt_msg_iter_get_next_message(
2739 struct bt_msg_iter
*notit
,
2740 bt_self_message_iterator
*msg_iter
, bt_message
**message
)
2742 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
2746 notit
->msg_iter
= msg_iter
;
2747 notit
->set_stream
= true;
2748 BT_COMP_LOGD("Getting next message: notit-addr=%p", notit
);
2751 status
= handle_state(notit
);
2752 if (G_UNLIKELY(status
== BT_MSG_ITER_STATUS_AGAIN
)) {
2753 BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
2755 } else if (G_UNLIKELY(status
!= BT_MSG_ITER_STATUS_OK
)) {
2756 BT_COMP_LOGW("Cannot handle state: notit-addr=%p, state=%s",
2757 notit
, state_string(notit
->state
));
2761 switch (notit
->state
) {
2762 case STATE_EMIT_MSG_EVENT
:
2763 BT_ASSERT(notit
->event_msg
);
2764 *message
= notit
->event_msg
;
2765 notit
->event_msg
= NULL
;
2767 case STATE_EMIT_MSG_DISCARDED_EVENTS
:
2768 /* create_msg_discared_events() logs errors */
2769 create_msg_discarded_events(notit
, message
);
2772 status
= BT_MSG_ITER_STATUS_ERROR
;
2776 case STATE_EMIT_MSG_DISCARDED_PACKETS
:
2777 /* create_msg_discared_packets() logs errors */
2778 create_msg_discarded_packets(notit
, message
);
2781 status
= BT_MSG_ITER_STATUS_ERROR
;
2785 case STATE_EMIT_MSG_PACKET_BEGINNING
:
2786 /* create_msg_packet_beginning() logs errors */
2787 create_msg_packet_beginning(notit
, message
);
2790 status
= BT_MSG_ITER_STATUS_ERROR
;
2794 case STATE_EMIT_MSG_PACKET_END_SINGLE
:
2795 case STATE_EMIT_MSG_PACKET_END_MULTI
:
2796 /* create_msg_packet_end() logs errors */
2797 create_msg_packet_end(notit
, message
);
2800 status
= BT_MSG_ITER_STATUS_ERROR
;
2804 case STATE_EMIT_MSG_STREAM_BEGINNING
:
2805 /* create_msg_stream_beginning() logs errors */
2806 create_msg_stream_beginning(notit
, message
);
2809 status
= BT_MSG_ITER_STATUS_ERROR
;
2813 case STATE_EMIT_MSG_STREAM_END
:
2814 /* create_msg_stream_end() logs errors */
2815 create_msg_stream_end(notit
, message
);
2818 status
= BT_MSG_ITER_STATUS_ERROR
;
2823 status
= BT_MSG_ITER_STATUS_EOF
;
2826 /* Non-emitting state: continue */
2836 enum bt_msg_iter_status
read_packet_header_context_fields(
2837 struct bt_msg_iter
*notit
)
2840 enum bt_msg_iter_status status
= BT_MSG_ITER_STATUS_OK
;
2843 notit
->set_stream
= false;
2845 if (notit
->state
== STATE_EMIT_MSG_PACKET_BEGINNING
) {
2846 /* We're already there */
2851 status
= handle_state(notit
);
2852 if (G_UNLIKELY(status
== BT_MSG_ITER_STATUS_AGAIN
)) {
2853 BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
2855 } else if (G_UNLIKELY(status
!= BT_MSG_ITER_STATUS_OK
)) {
2856 BT_COMP_LOGW("Cannot handle state: notit-addr=%p, state=%s",
2857 notit
, state_string(notit
->state
));
2861 switch (notit
->state
) {
2862 case STATE_EMIT_MSG_PACKET_BEGINNING
:
2864 * Packet header and context fields are
2865 * potentially decoded (or they don't exist).
2869 case STATE_SWITCH_PACKET
:
2870 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN
:
2871 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE
:
2872 case STATE_AFTER_TRACE_PACKET_HEADER
:
2873 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN
:
2874 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE
:
2875 case STATE_AFTER_STREAM_PACKET_CONTEXT
:
2876 case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING
:
2877 case STATE_EMIT_MSG_STREAM_BEGINNING
:
2878 case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS
:
2879 case STATE_EMIT_MSG_DISCARDED_EVENTS
:
2880 case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS
:
2881 case STATE_EMIT_MSG_DISCARDED_PACKETS
:
2882 /* Non-emitting state: continue */
2886 * We should never get past the
2887 * STATE_EMIT_MSG_PACKET_BEGINNING state.
2889 BT_COMP_LOGF("Unexpected state: notit-addr=%p, state=%s",
2890 notit
, state_string(notit
->state
));
2896 ret
= set_current_packet_content_sizes(notit
);
2898 status
= BT_MSG_ITER_STATUS_ERROR
;
2905 void bt_msg_iter_set_medops_data(struct bt_msg_iter
*notit
,
2909 notit
->medium
.data
= medops_data
;
2913 enum bt_msg_iter_status
bt_msg_iter_seek(struct bt_msg_iter
*notit
,
2916 enum bt_msg_iter_status ret
= BT_MSG_ITER_STATUS_OK
;
2917 enum bt_msg_iter_medium_status medium_status
;
2921 BT_COMP_LOGE("Cannot seek to negative offset: offset=%jd", (intmax_t) offset
);
2922 ret
= BT_MSG_ITER_STATUS_INVAL
;
2926 if (!notit
->medium
.medops
.seek
) {
2927 ret
= BT_MSG_ITER_STATUS_UNSUPPORTED
;
2928 BT_COMP_LOGD("Aborting seek as the iterator's underlying media does not implement seek support.");
2932 medium_status
= notit
->medium
.medops
.seek(
2933 BT_MSG_ITER_SEEK_WHENCE_SET
, offset
, notit
->medium
.data
);
2934 if (medium_status
!= BT_MSG_ITER_MEDIUM_STATUS_OK
) {
2935 if (medium_status
== BT_MSG_ITER_MEDIUM_STATUS_EOF
) {
2936 ret
= BT_MSG_ITER_STATUS_EOF
;
2938 ret
= BT_MSG_ITER_STATUS_ERROR
;
2943 bt_msg_iter_reset(notit
);
2944 notit
->cur_packet_offset
= offset
;
2951 enum bt_msg_iter_status
bt_msg_iter_get_packet_properties(
2952 struct bt_msg_iter
*notit
,
2953 struct bt_msg_iter_packet_properties
*props
)
2955 enum bt_msg_iter_status status
;
2959 status
= read_packet_header_context_fields(notit
);
2960 if (status
!= BT_MSG_ITER_STATUS_OK
) {
2964 props
->exp_packet_total_size
= notit
->cur_exp_packet_total_size
;
2965 props
->exp_packet_content_size
= notit
->cur_exp_packet_content_size
;
2966 props
->stream_class_id
= (uint64_t) notit
->cur_stream_class_id
;
2967 props
->data_stream_id
= notit
->cur_data_stream_id
;
2968 props
->snapshots
.discarded_events
= notit
->snapshots
.discarded_events
;
2969 props
->snapshots
.packets
= notit
->snapshots
.packets
;
2970 props
->snapshots
.beginning_clock
= notit
->snapshots
.beginning_clock
;
2971 props
->snapshots
.end_clock
= notit
->snapshots
.end_clock
;
2978 void bt_msg_iter_set_emit_stream_beginning_message(struct bt_msg_iter
*notit
,
2981 notit
->emit_stream_begin_msg
= val
;
2985 void bt_msg_iter_set_emit_stream_end_message(struct bt_msg_iter
*notit
,
2988 notit
->emit_stream_end_msg
= val
;