X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fevents.c;h=0eb688a32c1c4966e6afaf0d19632038b9ed8fee;hb=f3985ab106d89d8e764c1a8dd0c8bda09b755d10;hp=3660c04812aada2749e3b0d1ce3c6e3357e46746;hpb=ebdb2383272428704cfbb8662f567159f3697cad;p=babeltrace.git diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 3660c048..0eb688a3 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -46,10 +46,10 @@ */ __thread int bt_ctf_last_field_error = 0; -const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event, - enum bt_ctf_scope scope) +const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event, + enum ctf_scope scope) { - const struct definition *tmp = NULL; + const struct bt_definition *tmp = NULL; const struct ctf_event_definition *event; if (!ctf_event) @@ -96,17 +96,17 @@ error: return NULL; } -const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, - const struct definition *scope, +const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, + const struct bt_definition *scope, const char *field) { - const struct definition *def; + const struct bt_definition *def; char *field_underscore; if (!ctf_event || !scope || !field) return NULL; - def = lookup_definition(scope, field); + def = bt_lookup_definition(scope, field); /* * optionally a field can have an underscore prefix, try * to lookup the field with this prefix if it failed @@ -115,7 +115,7 @@ const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, field_underscore = g_new(char, strlen(field) + 2); field_underscore[0] = '_'; strcpy(&field_underscore[1], field); - def = lookup_definition(scope, field_underscore); + def = bt_lookup_definition(scope, field_underscore); g_free(field_underscore); } if (bt_ctf_field_type(bt_ctf_get_decl_from_def(def)) == CTF_TYPE_VARIANT) { @@ -127,11 +127,11 @@ const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, return def; } -const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event, - const struct definition *field, +const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event, + const struct bt_definition *field, unsigned int index) { - struct definition *ret = NULL; + struct bt_definition *ret = NULL; if (!ctf_event || !field) return NULL; @@ -166,15 +166,15 @@ const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event) return g_quark_to_string(event_class->name); } -const char *bt_ctf_field_name(const struct definition *def) +const char *bt_ctf_field_name(const struct bt_definition *def) { - if (!def) + if (!def || !def->name) return NULL; return rem_(g_quark_to_string(def->name)); } -enum ctf_type_id bt_ctf_field_type(const struct declaration *decl) +enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl) { if (!decl) return CTF_TYPE_UNKNOWN; @@ -183,8 +183,8 @@ enum ctf_type_id bt_ctf_field_type(const struct declaration *decl) } int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, - const struct definition *scope, - struct definition const * const **list, + const struct bt_definition *scope, + struct bt_definition const * const **list, unsigned int *count) { if (!ctf_event || !scope || !list || !count) @@ -204,7 +204,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, if (!def_struct) goto error; if (def_struct->fields->pdata) { - *list = (struct definition const* const*) def_struct->fields->pdata; + *list = (struct bt_definition const* const*) def_struct->fields->pdata; *count = def_struct->fields->len; goto end; } else { @@ -222,7 +222,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, if (!def_variant) goto error; if (def_variant->fields->pdata) { - *list = (struct definition const* const*) def_variant->fields->pdata; + *list = (struct bt_definition const* const*) def_variant->fields->pdata; *count = def_variant->fields->len; goto end; } else { @@ -238,7 +238,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, if (!def_array) goto error; if (def_array->elems->pdata) { - *list = (struct definition const* const*) def_array->elems->pdata; + *list = (struct bt_definition const* const*) def_array->elems->pdata; *count = def_array->elems->len; goto end; } else { @@ -254,8 +254,8 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event, if (!def_sequence) goto error; if (def_sequence->elems->pdata) { - *list = (struct definition const* const*) def_sequence->elems->pdata; - *count = def_sequence->elems->len; + *list = (struct bt_definition const* const*) def_sequence->elems->pdata; + *count = (unsigned int) def_sequence->length->value._unsigned; goto end; } else { goto error; @@ -289,8 +289,8 @@ struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *ctf_event cfs = container_of(event->stream, const struct ctf_file_stream, parent); trace = cfs->parent.stream_class->trace; - if (trace->ctx) - ret = trace->ctx; + if (trace->parent.ctx) + ret = trace->parent.ctx; return ret; } @@ -309,24 +309,25 @@ int bt_ctf_event_get_handle_id(const struct bt_ctf_event *ctf_event) cfs = container_of(event->stream, const struct ctf_file_stream, parent); trace = cfs->parent.stream_class->trace; - if (trace->handle) - ret = trace->handle->id; + if (trace->parent.handle) + ret = trace->parent.handle->id; return ret; } -uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event) +int bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event, int64_t *timestamp) { const struct ctf_event_definition *event; - if (!ctf_event) - return -1ULL; + if (!ctf_event || !timestamp) + return -1; event = ctf_event->parent; if (event && event->stream->has_timestamp) - return event->stream->real_timestamp; + *timestamp = event->stream->real_timestamp; else - return -1ULL; + return -1; + return 0; } uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event) @@ -358,7 +359,7 @@ int bt_ctf_field_get_error(void) } static const struct declaration_integer * -get_declaration_integer(const struct declaration *decl) +get_declaration_integer(const struct bt_declaration *decl) { if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_INTEGER) return NULL; @@ -366,7 +367,7 @@ get_declaration_integer(const struct declaration *decl) } static const struct declaration_string * -get_declaration_string(const struct declaration *decl) +get_declaration_string(const struct bt_declaration *decl) { if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_STRING) return NULL; @@ -374,7 +375,7 @@ get_declaration_string(const struct declaration *decl) } static const struct declaration_array * -get_declaration_array(const struct declaration *decl) +get_declaration_array(const struct bt_declaration *decl) { if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_ARRAY) return NULL; @@ -382,14 +383,14 @@ get_declaration_array(const struct declaration *decl) } static const struct declaration_sequence * -get_declaration_sequence(const struct declaration *decl) +get_declaration_sequence(const struct bt_declaration *decl) { if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE) return NULL; return container_of(decl, const struct declaration_sequence, p); } -int bt_ctf_get_int_signedness(const struct declaration *decl) +int bt_ctf_get_int_signedness(const struct bt_declaration *decl) { const struct declaration_integer *integer; @@ -401,7 +402,7 @@ int bt_ctf_get_int_signedness(const struct declaration *decl) return integer->signedness; } -int bt_ctf_get_int_base(const struct declaration *decl) +int bt_ctf_get_int_base(const struct bt_declaration *decl) { const struct declaration_integer *integer; @@ -413,7 +414,7 @@ int bt_ctf_get_int_base(const struct declaration *decl) return integer->base; } -int bt_ctf_get_int_byte_order(const struct declaration *decl) +int bt_ctf_get_int_byte_order(const struct bt_declaration *decl) { const struct declaration_integer *integer; @@ -425,7 +426,7 @@ int bt_ctf_get_int_byte_order(const struct declaration *decl) return integer->byte_order; } -ssize_t bt_ctf_get_int_len(const struct declaration *decl) +ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl) { const struct declaration_integer *integer; @@ -437,7 +438,7 @@ ssize_t bt_ctf_get_int_len(const struct declaration *decl) return (ssize_t) integer->len; } -const struct definition *bt_ctf_get_enum_int(const struct definition *field) +const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field) { const struct definition_enum *def_enum; @@ -449,7 +450,7 @@ const struct definition *bt_ctf_get_enum_int(const struct definition *field) return &def_enum->integer->p; } -const char *bt_ctf_get_enum_str(const struct definition *field) +const char *bt_ctf_get_enum_str(const struct bt_definition *field) { const struct definition_enum *def_enum; const struct declaration_enum *decl_enum; @@ -478,14 +479,14 @@ const char *bt_ctf_get_enum_str(const struct definition *field) g_array_unref(array); bt_ctf_field_set_error(-ENOENT); return NULL; - } + } /* Return first string. Arbitrary choice. */ ret = g_quark_to_string(g_array_index(array, GQuark, 0)); g_array_unref(array); return ret; } -enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl) +enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl) { enum ctf_string_encoding ret = 0; enum ctf_type_id type; @@ -540,7 +541,7 @@ error: return -1; } -int bt_ctf_get_array_len(const struct declaration *decl) +int bt_ctf_get_array_len(const struct bt_declaration *decl) { const struct declaration_array *array; @@ -554,7 +555,7 @@ error: return -1; } -uint64_t bt_ctf_get_uint64(const struct definition *field) +uint64_t bt_ctf_get_uint64(const struct bt_definition *field) { uint64_t ret = 0; @@ -566,7 +567,7 @@ uint64_t bt_ctf_get_uint64(const struct definition *field) return ret; } -int64_t bt_ctf_get_int64(const struct definition *field) +int64_t bt_ctf_get_int64(const struct bt_definition *field) { int64_t ret = 0; @@ -578,7 +579,7 @@ int64_t bt_ctf_get_int64(const struct definition *field) return ret; } -char *bt_ctf_get_char_array(const struct definition *field) +char *bt_ctf_get_char_array(const struct bt_definition *field) { char *ret = NULL; GString *char_array; @@ -596,7 +597,7 @@ end: return ret; } -char *bt_ctf_get_string(const struct definition *field) +char *bt_ctf_get_string(const struct bt_definition *field) { char *ret = NULL; @@ -608,19 +609,88 @@ char *bt_ctf_get_string(const struct definition *field) return ret; } +double bt_ctf_get_float(const struct bt_definition *field) +{ + double ret = 0.0; + + if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_FLOAT) { + ret = bt_get_float(field); + } else { + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field) +{ + const struct bt_definition *ret = NULL; + + if (field && bt_ctf_field_type( + bt_ctf_get_decl_from_def(field)) == CTF_TYPE_VARIANT) { + struct definition_variant *variant = container_of(field, + struct definition_variant, p); + + ret = bt_variant_get_current_field(variant); + } else { + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *field) +{ + uint64_t ret = -1; + const struct bt_declaration *declaration = + bt_ctf_get_decl_from_def(field); + + if (field && bt_ctf_field_type(declaration) == CTF_TYPE_STRUCT) { + const struct declaration_struct *struct_declaration = + container_of(declaration, struct declaration_struct, p); + + ret = bt_struct_declaration_len(struct_declaration); + } else { + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +const struct bt_definition *bt_ctf_get_struct_field_index( + const struct bt_definition *field, uint64_t i) +{ + const struct bt_definition *ret = NULL; + + if (field && bt_ctf_field_type( + bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRUCT && + i < bt_ctf_get_struct_field_count(field)) { + const struct definition_struct *structure = container_of( + field, struct definition_struct, p); + + ret = bt_struct_definition_get_field_from_index(structure, i); + } + + if (!ret) { + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx, struct bt_ctf_event_decl * const **list, unsigned int *count) { struct bt_trace_handle *handle; - struct trace_descriptor *td; + struct bt_trace_descriptor *td; struct ctf_trace *tin; if (!ctx || !list || !count) goto error; handle = g_hash_table_lookup(ctx->trace_handles, - (gpointer) (unsigned long) handle_id); + GUINT_TO_POINTER(handle_id)); if (!handle) goto error; @@ -643,8 +713,16 @@ const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event) return g_quark_to_string(event->parent.name); } +uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event) +{ + if (!event) + return (uint64_t)(-1); + + return event->parent.id; +} + int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl, - enum bt_ctf_scope scope, + enum ctf_scope scope, struct bt_ctf_field_decl const * const **list, unsigned int *count) { @@ -653,11 +731,11 @@ int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl, gpointer *ret_list = NULL; GPtrArray *fields_array = NULL; int ret = 0; - *count = 0; if (!event_decl || !list || !count) return -EINVAL; + *count = 0; switch (scope) { case BT_EVENT_CONTEXT: if (event_decl->context_decl) { @@ -767,7 +845,7 @@ const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field) return rem_(g_quark_to_string(((struct declaration_field *) field)->name)); } -const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def) +const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def) { if (def) return def->declaration; @@ -775,7 +853,7 @@ const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def) return NULL; } -const struct declaration *bt_ctf_get_decl_from_field_decl( +const struct bt_declaration *bt_ctf_get_decl_from_field_decl( const struct bt_ctf_field_decl *field) { if (field)