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