X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fevents.c;h=b33796bc2dfbc9580e46b57d88848de266445862;hp=d14836b07135e25a447e23b68dd4c42e4f5229d6;hb=c50d2a7af8f63f3f4d2c0a6fce9a6e214d2baeda;hpb=57f3005ee4ea188f0a78edbd172a6bad9a70d3f5 diff --git a/formats/ctf/events.c b/formats/ctf/events.c index d14836b0..b33796bc 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -29,6 +29,8 @@ #include #include +#include "events-private.h" + /* * thread local storage to store the last error that occured * while reading a field, this variable must be accessed by @@ -36,90 +38,11 @@ */ __thread int bt_ctf_last_field_error = 0; -struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos) -{ - struct bt_ctf_iter *iter; - int ret; - - iter = g_new0(struct bt_ctf_iter, 1); - ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos); - if (ret) { - g_free(iter); - return NULL; - } - iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks)); - iter->recalculate_dep_graph = 0; - iter->main_callbacks.callback = NULL; - iter->dep_gc = g_ptr_array_new(); - return iter; -} - -void bt_ctf_iter_destroy(struct bt_ctf_iter *iter) -{ - struct bt_stream_callbacks *bt_stream_cb; - struct bt_callback_chain *bt_chain; - int i, j; - - /* free all events callbacks */ - if (iter->main_callbacks.callback) - g_array_free(iter->main_callbacks.callback, TRUE); - - /* free per-event callbacks */ - for (i = 0; i < iter->callbacks->len; i++) { - bt_stream_cb = &g_array_index(iter->callbacks, - struct bt_stream_callbacks, i); - if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks) - continue; - for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) { - bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks, - struct bt_callback_chain, j); - if (bt_chain->callback) { - g_array_free(bt_chain->callback, TRUE); - } - } - g_array_free(bt_stream_cb->per_id_callbacks, TRUE); - } - - bt_iter_fini(&iter->parent); - g_free(iter); -} - -struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter) -{ - return &iter->parent; -} - -struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter) -{ - struct ctf_file_stream *file_stream; - struct bt_ctf_event *ret = &iter->current_ctf_event; - - file_stream = heap_maximum(iter->parent.stream_heap); - if (!file_stream) { - /* end of file for all streams */ - goto stop; - } - ret->stream = &file_stream->parent; - ret->event = g_ptr_array_index(ret->stream->events_by_id, - ret->stream->event_id); - - if (ret->stream->stream_id > iter->callbacks->len) - goto end; - - process_callbacks(iter, ret->stream); - -end: - return ret; -stop: - return NULL; -} - -struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, +const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event, enum bt_ctf_scope scope) { struct definition *tmp = NULL; + struct ctf_event_definition *event = ctf_event->parent; switch (scope) { case BT_TRACE_PACKET_HEADER: @@ -147,16 +70,12 @@ struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, tmp = &event->stream->stream_event_context->p; break; case BT_EVENT_CONTEXT: - if (!event->event) - goto error; - if (event->event->event_context) - tmp = &event->event->event_context->p; + if (event->event_context) + tmp = &event->event_context->p; break; case BT_EVENT_FIELDS: - if (!event->event) - goto error; - if (event->event->event_fields) - tmp = &event->event->event_fields->p; + if (event->event_fields) + tmp = &event->event_fields->p; break; } return tmp; @@ -165,14 +84,26 @@ error: return NULL; } -struct definition *bt_ctf_get_field(struct bt_ctf_event *event, - struct definition *scope, +const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, + const struct definition *scope, const char *field) { struct definition *def; + char *field_underscore; if (scope) { def = lookup_definition(scope, field); + /* + * optionally a field can have an underscore prefix, try + * to lookup the field with this prefix if it failed + */ + if (!def) { + field_underscore = g_new(char, strlen(field) + 2); + field_underscore[0] = '_'; + strcpy(&field_underscore[1], field); + def = lookup_definition(scope, field_underscore); + g_free(field_underscore); + } if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) { struct definition_variant *variant_definition; variant_definition = container_of(def, @@ -184,8 +115,8 @@ struct definition *bt_ctf_get_field(struct bt_ctf_event *event, return NULL; } -struct definition *bt_ctf_get_index(struct bt_ctf_event *event, - struct definition *field, +const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event, + const struct definition *field, unsigned int index) { struct definition *ret = NULL; @@ -204,10 +135,11 @@ struct definition *bt_ctf_get_index(struct bt_ctf_event *event, return ret; } -const char *bt_ctf_event_name(struct bt_ctf_event *event) +const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event) { - struct ctf_event *event_class; - struct ctf_stream_class *stream_class; + struct ctf_event_declaration *event_class; + struct ctf_stream_declaration *stream_class; + struct ctf_event_definition *event = ctf_event->parent; if (!event) return NULL; @@ -220,7 +152,7 @@ const char *bt_ctf_event_name(struct bt_ctf_event *event) const char *bt_ctf_field_name(const struct definition *def) { if (def) - return g_quark_to_string(def->name); + return rem_(g_quark_to_string(def->name)); return NULL; } @@ -231,8 +163,8 @@ enum ctf_type_id bt_ctf_field_type(const struct definition *def) return CTF_TYPE_UNKNOWN; } -int bt_ctf_get_field_list(struct bt_ctf_event *event, - struct definition *scope, +int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, + const struct definition *scope, struct definition const * const **list, unsigned int *count) { @@ -244,9 +176,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_STRUCT: { - struct definition_struct *def_struct; + const struct definition_struct *def_struct; - def_struct = container_of(scope, struct definition_struct, p); + def_struct = container_of(scope, const struct definition_struct, p); if (!def_struct) goto error; if (def_struct->fields->pdata) { @@ -261,9 +193,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_VARIANT: { - struct definition_variant *def_variant; + const struct definition_variant *def_variant; - def_variant = container_of(scope, struct definition_variant, p); + def_variant = container_of(scope, const struct definition_variant, p); if (!def_variant) goto error; if (def_variant->fields->pdata) { @@ -276,9 +208,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_ARRAY: { - struct definition_array *def_array; + const struct definition_array *def_array; - def_array = container_of(scope, struct definition_array, p); + def_array = container_of(scope, const struct definition_array, p); if (!def_array) goto error; if (def_array->elems->pdata) { @@ -291,9 +223,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_SEQUENCE: { - struct definition_sequence *def_sequence; + const struct definition_sequence *def_sequence; - def_sequence = container_of(scope, struct definition_sequence, p); + def_sequence = container_of(scope, const struct definition_sequence, p); if (!def_sequence) goto error; if (def_sequence->elems->pdata) { @@ -317,39 +249,56 @@ error: return -1; } -uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event) +struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *ctf_event) { - if (event && event->stream->has_timestamp) - return event->stream->timestamp; - else - return -1ULL; + struct bt_context *ret = NULL; + struct ctf_file_stream *cfs; + struct ctf_trace *trace; + struct ctf_event_definition *event = ctf_event->parent; + + cfs = container_of(event->stream, struct ctf_file_stream, + parent); + trace = cfs->parent.stream_class->trace; + if (trace->ctx) + ret = trace->ctx; + + return ret; } -uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event) +int bt_ctf_event_get_handle_id(const struct bt_ctf_event *ctf_event) { - uint64_t ts_nsec; + int ret = -1; + struct ctf_file_stream *cfs; struct ctf_trace *trace; - struct trace_collection *tc; - uint64_t tc_offset; - uint64_t timestamp; + struct ctf_event_definition *event = ctf_event->parent; - if (!event->stream->has_timestamp) { - return -1ULL; - } + cfs = container_of(event->stream, struct ctf_file_stream, + parent); + trace = cfs->parent.stream_class->trace; + if (trace->handle) + ret = trace->handle->id; - trace = event->stream->stream_class->trace; - tc = trace->collection; - tc_offset = tc->single_clock_offset_avg; - timestamp = event->stream->timestamp; - if (event->stream->current_clock->freq == 1000000000ULL) { - ts_nsec = timestamp; - } else { - ts_nsec = (uint64_t) ((double) timestamp * 1000000000.0 - / (double) event->stream->current_clock->freq); - } - ts_nsec += tc_offset; + return ret; +} - return ts_nsec; +uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *ctf_event) +{ + struct ctf_event_definition *event = ctf_event->parent; + if (event && event->stream->has_timestamp) + return ctf_get_timestamp_raw(event->stream, + event->stream->timestamp); + else + return -1ULL; +} + +uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event) +{ + struct ctf_event_definition *event = ctf_event->parent; + if (event && event->stream->has_timestamp) + return ctf_get_timestamp(event->stream, + event->stream->timestamp); + else + return -1ULL; } static void bt_ctf_field_set_error(int error) @@ -366,6 +315,84 @@ int bt_ctf_field_get_error(void) return ret; } +int bt_ctf_get_int_signedness(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_signedness(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +int bt_ctf_get_int_base(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_base(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +int bt_ctf_get_int_byte_order(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_byte_order(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field) +{ + enum ctf_string_encoding ret = 0; + + if (!field) + goto end; + + if (bt_ctf_field_type(field) == CTF_TYPE_INTEGER) + ret = get_int_encoding(field); + else if (bt_ctf_field_type(field) == CTF_TYPE_STRING) + ret = get_string_encoding(field); + else + goto error; + +end: + return ret; + +error: + bt_ctf_field_set_error(-EINVAL); + return -1; +} + +int bt_ctf_get_array_len(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) { + ret = get_array_len(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + uint64_t bt_ctf_get_uint64(const struct definition *field) { unsigned int ret = 0;