X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fctf%2Fcommon%2Fnotif-iter%2Fnotif-iter.c;h=9a7fcb2f0687c0c921a0bad8cba3a4d2b4f63ab1;hb=4929b111b3c460f00f3f166e6172e3d7d1caed4d;hp=823a753ff29fcff4539ebeff616410fe1204f969;hpb=ac0c6bddcdde51dcbb46fc73c61d4f2330774451;p=babeltrace.git diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 823a753f..9a7fcb2f 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -38,15 +38,17 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include #include #include +#include -#define PRINT_ERR_STREAM notit->err_stream +#define PRINT_ERR_STREAM (notit ? notit->err_stream : stderr) #define PRINT_PREFIX "ctf-notif-iter" -#include "print.h" +#include "../print.h" #include "notif-iter.h" #include "../btr/btr.h" @@ -360,7 +362,7 @@ static inline enum bt_ctf_notif_iter_status notif_iter_status_from_m_status( enum bt_ctf_notif_iter_medium_status m_status) { - return m_status; + return (int) m_status; } static inline @@ -381,38 +383,12 @@ size_t packet_at(struct bt_ctf_notif_iter *notit) return notit->buf.packet_offset + notit->buf.at; } -static inline -size_t remaining_content_bits(struct bt_ctf_notif_iter *notit) -{ - if (notit->cur_content_size == -1) { - return -1; - } - - return notit->cur_content_size - packet_at(notit); -} - -static inline -size_t remaining_packet_bits(struct bt_ctf_notif_iter *notit) -{ - if (notit->cur_packet_size == -1) { - return -1; - } - - return notit->cur_packet_size - packet_at(notit); -} - static inline void buf_consume_bits(struct bt_ctf_notif_iter *notit, size_t incr) { notit->buf.at += incr; } -static inline -bool buf_has_enough_bits(struct bt_ctf_notif_iter *notit, size_t sz) -{ - return buf_available_bits(notit) >= sz; -} - static enum bt_ctf_notif_iter_status request_medium_bytes( struct bt_ctf_notif_iter *notit) @@ -597,14 +573,14 @@ static inline bool is_struct_type(struct bt_ctf_field_type *field_type) { return bt_ctf_field_type_get_type_id(field_type) == - BT_CTF_TYPE_ID_STRUCT; + BT_CTF_FIELD_TYPE_ID_STRUCT; } static inline bool is_variant_type(struct bt_ctf_field_type *field_type) { return bt_ctf_field_type_get_type_id(field_type) == - BT_CTF_TYPE_ID_VARIANT; + BT_CTF_FIELD_TYPE_ID_VARIANT; } static @@ -1408,22 +1384,21 @@ struct bt_ctf_field *get_next_field(struct bt_ctf_notif_iter *notit) } switch (bt_ctf_field_type_get_type_id(base_type)) { - case BT_CTF_TYPE_ID_STRUCT: + case BT_CTF_FIELD_TYPE_ID_STRUCT: next_field = bt_ctf_field_structure_get_field_by_index( base_field, index); break; - case BT_CTF_TYPE_ID_ARRAY: + case BT_CTF_FIELD_TYPE_ID_ARRAY: next_field = bt_ctf_field_array_get_field(base_field, index); break; - case BT_CTF_TYPE_ID_SEQUENCE: + case BT_CTF_FIELD_TYPE_ID_SEQUENCE: next_field = bt_ctf_field_sequence_get_field(base_field, index); break; - case BT_CTF_TYPE_ID_VARIANT: + case BT_CTF_FIELD_TYPE_ID_VARIANT: next_field = bt_ctf_field_variant_get_current_field(base_field); break; default: - assert(false); - break; + abort(); } end: @@ -1487,18 +1462,23 @@ end: static enum bt_ctf_btr_status update_clock(struct bt_ctf_notif_iter *notit, - struct bt_ctf_field_type *int_field_type, struct bt_ctf_field *int_field) { gboolean clock_class_found; uint64_t *clock_state; + struct bt_ctf_field_type *int_field_type = NULL; enum bt_ctf_btr_status ret = BT_CTF_BTR_STATUS_OK; - struct bt_ctf_clock_class *clock_class = - bt_ctf_field_type_integer_get_mapped_clock_class( - int_field_type); + struct bt_ctf_clock_class *clock_class = NULL; + int_field_type = bt_ctf_field_get_type(int_field); + if (unlikely(!int_field_type)) { + goto end; + } + + clock_class = bt_ctf_field_type_integer_get_mapped_clock_class( + int_field_type); if (likely(!clock_class)) { - goto end_no_clock; + goto end; } clock_class_found = g_hash_table_lookup_extended(notit->clock_states, @@ -1526,15 +1506,15 @@ enum bt_ctf_btr_status update_clock(struct bt_ctf_notif_iter *notit, /* Update the clock's state. */ update_clock_state(clock_state, int_field); end: + bt_put(int_field_type); bt_put(clock_class); -end_no_clock: return ret; } static enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value, struct bt_ctf_field_type *type, void *data, - struct bt_ctf_field **_field) + struct bt_ctf_field **out_int_field) { enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK; struct bt_ctf_field *field = NULL; @@ -1551,19 +1531,17 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value, } switch(bt_ctf_field_type_get_type_id(type)) { - case BT_CTF_TYPE_ID_INTEGER: + case BT_CTF_FIELD_TYPE_ID_INTEGER: /* Integer field is created field */ BT_MOVE(int_field, field); bt_get(type); break; - case BT_CTF_TYPE_ID_ENUM: + case BT_CTF_FIELD_TYPE_ID_ENUM: int_field = bt_ctf_field_enumeration_get_container(field); type = bt_ctf_field_get_type(int_field); break; default: - assert(0); - type = NULL; - break; + abort(); } if (!int_field) { @@ -1575,7 +1553,7 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value, ret = bt_ctf_field_unsigned_integer_set_value(int_field, value); assert(!ret); stack_top(notit->stack)->index++; - *_field = int_field; + *out_int_field = int_field; end: BT_PUT(field); @@ -1621,7 +1599,7 @@ enum bt_ctf_btr_status btr_unsigned_int_cb(uint64_t value, goto end; } - status = update_clock(notit, type, field); + status = update_clock(notit, field); BT_PUT(field); end: return status; @@ -1646,19 +1624,17 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value, } switch(bt_ctf_field_type_get_type_id(type)) { - case BT_CTF_TYPE_ID_INTEGER: + case BT_CTF_FIELD_TYPE_ID_INTEGER: /* Integer field is created field */ BT_MOVE(int_field, field); bt_get(type); break; - case BT_CTF_TYPE_ID_ENUM: + case BT_CTF_FIELD_TYPE_ID_ENUM: int_field = bt_ctf_field_enumeration_get_container(field); type = bt_ctf_field_get_type(int_field); break; default: - assert(0); - type = NULL; - break; + abort(); } if (!int_field) { @@ -1670,7 +1646,7 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value, ret = bt_ctf_field_signed_integer_set_value(int_field, value); assert(!ret); stack_top(notit->stack)->index++; - status = update_clock(notit, type, int_field); + status = update_clock(notit, int_field); end: BT_PUT(field); BT_PUT(int_field); @@ -2034,8 +2010,7 @@ int set_event_clocks(struct bt_ctf_event *event, ret = -1; goto end; } - ret = bt_ctf_event_set_clock_value(event, clock_class, - clock_value); + ret = bt_ctf_event_set_clock_value(event, clock_value); bt_put(clock_value); if (ret) { goto end; @@ -2077,7 +2052,7 @@ struct bt_ctf_event *create_event(struct bt_ctf_notif_iter *notit) goto error; } - ret = bt_ctf_event_set_payload_field(event, + ret = bt_ctf_event_set_event_payload(event, notit->dscopes.event_payload); if (ret) { goto error; @@ -2185,6 +2160,7 @@ void notify_end_of_packet(struct bt_ctf_notif_iter *notit, static void notify_event(struct bt_ctf_notif_iter *notit, + struct bt_clock_class_priority_map *cc_prio_map, struct bt_notification **notification) { struct bt_ctf_event *event; @@ -2196,7 +2172,7 @@ void notify_event(struct bt_ctf_notif_iter *notit, goto end; } - ret = bt_notification_event_create(event); + ret = bt_notification_event_create(event, cc_prio_map); if (!ret) { goto end; } @@ -2205,30 +2181,6 @@ end: BT_PUT(event); } -//FIXME: not used ? -static -void notify_eos(struct bt_ctf_notif_iter *notit, - struct bt_notification **notification) -{ - struct bt_ctf_stream *stream = NULL; - struct bt_notification *ret = NULL; - - /* Ask the user for the stream */ - stream = notit->medium.medops.get_stream(notit->meta.stream_class, - notit->medium.data); - if (!stream) { - goto end; - } - - ret = bt_notification_stream_end_create(stream); - if (!ret) { - goto end; - } - *notification = ret; -end: - BT_PUT(stream); -} - static int init_clock_states(GHashTable *clock_states, struct bt_ctf_trace *trace) { @@ -2243,7 +2195,7 @@ int init_clock_states(GHashTable *clock_states, struct bt_ctf_trace *trace) for (i = 0; i < clock_class_count; i++) { struct bt_ctf_clock_class *clock_class; - clock_class = bt_ctf_trace_get_clock_class(trace, i); + clock_class = bt_ctf_trace_get_clock_class_by_index(trace, i); if (!clock_class) { ret = -1; goto end; @@ -2329,6 +2281,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, assert(trace); assert(medops.request_bytes); + assert(medops.get_stream); notit = g_new0(struct bt_ctf_notif_iter, 1); if (!notit) { PERR("Failed to allocate memory for CTF notification iterator\n"); @@ -2419,6 +2372,7 @@ void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notit) enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification( struct bt_ctf_notif_iter *notit, + struct bt_clock_class_priority_map *cc_prio_map, struct bt_notification **notification) { enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK; @@ -2428,6 +2382,10 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification( while (true) { status = handle_state(notit); + if (status == BT_CTF_NOTIF_ITER_STATUS_AGAIN) { + PDBG("Medium operation reported \"try again later\""); + goto end; + } if (status != BT_CTF_NOTIF_ITER_STATUS_OK) { if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) { PDBG("Medium operation reported end of stream\n"); @@ -2448,7 +2406,7 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification( goto end; case STATE_EMIT_NOTIF_EVENT: PDBG("Emitting event notification\n"); - notify_event(notit, notification); + notify_event(notit, cc_prio_map, notification); if (!*notification) { status = BT_CTF_NOTIF_ITER_STATUS_ERROR; } @@ -2461,8 +2419,8 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification( bt_ctf_field_get_type( notit->cur_timestamp_end); - btr_status = update_clock(notit, field_type, - notit->cur_timestamp_end); + btr_status = update_clock(notit, + notit->cur_timestamp_end); BT_PUT(field_type); if (btr_status != BT_CTF_BTR_STATUS_OK) { status = BT_CTF_NOTIF_ITER_STATUS_ERROR; @@ -2485,3 +2443,72 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification( end: return status; } + +BT_HIDDEN +enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_packet_header_context_fields( + struct bt_ctf_notif_iter *notit, + struct bt_ctf_field **packet_header_field, + struct bt_ctf_field **packet_context_field) +{ + enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK; + + assert(notit); + + if (notit->state == STATE_EMIT_NOTIF_NEW_PACKET) { + /* We're already there */ + goto set_fields; + } + + while (true) { + status = handle_state(notit); + if (status == BT_CTF_NOTIF_ITER_STATUS_AGAIN) { + PDBG("Medium operation reported \"try again later\""); + goto end; + } + if (status != BT_CTF_NOTIF_ITER_STATUS_OK) { + if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) { + PDBG("Medium operation reported end of stream\n"); + } else { + PERR("Failed to handle state:\n"); + PERR("\tState: %d\n", notit->state); + } + goto end; + } + + switch (notit->state) { + case STATE_EMIT_NOTIF_NEW_PACKET: + /* + * Packet header and context fields are + * potentially decoded (or they don't exist). + */ + goto set_fields; + case STATE_INIT: + case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN: + case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE: + case STATE_AFTER_TRACE_PACKET_HEADER: + case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN: + case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE: + case STATE_AFTER_STREAM_PACKET_CONTEXT: + /* Non-emitting state: continue */ + break; + default: + /* + * We should never get past the + * STATE_EMIT_NOTIF_NEW_PACKET state. + */ + abort(); + } + } + +set_fields: + if (packet_header_field) { + *packet_header_field = bt_get(notit->dscopes.trace_packet_header); + } + + if (packet_context_field) { + *packet_context_field = bt_get(notit->dscopes.stream_packet_context); + } + +end: + return status; +}