| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #include <babeltrace2/babeltrace.h> |
| 8 | |
| 9 | #include "common/assert.h" |
| 10 | #include "cpp-common/bt2c/logging.hpp" |
| 11 | |
| 12 | #include "ctf-meta-visitors.hpp" |
| 13 | |
| 14 | static inline void warn_meaningless_field(const char *name, const char *scope_name, |
| 15 | const bt2c::Logger& logger) |
| 16 | { |
| 17 | BT_ASSERT(name); |
| 18 | BT_CPPLOGW_SPEC(logger, "User field found in {}: ignoring: name=\"{}\"", scope_name, name); |
| 19 | } |
| 20 | |
| 21 | static inline void warn_meaningless_fields(struct ctf_field_class *fc, const char *name, |
| 22 | const char *scope_name, const bt2c::Logger& logger) |
| 23 | { |
| 24 | uint64_t i; |
| 25 | |
| 26 | if (!fc) { |
| 27 | goto end; |
| 28 | } |
| 29 | |
| 30 | /* |
| 31 | * 'name' is guaranteed to be non-NULL whenever the field class is not a |
| 32 | * structure. In the case of a structure field class, its members' names |
| 33 | * are used. |
| 34 | */ |
| 35 | switch (fc->type) { |
| 36 | case CTF_FIELD_CLASS_TYPE_FLOAT: |
| 37 | case CTF_FIELD_CLASS_TYPE_STRING: |
| 38 | warn_meaningless_field(name, scope_name, logger); |
| 39 | break; |
| 40 | case CTF_FIELD_CLASS_TYPE_INT: |
| 41 | case CTF_FIELD_CLASS_TYPE_ENUM: |
| 42 | { |
| 43 | struct ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); |
| 44 | |
| 45 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE && !int_fc->mapped_clock_class) { |
| 46 | warn_meaningless_field(name, scope_name, logger); |
| 47 | } |
| 48 | |
| 49 | break; |
| 50 | } |
| 51 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
| 52 | { |
| 53 | struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc); |
| 54 | |
| 55 | for (i = 0; i < struct_fc->members->len; i++) { |
| 56 | struct ctf_named_field_class *named_fc = |
| 57 | ctf_field_class_struct_borrow_member_by_index(struct_fc, i); |
| 58 | |
| 59 | warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); |
| 60 | } |
| 61 | |
| 62 | break; |
| 63 | } |
| 64 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
| 65 | { |
| 66 | struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); |
| 67 | |
| 68 | for (i = 0; i < var_fc->options->len; i++) { |
| 69 | struct ctf_named_field_class *named_fc = |
| 70 | ctf_field_class_variant_borrow_option_by_index(var_fc, i); |
| 71 | |
| 72 | warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); |
| 73 | } |
| 74 | |
| 75 | break; |
| 76 | } |
| 77 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
| 78 | { |
| 79 | struct ctf_field_class_array *array_fc = ctf_field_class_as_array(fc); |
| 80 | |
| 81 | if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) { |
| 82 | goto end; |
| 83 | } |
| 84 | } |
| 85 | /* fall-through */ |
| 86 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: |
| 87 | { |
| 88 | struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); |
| 89 | |
| 90 | warn_meaningless_fields(array_fc->elem_fc, name, scope_name, logger); |
| 91 | break; |
| 92 | } |
| 93 | default: |
| 94 | bt_common_abort(); |
| 95 | } |
| 96 | |
| 97 | end: |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | void ctf_trace_class_warn_meaningless_header_fields(struct ctf_trace_class *ctf_tc, |
| 102 | const bt2c::Logger& parentLogger) |
| 103 | { |
| 104 | uint64_t i; |
| 105 | bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"}; |
| 106 | |
| 107 | if (!ctf_tc->is_translated) { |
| 108 | warn_meaningless_fields(ctf_tc->packet_header_fc, NULL, "packet header", logger); |
| 109 | } |
| 110 | |
| 111 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { |
| 112 | ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; |
| 113 | |
| 114 | if (!sc->is_translated) { |
| 115 | warn_meaningless_fields(sc->event_header_fc, NULL, "event header", logger); |
| 116 | } |
| 117 | } |
| 118 | } |