/* True to emit a stream end message. */
bool emit_stream_end_msg;
+ /*
+ * True if library objects are unavailable during the decoding and
+ * should not be created/used.
+ */
+ bool dry_run;
+
/* True to set the stream */
bool set_stream;
BT_ASSERT(!notit->packet_context_field);
- if (packet_context_fc->in_ir) {
+ if (packet_context_fc->in_ir && !notit->dry_run) {
/*
* Create free packet context field from stream class.
* This field is going to be moved to the packet once we
goto end;
}
+ if (G_UNLIKELY(notit->dry_run)) {
+ goto next_state;
+ }
+
status = set_current_event_message(notit);
if (status != BT_MSG_ITER_STATUS_OK) {
goto end;
notit->event = bt_message_event_borrow_event(
notit->event_msg);
BT_ASSERT(notit->event);
+
+next_state:
notit->state = STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN;
end:
goto end;
}
- if (event_common_context_fc->in_ir) {
+ if (event_common_context_fc->in_ir && !notit->dry_run) {
BT_ASSERT(!notit->dscopes.event_common_context);
notit->dscopes.event_common_context =
bt_event_borrow_common_context_field(
goto end;
}
- if (event_spec_context_fc->in_ir) {
+ if (event_spec_context_fc->in_ir && !notit->dry_run) {
BT_ASSERT(!notit->dscopes.event_spec_context);
notit->dscopes.event_spec_context =
bt_event_borrow_specific_context_field(
goto end;
}
- if (event_payload_fc->in_ir) {
+ if (event_payload_fc->in_ir && !notit->dry_run) {
BT_ASSERT(!notit->dscopes.event_payload);
notit->dscopes.event_payload =
bt_event_borrow_payload_field(
bt_msg_iter_reset_for_next_stream_file(notit);
notit->cur_stream_class_id = -1;
notit->cur_data_stream_id = -1;
- notit->emit_stream_begin_msg = true;
- notit->emit_stream_end_msg = true;
notit->snapshots.discarded_events = UINT64_C(-1);
notit->snapshots.packets = UINT64_C(-1);
notit->prev_packet_snapshots.discarded_events = UINT64_C(-1);
(uint64_t) int_fc->storing_index) = value;
}
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
BT_ASSERT(!int_fc->mapped_clock_class);
BT_ASSERT(int_fc->storing_index < 0);
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
(uint64_t) int_fc->storing_index) = (uint64_t) value;
}
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
"fc-type=%d, fc-in-ir=%d, value=%f",
notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
"fc-type=%d, fc-in-ir=%d",
notit, notit->bfcr, fc, fc->type, fc->in_ir);
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
notit, notit->bfcr, fc, fc->type, fc->in_ir,
len);
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
"fc-type=%d, fc-in-ir=%d",
notit, notit->bfcr, fc, fc->type, fc->in_ir);
- if (G_UNLIKELY(!fc->in_ir)) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
"fc-type=%d, fc-in-ir=%d",
notit, notit->bfcr, fc, fc->type, fc->in_ir);
- if (!fc->in_ir) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
"fc-type=%d, fc-in-ir=%d",
notit, notit->bfcr, fc, fc->type, fc->in_ir);
- if (!fc->in_ir) {
+ if (G_UNLIKELY(!fc->in_ir || notit->dry_run)) {
goto end;
}
length = (uint64_t) g_array_index(notit->stored_values, uint64_t,
seq_fc->stored_length_index);
+
+ if (G_UNLIKELY(notit->dry_run)){
+ goto end;
+ }
+
seq_field = stack_top(notit->stack)->base;
BT_ASSERT(seq_field);
}
}
+end:
return length;
}
selected_option = ctf_field_class_variant_borrow_option_by_index(
var_fc, (uint64_t) option_index);
- if (selected_option->fc->in_ir) {
+ if (selected_option->fc->in_ir && !notit->dry_run) {
bt_field *var_field = stack_top(notit->stack)->base;
ret = bt_field_variant_select_option_field_by_index(
}
static
-enum bt_msg_iter_status read_packet_header_context_fields(
- struct bt_msg_iter *notit)
+enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *notit,
+ enum state target_state_1, enum state target_state_2)
{
- int ret;
enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
BT_ASSERT(notit);
notit->set_stream = false;
- if (notit->state == STATE_EMIT_MSG_PACKET_BEGINNING) {
- /* We're already there */
- goto end;
- }
+ do {
+ /*
+ * Check if we reached the state at which we want to stop
+ * decoding.
+ */
+ if (notit->state == target_state_1 ||
+ notit->state == target_state_2) {
+ goto end;
+ }
- while (true) {
status = handle_state(notit);
if (G_UNLIKELY(status == BT_MSG_ITER_STATUS_AGAIN)) {
BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
}
switch (notit->state) {
- case STATE_EMIT_MSG_PACKET_BEGINNING:
- /*
- * Packet header and context fields are
- * potentially decoded (or they don't exist).
- */
- goto end;
case STATE_INIT:
case STATE_SWITCH_PACKET:
case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
case STATE_EMIT_MSG_DISCARDED_EVENTS:
case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS:
case STATE_EMIT_MSG_DISCARDED_PACKETS:
- /* Non-emitting state: continue */
+ case STATE_EMIT_MSG_PACKET_BEGINNING:
+ case STATE_DSCOPE_EVENT_HEADER_BEGIN:
+ case STATE_DSCOPE_EVENT_HEADER_CONTINUE:
+ case STATE_AFTER_EVENT_HEADER:
+ case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN:
+ case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE:
+ case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN:
+ case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE:
+ case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN:
+ case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE:
+ case STATE_EMIT_MSG_EVENT:
+ case STATE_SKIP_PACKET_PADDING:
+ case STATE_EMIT_MSG_PACKET_END_MULTI:
+ case STATE_EMIT_MSG_PACKET_END_SINGLE:
+ case STATE_CHECK_EMIT_MSG_STREAM_END:
+ case STATE_EMIT_MSG_STREAM_END:
break;
+ case STATE_DONE:
+ /* fall-through */
default:
- /*
- * We should never get past the
- * STATE_EMIT_MSG_PACKET_BEGINNING state.
- */
+ /* We should never get to the STATE_DONE state. */
BT_COMP_LOGF("Unexpected state: notit-addr=%p, state=%s",
notit, state_string(notit->state));
abort();
}
- }
+ } while (true);
end:
+ return status;
+}
+
+static
+enum bt_msg_iter_status read_packet_header_context_fields(
+ struct bt_msg_iter *notit)
+{
+ int ret;
+ enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+
+ status = decode_until_state(notit, STATE_EMIT_MSG_PACKET_BEGINNING, -1);
+ if (status != BT_MSG_ITER_STATUS_OK) {
+ goto end;
+ }
+
ret = set_current_packet_content_sizes(notit);
if (ret) {
status = BT_MSG_ITER_STATUS_ERROR;
+ goto end;
}
+end:
return status;
}
return ret;
}
+static
+enum bt_msg_iter_status clock_snapshot_at_msg_iter_state(
+ struct bt_msg_iter *notit, enum state target_state_1,
+ enum state target_state_2, uint64_t *clock_snapshot)
+{
+ enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+
+ BT_ASSERT(notit);
+ BT_ASSERT(clock_snapshot);
+ status = decode_until_state(notit, target_state_1, target_state_2);
+ if (status != BT_MSG_ITER_STATUS_OK) {
+ goto end;
+ }
+
+ *clock_snapshot = notit->default_clock_snapshot;
+end:
+ return status;
+}
+
+BT_HIDDEN
+enum bt_msg_iter_status bt_msg_iter_curr_packet_first_event_clock_snapshot(
+ struct bt_msg_iter *notit, uint64_t *first_clock_snapshot)
+{
+ return clock_snapshot_at_msg_iter_state(notit,
+ STATE_AFTER_EVENT_HEADER, -1, first_clock_snapshot);
+}
+
+BT_HIDDEN
+enum bt_msg_iter_status bt_msg_iter_curr_packet_last_event_clock_snapshot(
+ struct bt_msg_iter *notit, uint64_t *last_clock_snapshot)
+{
+ return clock_snapshot_at_msg_iter_state(notit,
+ STATE_EMIT_MSG_PACKET_END_SINGLE,
+ STATE_EMIT_MSG_PACKET_END_MULTI, last_clock_snapshot);
+}
+
BT_HIDDEN
enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
struct bt_msg_iter *notit,
{
notit->emit_stream_end_msg = val;
}
+
+BT_HIDDEN
+void bt_msg_iter_set_dry_run(struct bt_msg_iter *notit,
+ bool val)
+{
+ notit->dry_run = val;
+}