X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmetadata%2Fctf-meta.h;h=71232b03e2500b30573cb7cea86a55eb8cca8796;hb=c4f23e30bf67d2523163614bc9461d84cbe1ae80;hp=29c5e178797d738c5da4752f74e90cca98565c31;hpb=578e048b5debf169e286e5b5cc747b5d6c16886d;p=babeltrace.git diff --git a/src/plugins/ctf/common/metadata/ctf-meta.h b/src/plugins/ctf/common/metadata/ctf-meta.h index 29c5e178..71232b03 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta.h +++ b/src/plugins/ctf/common/metadata/ctf-meta.h @@ -17,8 +17,10 @@ #include #include "common/common.h" +#include "common/uuid.h" #include "common/assert.h" #include +#include #include #include @@ -49,6 +51,7 @@ enum ctf_field_class_meaning { }; enum ctf_byte_order { + CTF_BYTE_ORDER_UNKNOWN, CTF_BYTE_ORDER_DEFAULT, CTF_BYTE_ORDER_LITTLE, CTF_BYTE_ORDER_BIG, @@ -60,7 +63,8 @@ enum ctf_encoding { }; enum ctf_scope { - CTF_SCOPE_PACKET_HEADER, + CTF_SCOPE_PACKET_UNKNOWN = -1, + CTF_SCOPE_PACKET_HEADER = 0, CTF_SCOPE_PACKET_CONTEXT, CTF_SCOPE_EVENT_HEADER, CTF_SCOPE_EVENT_COMMON_CONTEXT, @@ -75,7 +79,7 @@ struct ctf_clock_class { uint64_t precision; int64_t offset_seconds; uint64_t offset_cycles; - uint8_t uuid[16]; + bt_uuid_t uuid; bool has_uuid; bool is_absolute; @@ -125,7 +129,9 @@ struct ctf_range { struct ctf_field_class_enum_mapping { GString *label; - struct ctf_range range; + + /* Array of `struct ctf_range` */ + GArray *ranges; }; struct ctf_field_class_enum { @@ -145,6 +151,10 @@ struct ctf_field_class_string { }; struct ctf_named_field_class { + /* Original name which can include a leading `_` */ + GString *orig_name; + + /* Name as translated to trace IR (leading `_` removed) */ GString *name; /* Owned by this */ @@ -214,6 +224,7 @@ struct ctf_event_class { GString *emf_uri; bt_event_class_log_level log_level; bool is_translated; + bool is_log_level_set; /* Owned by this */ struct ctf_field_class *spec_context_fc; @@ -278,7 +289,7 @@ struct ctf_trace_class_env_entry { struct ctf_trace_class { unsigned int major; unsigned int minor; - uint8_t uuid[16]; + bt_uuid_t uuid; bool is_uuid_set; enum ctf_byte_order default_byte_order; @@ -300,6 +311,12 @@ struct ctf_trace_class { /* Weak, set during translation */ bt_trace_class *ir_tc; + + struct { + bool lttng_crash; + bool lttng_event_after_packet; + bool barectf_event_before_packet; + } quirks; }; static inline @@ -355,6 +372,8 @@ void _ctf_named_field_class_init(struct ctf_named_field_class *named_fc) BT_ASSERT(named_fc); named_fc->name = g_string_new(NULL); BT_ASSERT(named_fc->name); + named_fc->orig_name = g_string_new(NULL); + BT_ASSERT(named_fc->orig_name); } static inline @@ -366,6 +385,10 @@ void _ctf_named_field_class_fini(struct ctf_named_field_class *named_fc) g_string_free(named_fc->name, TRUE); } + if (named_fc->orig_name) { + g_string_free(named_fc->orig_name, TRUE); + } + ctf_field_class_destroy(named_fc->fc); } @@ -376,6 +399,8 @@ void _ctf_field_class_enum_mapping_init( BT_ASSERT(mapping); mapping->label = g_string_new(NULL); BT_ASSERT(mapping->label); + mapping->ranges = g_array_new(FALSE, TRUE, sizeof(struct ctf_range)); + BT_ASSERT(mapping->ranges); } static inline @@ -387,6 +412,10 @@ void _ctf_field_class_enum_mapping_fini( if (mapping->label) { g_string_free(mapping->label, TRUE); } + + if (mapping->ranges) { + g_array_free(mapping->ranges, TRUE); + } } static inline @@ -660,39 +689,92 @@ void ctf_field_class_destroy(struct ctf_field_class *fc) } static inline -void ctf_field_class_enum_append_mapping(struct ctf_field_class_enum *fc, - const char *label, uint64_t u_lower, uint64_t u_upper) +struct ctf_range *ctf_field_class_enum_mapping_borrow_range_by_index( + struct ctf_field_class_enum_mapping *mapping, uint64_t index) { - struct ctf_field_class_enum_mapping *mapping; - - BT_ASSERT(fc); - BT_ASSERT(label); - g_array_set_size(fc->mappings, fc->mappings->len + 1); - - mapping = &g_array_index(fc->mappings, - struct ctf_field_class_enum_mapping, fc->mappings->len - 1); - _ctf_field_class_enum_mapping_init(mapping); - g_string_assign(mapping->label, label); - mapping->range.lower.u = u_lower; - mapping->range.upper.u = u_upper; + BT_ASSERT_DBG(mapping); + BT_ASSERT_DBG(index < mapping->ranges->len); + return &g_array_index(mapping->ranges, struct ctf_range, index); } static inline struct ctf_field_class_enum_mapping *ctf_field_class_enum_borrow_mapping_by_index( struct ctf_field_class_enum *fc, uint64_t index) { - BT_ASSERT(fc); - BT_ASSERT(index < fc->mappings->len); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(index < fc->mappings->len); return &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, index); } +static inline +struct ctf_field_class_enum_mapping *ctf_field_class_enum_borrow_mapping_by_label( + struct ctf_field_class_enum *fc, const char *label) +{ + struct ctf_field_class_enum_mapping *ret_mapping = NULL; + uint64_t i; + + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(label); + + for (i = 0; i < fc->mappings->len; i++) { + struct ctf_field_class_enum_mapping *mapping = + ctf_field_class_enum_borrow_mapping_by_index(fc, i); + + if (strcmp(mapping->label->str, label) == 0) { + ret_mapping = mapping; + goto end; + } + } + +end: + return ret_mapping; +} + +static inline +void ctf_field_class_enum_map_range(struct ctf_field_class_enum *fc, + const char *label, uint64_t u_lower, uint64_t u_upper) +{ + struct ctf_field_class_enum_mapping *mapping = NULL; + struct ctf_range range = { + .lower.u = u_lower, + .upper.u = u_upper, + }; + uint64_t i; + + BT_ASSERT(fc); + BT_ASSERT(label); + + for (i = 0; i < fc->mappings->len; i++) { + mapping = ctf_field_class_enum_borrow_mapping_by_index( + fc, i); + + if (strcmp(mapping->label->str, label) == 0) { + break; + } + } + + if (i == fc->mappings->len) { + mapping = NULL; + } + + if (!mapping) { + g_array_set_size(fc->mappings, fc->mappings->len + 1); + mapping = ctf_field_class_enum_borrow_mapping_by_index( + fc, fc->mappings->len - 1); + _ctf_field_class_enum_mapping_init(mapping); + g_string_assign(mapping->label, label); + } + + g_array_append_val(mapping->ranges, range); +} + static inline struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_index( struct ctf_field_class_struct *fc, uint64_t index) { - BT_ASSERT(fc); - BT_ASSERT(index < fc->members->len); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(index < fc->members->len); return &g_array_index(fc->members, struct ctf_named_field_class, index); } @@ -704,8 +786,8 @@ struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_name( uint64_t i; struct ctf_named_field_class *ret_named_fc = NULL; - BT_ASSERT(fc); - BT_ASSERT(name); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(name); for (i = 0; i < fc->members->len; i++) { struct ctf_named_field_class *named_fc = @@ -767,21 +849,34 @@ end: return int_fc; } +static inline +void _ctf_named_field_class_unescape_orig_name( + struct ctf_named_field_class *named_fc) +{ + const char *name = named_fc->orig_name->str; + + if (name[0] == '_') { + name++; + } + + g_string_assign(named_fc->name, name); +} static inline void ctf_field_class_struct_append_member(struct ctf_field_class_struct *fc, - const char *name, struct ctf_field_class *member_fc) + const char *orig_name, struct ctf_field_class *member_fc) { struct ctf_named_field_class *named_fc; BT_ASSERT(fc); - BT_ASSERT(name); + BT_ASSERT(orig_name); g_array_set_size(fc->members, fc->members->len + 1); named_fc = &g_array_index(fc->members, struct ctf_named_field_class, fc->members->len - 1); _ctf_named_field_class_init(named_fc); - g_string_assign(named_fc->name, name); + g_string_assign(named_fc->orig_name, orig_name); + _ctf_named_field_class_unescape_orig_name(named_fc); named_fc->fc = member_fc; if (member_fc->alignment > fc->base.alignment) { @@ -793,8 +888,8 @@ static inline struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_index( struct ctf_field_class_variant *fc, uint64_t index) { - BT_ASSERT(fc); - BT_ASSERT(index < fc->options->len); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(index < fc->options->len); return &g_array_index(fc->options, struct ctf_named_field_class, index); } @@ -806,8 +901,8 @@ struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_name( uint64_t i; struct ctf_named_field_class *ret_named_fc = NULL; - BT_ASSERT(fc); - BT_ASSERT(name); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(name); for (i = 0; i < fc->options->len; i++) { struct ctf_named_field_class *named_fc = @@ -828,26 +923,27 @@ struct ctf_field_class_variant_range * ctf_field_class_variant_borrow_range_by_index( struct ctf_field_class_variant *fc, uint64_t index) { - BT_ASSERT(fc); - BT_ASSERT(index < fc->ranges->len); + BT_ASSERT_DBG(fc); + BT_ASSERT_DBG(index < fc->ranges->len); return &g_array_index(fc->ranges, struct ctf_field_class_variant_range, index); } static inline void ctf_field_class_variant_append_option(struct ctf_field_class_variant *fc, - const char *name, struct ctf_field_class *option_fc) + const char *orig_name, struct ctf_field_class *option_fc) { struct ctf_named_field_class *named_fc; BT_ASSERT(fc); - BT_ASSERT(name); + BT_ASSERT(orig_name); g_array_set_size(fc->options, fc->options->len + 1); named_fc = &g_array_index(fc->options, struct ctf_named_field_class, fc->options->len - 1); _ctf_named_field_class_init(named_fc); - g_string_assign(named_fc->name, name); + g_string_assign(named_fc->orig_name, orig_name); + _ctf_named_field_class_unescape_orig_name(named_fc); named_fc->fc = option_fc; } @@ -863,25 +959,28 @@ void ctf_field_class_variant_set_tag_field_class( fc->tag_fc = tag_fc; for (option_i = 0; option_i < fc->options->len; option_i++) { - uint64_t mapping_i; + uint64_t range_i; struct ctf_named_field_class *named_fc = ctf_field_class_variant_borrow_option_by_index( fc, option_i); + struct ctf_field_class_enum_mapping *mapping; - for (mapping_i = 0; mapping_i < tag_fc->mappings->len; - mapping_i++) { - struct ctf_field_class_enum_mapping *mapping = - ctf_field_class_enum_borrow_mapping_by_index( - tag_fc, mapping_i); + mapping = ctf_field_class_enum_borrow_mapping_by_label( + tag_fc, named_fc->orig_name->str); + if (!mapping) { + continue; + } - if (strcmp(named_fc->name->str, - mapping->label->str) == 0) { - struct ctf_field_class_variant_range range; + for (range_i = 0; range_i < mapping->ranges->len; + range_i++) { + struct ctf_range *range = + ctf_field_class_enum_mapping_borrow_range_by_index( + mapping, range_i); + struct ctf_field_class_variant_range var_range; - range.range = mapping->range; - range.option_index = option_i; - g_array_append_val(fc->ranges, range); - } + var_range.range = *range; + var_range.option_index = option_i; + g_array_append_val(fc->ranges, var_range); } } } @@ -899,7 +998,7 @@ struct ctf_field_class *ctf_field_class_compound_borrow_field_class_by_index( ctf_field_class_struct_borrow_member_by_index( (void *) comp_fc, index); - BT_ASSERT(named_fc); + BT_ASSERT_DBG(named_fc); fc = named_fc->fc; break; } @@ -909,7 +1008,7 @@ struct ctf_field_class *ctf_field_class_compound_borrow_field_class_by_index( ctf_field_class_variant_borrow_option_by_index( (void *) comp_fc, index); - BT_ASSERT(named_fc); + BT_ASSERT_DBG(named_fc); fc = named_fc->fc; break; } @@ -964,8 +1063,8 @@ uint64_t ctf_field_class_compound_get_field_class_count(struct ctf_field_class * } static inline -int64_t ctf_field_class_compound_get_field_class_index_from_name( - struct ctf_field_class *fc, const char *name) +int64_t ctf_field_class_compound_get_field_class_index_from_orig_name( + struct ctf_field_class *fc, const char *orig_name) { int64_t ret_index = -1; uint64_t i; @@ -980,7 +1079,7 @@ int64_t ctf_field_class_compound_get_field_class_index_from_name( ctf_field_class_struct_borrow_member_by_index( struct_fc, i); - if (strcmp(name, named_fc->name->str) == 0) { + if (strcmp(orig_name, named_fc->orig_name->str) == 0) { ret_index = (int64_t) i; goto end; } @@ -997,7 +1096,7 @@ int64_t ctf_field_class_compound_get_field_class_index_from_name( ctf_field_class_variant_borrow_option_by_index( var_fc, i); - if (strcmp(name, named_fc->name->str) == 0) { + if (strcmp(orig_name, named_fc->orig_name->str) == 0) { ret_index = (int64_t) i; goto end; } @@ -1024,8 +1123,8 @@ static inline int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path *fp, uint64_t index) { - BT_ASSERT(fp); - BT_ASSERT(index < fp->path->len); + BT_ASSERT_DBG(fp); + BT_ASSERT_DBG(index < fp->path->len); return g_array_index(fp->path, int64_t, index); } @@ -1041,17 +1140,17 @@ const char *ctf_scope_string(enum ctf_scope scope) { switch (scope) { case CTF_SCOPE_PACKET_HEADER: - return "CTF_SCOPE_PACKET_HEADER"; + return "PACKET_HEADER"; case CTF_SCOPE_PACKET_CONTEXT: - return "CTF_SCOPE_PACKET_CONTEXT"; + return "PACKET_CONTEXT"; case CTF_SCOPE_EVENT_HEADER: - return "CTF_SCOPE_EVENT_HEADER"; + return "EVENT_HEADER"; case CTF_SCOPE_EVENT_COMMON_CONTEXT: - return "CTF_SCOPE_EVENT_COMMON_CONTEXT"; + return "EVENT_COMMON_CONTEXT"; case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: - return "CTF_SCOPE_EVENT_SPECIFIC_CONTEXT"; + return "EVENT_SPECIFIC_CONTEXT"; case CTF_SCOPE_EVENT_PAYLOAD: - return "CTF_SCOPE_EVENT_PAYLOAD"; + return "EVENT_PAYLOAD"; default: abort(); } @@ -1115,7 +1214,7 @@ struct ctf_field_class *ctf_field_path_borrow_field_class( abort(); } - BT_ASSERT(fc); + BT_ASSERT_DBG(fc); for (i = 0; i < field_path->path->len; i++) { int64_t child_index = @@ -1123,11 +1222,11 @@ struct ctf_field_class *ctf_field_path_borrow_field_class( struct ctf_field_class *child_fc = ctf_field_class_compound_borrow_field_class_by_index( fc, child_index); - BT_ASSERT(child_fc); + BT_ASSERT_DBG(child_fc); fc = child_fc; } - BT_ASSERT(fc); + BT_ASSERT_DBG(fc); return fc; } @@ -1181,12 +1280,21 @@ struct ctf_field_class_enum *_ctf_field_class_enum_copy( ctf_field_class_int_copy_content((void *) copy_fc, (void *) fc); for (i = 0; i < fc->mappings->len; i++) { + uint64_t range_i; + struct ctf_field_class_enum_mapping *mapping = &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, i); - ctf_field_class_enum_append_mapping(copy_fc, mapping->label->str, - mapping->range.lower.u, mapping->range.upper.u); + for (range_i = 0; range_i < mapping->ranges->len; range_i++) { + struct ctf_range *range = + &g_array_index(mapping->ranges, + struct ctf_range, range_i); + + ctf_field_class_enum_map_range(copy_fc, + mapping->label->str, range->lower.u, + range->upper.u); + } } return copy_fc; @@ -1387,10 +1495,19 @@ struct ctf_event_class *ctf_event_class_create(void) BT_ASSERT(ec->name); ec->emf_uri = g_string_new(NULL); BT_ASSERT(ec->emf_uri); - ec->log_level = -1; + ec->is_log_level_set = false; return ec; } +static inline +void ctf_event_class_set_log_level(struct ctf_event_class *ec, + enum bt_event_class_log_level log_level) +{ + BT_ASSERT(ec); + ec->log_level = log_level; + ec->is_log_level_set = true; +} + static inline void ctf_event_class_destroy(struct ctf_event_class *ec) { @@ -1460,7 +1577,7 @@ static inline struct ctf_event_class *ctf_stream_class_borrow_event_class_by_id( struct ctf_stream_class *sc, uint64_t type) { - BT_ASSERT(sc); + BT_ASSERT_DBG(sc); return g_hash_table_lookup(sc->event_classes_by_id, GUINT_TO_POINTER((guint) type)); } @@ -1527,7 +1644,7 @@ struct ctf_trace_class *ctf_trace_class_create(void) struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1); BT_ASSERT(tc); - tc->default_byte_order = -1; + tc->default_byte_order = CTF_BYTE_ORDER_UNKNOWN; tc->clock_classes = g_ptr_array_new_with_free_func( (GDestroyNotify) ctf_clock_class_destroy); BT_ASSERT(tc->clock_classes); @@ -1604,7 +1721,7 @@ struct ctf_stream_class *ctf_trace_class_borrow_stream_class_by_id( uint64_t i; struct ctf_stream_class *ret_sc = NULL; - BT_ASSERT(tc); + BT_ASSERT_DBG(tc); for (i = 0; i < tc->stream_classes->len; i++) { struct ctf_stream_class *sc = tc->stream_classes->pdata[i]; @@ -1626,13 +1743,13 @@ struct ctf_clock_class *ctf_trace_class_borrow_clock_class_by_name( uint64_t i; struct ctf_clock_class *ret_cc = NULL; - BT_ASSERT(tc); - BT_ASSERT(name); + BT_ASSERT_DBG(tc); + BT_ASSERT_DBG(name); for (i = 0; i < tc->clock_classes->len; i++) { struct ctf_clock_class *cc = tc->clock_classes->pdata[i]; - BT_ASSERT(cc->name); + BT_ASSERT_DBG(cc->name); if (strcmp(cc->name->str, name) == 0) { ret_cc = cc; goto end; @@ -1647,8 +1764,8 @@ static inline struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_index( struct ctf_trace_class *tc, uint64_t index) { - BT_ASSERT(tc); - BT_ASSERT(index < tc->env_entries->len); + BT_ASSERT_DBG(tc); + BT_ASSERT_DBG(index < tc->env_entries->len); return &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, index); } @@ -1660,8 +1777,8 @@ struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_name( struct ctf_trace_class_env_entry *ret_entry = NULL; uint64_t i; - BT_ASSERT(tc); - BT_ASSERT(name); + BT_ASSERT_DBG(tc); + BT_ASSERT_DBG(name); for (i = 0; i < tc->env_entries->len; i++) { struct ctf_trace_class_env_entry *env_entry =