X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fevents.c;h=b35f54a8ecba9cee1f5000323b47b3c082462c7a;hb=17d37c4d92c1f0f8e81b18ae1cde2c509dc06d54;hp=5ac74e6e1617cff6961713498d7cb21cff282033;hpb=5c5facc70af60670ec8f53b9d90d13722a8477f4;p=babeltrace.git diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 5ac74e6e..b35f54a8 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -23,8 +23,14 @@ #include #include #include +#include +#include +#include +#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 @@ -32,6 +38,86 @@ */ __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, enum bt_ctf_scope scope) { @@ -86,9 +172,21 @@ struct definition *bt_ctf_get_field(struct bt_ctf_event *event, 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, @@ -136,11 +234,11 @@ 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; } -enum ctf_type_id bt_ctf_field_type(struct definition *def) +enum ctf_type_id bt_ctf_field_type(const struct definition *def) { if (def) return def->declaration->id; @@ -233,12 +331,22 @@ error: return -1; } +uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event) +{ + 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(struct bt_ctf_event *event) { if (event && event->stream->has_timestamp) - return event->stream->timestamp; + return ctf_get_timestamp(event->stream, + event->stream->timestamp); else - return 0; + return -1ULL; } static void bt_ctf_field_set_error(int error) @@ -255,7 +363,85 @@ int bt_ctf_field_get_error(void) return ret; } -uint64_t bt_ctf_get_uint64(struct definition *field) +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; @@ -267,7 +453,7 @@ uint64_t bt_ctf_get_uint64(struct definition *field) return ret; } -int64_t bt_ctf_get_int64(struct definition *field) +int64_t bt_ctf_get_int64(const struct definition *field) { int ret = 0; @@ -280,7 +466,7 @@ int64_t bt_ctf_get_int64(struct definition *field) } -char *bt_ctf_get_char_array(struct definition *field) +char *bt_ctf_get_char_array(const struct definition *field) { char *ret = NULL; @@ -292,7 +478,7 @@ char *bt_ctf_get_char_array(struct definition *field) return ret; } -char *bt_ctf_get_string(struct definition *field) +char *bt_ctf_get_string(const struct definition *field) { char *ret = NULL;