* Babeltrace - CTF message iterator
*/
+#include <glib.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include <babeltrace2/babeltrace.h>
+
#define BT_COMP_LOG_SELF_COMP (msg_it->self_comp)
#define BT_LOG_OUTPUT_LEVEL (msg_it->log_level)
#define BT_LOG_TAG "PLUGIN/CTF/MSG-ITER"
#include "logging/comp-logging.h"
-#include <stdint.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdbool.h>
#include "common/assert.h"
-#include <string.h>
-#include <babeltrace2/babeltrace.h>
#include "common/common.h"
-#include <glib.h>
-#include <stdlib.h>
-#include "msg-iter.hpp"
#include "../bfcr/bfcr.hpp"
-
-struct ctf_msg_iter;
+#include "msg-iter.hpp"
+#include "plugins/ctf/common/metadata/ctf-meta.hpp"
/* A visit stack entry */
struct stack_entry
size_t index;
};
-struct ctf_msg_iter;
-
/* Visit stack */
struct stack
{
g_array_set_size(stack->entries, stack->size + 1);
}
- entry = &g_array_index(stack->entries, struct stack_entry, stack->size);
+ entry = &bt_g_array_index(stack->entries, struct stack_entry, stack->size);
entry->base = base;
entry->index = 0;
stack->size++;
{
BT_ASSERT_DBG(stack);
BT_ASSERT_DBG(stack_size(stack));
- return &g_array_index(stack->entries, struct stack_entry, stack->size - 1);
+ return &bt_g_array_index(stack->entries, struct stack_entry, stack->size - 1);
}
static inline bool stack_empty(struct stack *stack)
return status;
}
-BT_HIDDEN
void ctf_msg_iter_reset_for_next_stream_file(struct ctf_msg_iter *msg_it)
{
BT_ASSERT(msg_it);
/**
* Resets the internal state of a CTF message iterator.
*/
-BT_HIDDEN
void ctf_msg_iter_reset(struct ctf_msg_iter *msg_it)
{
ctf_msg_iter_reset_for_next_stream_file(msg_it);
msg_it->default_clock_snapshot);
}
+/*
+ * Ensure the message iterator's `stored_values` array is large enough to
+ * accommodate `storing_index`.
+ *
+ * We may need more slots in the array than initially allocated if more
+ * metadata arrives along the way.
+ */
+static void ensure_stored_values_size(ctf_msg_iter *msg_it, uint64_t storing_index)
+{
+ if (G_UNLIKELY(storing_index >= msg_it->stored_values->len)) {
+ g_array_set_size(msg_it->stored_values, msg_it->meta.tc->stored_value_count);
+ }
+}
+
static enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value, struct ctf_field_class *fc,
void *data)
{
}
if (G_UNLIKELY(int_fc->storing_index >= 0)) {
- g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = value;
+ ensure_stored_values_size(msg_it, int_fc->storing_index);
+ bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = value;
}
if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) {
BT_ASSERT_DBG(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE);
if (G_UNLIKELY(int_fc->storing_index >= 0)) {
- g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) =
+ ensure_stored_values_size(msg_it, int_fc->storing_index);
+ bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) =
(uint64_t) value;
}
int64_t length;
int ret;
- length = (uint64_t) g_array_index(msg_it->stored_values, uint64_t, seq_fc->stored_length_index);
+ length =
+ (uint64_t) bt_g_array_index(msg_it->stored_values, uint64_t, seq_fc->stored_length_index);
if (G_UNLIKELY(msg_it->dry_run)) {
goto end;
} tag;
/* Get variant's tag */
- tag.u = g_array_index(msg_it->stored_values, uint64_t, var_fc->stored_tag_index);
+ tag.u = bt_g_array_index(msg_it->stored_values, uint64_t, var_fc->stored_tag_index);
/*
* Check each range to find the selected option's index.
return msg;
}
-BT_HIDDEN
struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, size_t max_request_sz,
struct ctf_msg_iter_medium_ops medops, void *data,
bt_logging_level log_level, bt_self_component *self_comp,
}
goto end;
case STATE_EMIT_MSG_DISCARDED_EVENTS:
- /* create_msg_discared_events() logs errors */
+ /* create_msg_discarded_events() logs errors */
*message = create_msg_discarded_events(msg_it);
if (!*message) {
goto end;
case STATE_EMIT_MSG_DISCARDED_PACKETS:
- /* create_msg_discared_packets() logs errors */
+ /* create_msg_discarded_packets() logs errors */
*message = create_msg_discarded_packets(msg_it);
if (!*message) {
return status;
}
-BT_HIDDEN
enum ctf_msg_iter_status ctf_msg_iter_seek(struct ctf_msg_iter *msg_it, off_t offset)
{
enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
return status;
}
-BT_HIDDEN
enum ctf_msg_iter_status
ctf_msg_iter_curr_packet_first_event_clock_snapshot(struct ctf_msg_iter *msg_it,
uint64_t *first_clock_snapshot)
first_clock_snapshot);
}
-BT_HIDDEN
enum ctf_msg_iter_status
ctf_msg_iter_curr_packet_last_event_clock_snapshot(struct ctf_msg_iter *msg_it,
uint64_t *last_clock_snapshot)
STATE_EMIT_MSG_PACKET_END_MULTI, last_clock_snapshot);
}
-BT_HIDDEN
enum ctf_msg_iter_status
ctf_msg_iter_get_packet_properties(struct ctf_msg_iter *msg_it,
struct ctf_msg_iter_packet_properties *props)
return status;
}
-BT_HIDDEN
void ctf_msg_iter_set_dry_run(struct ctf_msg_iter *msg_it, bool val)
{
msg_it->dry_run = val;