X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Ffs-sink%2Ffs-sink-ctf-meta.h;h=e2045da3f9feba5813befac10696fd8c0df11cc9;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hp=6ae88dfb026e6546bf59bef9a89ad618e00141b4;hpb=578e048b5debf169e286e5b5cc747b5d6c16886d;p=babeltrace.git diff --git a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h index 6ae88dfb..e2045da3 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h @@ -1,24 +1,16 @@ -#ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H -#define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H - /* - * Copyright 2018-2019 - Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * SPDX-License-Identifier: MIT * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * Copyright 2018-2019 Philippe Proulx */ +#ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H +#define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H + #include #include "common/common.h" #include "common/assert.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #include @@ -26,12 +18,15 @@ #include enum fs_sink_ctf_field_class_type { + FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, + FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, + FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, }; @@ -52,6 +47,10 @@ struct fs_sink_ctf_field_class_bit_array { unsigned int size; }; +struct fs_sink_ctf_field_class_bool { + struct fs_sink_ctf_field_class_bit_array base; +}; + struct fs_sink_ctf_field_class_int { struct fs_sink_ctf_field_class_bit_array base; bool is_signed; @@ -79,6 +78,12 @@ struct fs_sink_ctf_field_class_struct { GArray *members; }; +struct fs_sink_ctf_field_class_option { + struct fs_sink_ctf_field_class base; + struct fs_sink_ctf_field_class *content_fc; + GString *tag_ref; +}; + struct fs_sink_ctf_field_class_variant { struct fs_sink_ctf_field_class base; GString *tag_ref; @@ -120,11 +125,11 @@ struct fs_sink_ctf_event_class { struct fs_sink_ctf_field_class *payload_fc; }; -struct fs_sink_ctf_trace_class; +struct fs_sink_ctf_trace; struct fs_sink_ctf_stream_class { /* Weak */ - struct fs_sink_ctf_trace_class *tc; + struct fs_sink_ctf_trace *trace; /* Weak */ const bt_stream_class *ir_sc; @@ -133,6 +138,7 @@ struct fs_sink_ctf_stream_class { const bt_clock_class *default_clock_class; GString *default_clock_class_name; + bool has_packets; bool packets_have_ts_begin; bool packets_have_ts_end; bool has_discarded_events; @@ -155,11 +161,14 @@ struct fs_sink_ctf_stream_class { GHashTable *event_classes_from_ir; }; -struct fs_sink_ctf_trace_class { +struct fs_sink_ctf_trace { + /* Weak */ + const bt_trace *ir_trace; + /* Weak */ const bt_trace_class *ir_tc; - unsigned char uuid[BABELTRACE_UUID_LEN]; + bt_uuid_t uuid; /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */ GPtrArray *stream_classes; @@ -204,8 +213,8 @@ void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc, (unsigned int) bt_field_class_integer_get_field_value_range( ir_fc), index_in_parent); - fc->is_signed = (ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || - ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); + fc->is_signed = bt_field_class_type_is(ir_fc_type, + BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); } static inline @@ -232,6 +241,41 @@ void _fs_sink_ctf_named_field_class_fini( named_fc->fc = NULL; } +static inline +struct fs_sink_ctf_field_class_bit_array * +fs_sink_ctf_field_class_bit_array_create( + const bt_field_class *ir_fc, uint64_t index_in_parent) +{ + struct fs_sink_ctf_field_class_bit_array *fc = + g_new0(struct fs_sink_ctf_field_class_bit_array, 1); + + BT_ASSERT(fc); + _fs_sink_ctf_field_class_bit_array_init((void *) fc, + FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc, + (unsigned int) bt_field_class_bit_array_get_length(ir_fc), + index_in_parent); + return fc; +} + +static inline +struct fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_bool_create( + const bt_field_class *ir_fc, uint64_t index_in_parent) +{ + struct fs_sink_ctf_field_class_bool *fc = + g_new0(struct fs_sink_ctf_field_class_bool, 1); + + BT_ASSERT(fc); + + /* + * CTF 1.8 has no boolean field class type, so this component + * translates it to an 8-bit unsigned integer field class. + */ + _fs_sink_ctf_field_class_bit_array_init((void *) fc, + FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, + 8, index_in_parent); + return fc; +} + static inline struct fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_int_create( const bt_field_class *ir_fc, uint64_t index_in_parent) @@ -255,7 +299,9 @@ struct fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_float_create( BT_ASSERT(fc); _fs_sink_ctf_field_class_bit_array_init((void *) fc, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, - ir_fc, bt_field_class_real_is_single_precision(ir_fc) ? 32 : 64, + ir_fc, + bt_field_class_get_type(ir_fc) == + BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64, index_in_parent); return fc; } @@ -290,6 +336,22 @@ struct fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_struct_create_emp return fc; } +static inline +struct fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_option_create_empty( + const bt_field_class *ir_fc, uint64_t index_in_parent) +{ + struct fs_sink_ctf_field_class_option *fc = + g_new0(struct fs_sink_ctf_field_class_option, 1); + + BT_ASSERT(fc); + _fs_sink_ctf_field_class_init((void *) fc, + FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, + 1, index_in_parent); + fc->tag_ref = g_string_new(NULL); + BT_ASSERT(fc->tag_ref); + return fc; +} + static inline struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_empty( const bt_field_class *ir_fc, uint64_t index_in_parent) @@ -307,8 +369,8 @@ struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_e fc->tag_ref = g_string_new(NULL); BT_ASSERT(fc->tag_ref); fc->tag_is_before = - bt_field_class_variant_borrow_selector_field_path_const(ir_fc) == - NULL; + bt_field_class_get_type(fc->base.ir_fc) == + BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD; return fc; } @@ -323,7 +385,7 @@ struct fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_array_create_empty _fs_sink_ctf_field_class_init((void *) fc, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, 1, index_in_parent); - fc->length = bt_field_class_static_array_get_length(ir_fc); + fc->length = bt_field_class_array_static_get_length(ir_fc); return fc; } @@ -341,8 +403,8 @@ struct fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_sequence_create fc->length_ref = g_string_new(NULL); BT_ASSERT(fc->length_ref); fc->length_is_before = - bt_field_class_dynamic_array_borrow_length_field_path_const(ir_fc) == - NULL; + bt_field_class_get_type(ir_fc) == + BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD; return fc; } @@ -362,6 +424,24 @@ void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc) BT_ASSERT(fc); } +static inline +void _fs_sink_ctf_field_class_bit_array_destroy( + struct fs_sink_ctf_field_class_int *fc) +{ + BT_ASSERT(fc); + _fs_sink_ctf_field_class_fini((void *) fc); + g_free(fc); +} + +static inline +void _fs_sink_ctf_field_class_bool_destroy( + struct fs_sink_ctf_field_class_int *fc) +{ + BT_ASSERT(fc); + _fs_sink_ctf_field_class_fini((void *) fc); + g_free(fc); +} + static inline void _fs_sink_ctf_field_class_int_destroy( struct fs_sink_ctf_field_class_int *fc) @@ -448,6 +528,22 @@ void _fs_sink_ctf_field_class_sequence_destroy( g_free(fc); } +static inline +void _fs_sink_ctf_field_class_option_destroy( + struct fs_sink_ctf_field_class_option *fc) +{ + BT_ASSERT(fc); + _fs_sink_ctf_field_class_fini((void *) fc); + fs_sink_ctf_field_class_destroy(fc->content_fc); + + if (fc->tag_ref) { + g_string_free(fc->tag_ref, TRUE); + fc->tag_ref = NULL; + } + + g_free(fc); +} + static inline void _fs_sink_ctf_field_class_variant_destroy( struct fs_sink_ctf_field_class_variant *fc) @@ -486,6 +582,12 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc) } switch (fc->type) { + case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: + _fs_sink_ctf_field_class_bool_destroy((void *) fc); + break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: + _fs_sink_ctf_field_class_bit_array_destroy((void *) fc); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: _fs_sink_ctf_field_class_int_destroy((void *) fc); break; @@ -504,11 +606,14 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc) case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE: _fs_sink_ctf_field_class_sequence_destroy((void *) fc); break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION: + _fs_sink_ctf_field_class_option_destroy((void *) fc); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT: _fs_sink_ctf_field_class_variant_destroy((void *) fc); break; default: - abort(); + bt_common_abort(); } } @@ -517,8 +622,8 @@ struct fs_sink_ctf_named_field_class * fs_sink_ctf_field_class_struct_borrow_member_by_index( struct fs_sink_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 fs_sink_ctf_named_field_class, index); } @@ -531,8 +636,8 @@ fs_sink_ctf_field_class_struct_borrow_member_by_name( uint64_t i; struct fs_sink_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 fs_sink_ctf_named_field_class *named_fc = @@ -631,8 +736,8 @@ struct fs_sink_ctf_named_field_class * fs_sink_ctf_field_class_variant_borrow_option_by_index( struct fs_sink_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 fs_sink_ctf_named_field_class, index); } @@ -645,8 +750,8 @@ fs_sink_ctf_field_class_variant_borrow_option_by_name( uint64_t i; struct fs_sink_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 fs_sink_ctf_named_field_class *named_fc = @@ -715,16 +820,16 @@ void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec) static inline struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create( - struct fs_sink_ctf_trace_class *tc, + struct fs_sink_ctf_trace *trace, const bt_stream_class *ir_sc) { struct fs_sink_ctf_stream_class *sc = g_new0(struct fs_sink_ctf_stream_class, 1); - BT_ASSERT(tc); + BT_ASSERT(trace); BT_ASSERT(ir_sc); BT_ASSERT(sc); - sc->tc = tc; + sc->trace = trace; sc->ir_sc = ir_sc; sc->default_clock_class = bt_stream_class_borrow_default_clock_class_const(ir_sc); @@ -736,6 +841,7 @@ struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create( sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, g_direct_equal); BT_ASSERT(sc->event_classes_from_ir); + sc->has_packets = bt_stream_class_supports_packets(ir_sc); sc->packets_have_ts_begin = bt_stream_class_packets_have_beginning_default_clock_snapshot( ir_sc); @@ -756,7 +862,7 @@ struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create( ir_sc); } - g_ptr_array_add(tc->stream_classes, sc); + g_ptr_array_add(trace->stream_classes, sc); return sc; } @@ -798,129 +904,37 @@ void fs_sink_ctf_stream_class_append_event_class( } static inline -void fs_sink_ctf_trace_class_destroy(struct fs_sink_ctf_trace_class *tc) +void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace) { - if (!tc) { + if (!trace) { return; } - if (tc->stream_classes) { - g_ptr_array_free(tc->stream_classes, TRUE); - tc->stream_classes = NULL; + if (trace->stream_classes) { + g_ptr_array_free(trace->stream_classes, TRUE); + trace->stream_classes = NULL; } - g_free(tc); + g_free(trace); } static inline -struct fs_sink_ctf_trace_class *fs_sink_ctf_trace_class_create( - const bt_trace_class *ir_tc) +struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace) { - struct fs_sink_ctf_trace_class *tc = - g_new0(struct fs_sink_ctf_trace_class, 1); + struct fs_sink_ctf_trace *trace = + g_new0(struct fs_sink_ctf_trace, 1); - BT_ASSERT(tc); + BT_ASSERT(trace); - if (bt_uuid_generate(tc->uuid)) { - fs_sink_ctf_trace_class_destroy(tc); - tc = NULL; - goto end; - } + bt_uuid_generate(trace->uuid); - tc->ir_tc = ir_tc; - tc->stream_classes = g_ptr_array_new_with_free_func( + trace->ir_trace = ir_trace; + trace->ir_tc = bt_trace_borrow_class_const(ir_trace); + trace->stream_classes = g_ptr_array_new_with_free_func( (GDestroyNotify) fs_sink_ctf_stream_class_destroy); - BT_ASSERT(tc->stream_classes); + BT_ASSERT(trace->stream_classes); -end: - return tc; -} - -static inline -bool fs_sink_ctf_ist_valid_identifier(const char *name) -{ - const char *at; - uint64_t i; - bool ist_valid = true; - static const char *reserved_keywords[] = { - "align", - "callsite", - "const", - "char", - "clock", - "double", - "enum", - "env", - "event", - "floating_point", - "float", - "integer", - "int", - "long", - "short", - "signed", - "stream", - "string", - "struct", - "trace", - "typealias", - "typedef", - "unsigned", - "variant", - "void", - "_Bool", - "_Complex", - "_Imaginary", - }; - - /* Make sure the name is not a reserved keyword */ - for (i = 0; i < sizeof(reserved_keywords) / sizeof(*reserved_keywords); - i++) { - if (strcmp(name, reserved_keywords[i]) == 0) { - ist_valid = false; - goto end; - } - } - - /* Make sure the name is not an empty string */ - if (strlen(name) == 0) { - ist_valid = false; - goto end; - } - - /* Make sure the name starts with a letter or `_` */ - if (!isalpha(name[0]) && name[0] != '_') { - ist_valid = false; - goto end; - } - - /* Make sure the name only contains letters, digits, and `_` */ - for (at = name; *at != '\0'; at++) { - if (!isalnum(*at) && *at != '_') { - ist_valid = false; - goto end; - } - } - -end: - return ist_valid; -} - -static inline -int fs_sink_ctf_protect_name(GString *name) -{ - int ret = 0; - - if (!fs_sink_ctf_ist_valid_identifier(name->str)) { - ret = -1; - goto end; - } - - /* Prepend `_` to protect it */ - g_string_prepend_c(name, '_'); - -end: - return ret; + return trace; } #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */