| 1 | /* |
| 2 | * Copyright 2018 - Philippe Proulx <pproulx@efficios.com> |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | */ |
| 14 | |
| 15 | #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) |
| 16 | #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) |
| 17 | #define BT_LOG_TAG "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS" |
| 18 | #include "plugins/comp-logging.h" |
| 19 | |
| 20 | #include <babeltrace2/babeltrace.h> |
| 21 | #include "common/macros.h" |
| 22 | #include "common/assert.h" |
| 23 | #include <glib.h> |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
| 26 | #include <inttypes.h> |
| 27 | |
| 28 | #include "ctf-meta-visitors.h" |
| 29 | #include "logging.h" |
| 30 | |
| 31 | static inline |
| 32 | void warn_meaningless_field(const char *name, const char *scope_name, |
| 33 | struct meta_log_config *log_cfg) |
| 34 | { |
| 35 | BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"", |
| 36 | scope_name, name); |
| 37 | } |
| 38 | |
| 39 | static inline |
| 40 | void warn_meaningless_fields(struct ctf_field_class *fc, const char *name, |
| 41 | const char *scope_name, struct meta_log_config *log_cfg) |
| 42 | { |
| 43 | uint64_t i; |
| 44 | |
| 45 | if (!fc) { |
| 46 | goto end; |
| 47 | } |
| 48 | |
| 49 | switch (fc->type) { |
| 50 | case CTF_FIELD_CLASS_TYPE_FLOAT: |
| 51 | case CTF_FIELD_CLASS_TYPE_STRING: |
| 52 | warn_meaningless_field(name, scope_name, log_cfg); |
| 53 | break; |
| 54 | case CTF_FIELD_CLASS_TYPE_INT: |
| 55 | case CTF_FIELD_CLASS_TYPE_ENUM: |
| 56 | { |
| 57 | struct ctf_field_class_int *int_fc = (void *) fc; |
| 58 | |
| 59 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE && |
| 60 | !int_fc->mapped_clock_class) { |
| 61 | warn_meaningless_field(name, scope_name, log_cfg); |
| 62 | } |
| 63 | |
| 64 | break; |
| 65 | } |
| 66 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
| 67 | { |
| 68 | struct ctf_field_class_struct *struct_fc = (void *) fc; |
| 69 | |
| 70 | for (i = 0; i < struct_fc->members->len; i++) { |
| 71 | struct ctf_named_field_class *named_fc = |
| 72 | ctf_field_class_struct_borrow_member_by_index( |
| 73 | struct_fc, i); |
| 74 | |
| 75 | warn_meaningless_fields(named_fc->fc, |
| 76 | named_fc->name->str, scope_name, log_cfg); |
| 77 | } |
| 78 | |
| 79 | break; |
| 80 | } |
| 81 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
| 82 | { |
| 83 | struct ctf_field_class_variant *var_fc = (void *) fc; |
| 84 | |
| 85 | for (i = 0; i < var_fc->options->len; i++) { |
| 86 | struct ctf_named_field_class *named_fc = |
| 87 | ctf_field_class_variant_borrow_option_by_index( |
| 88 | var_fc, i); |
| 89 | |
| 90 | warn_meaningless_fields(named_fc->fc, |
| 91 | named_fc->name->str, scope_name, log_cfg); |
| 92 | } |
| 93 | |
| 94 | break; |
| 95 | } |
| 96 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
| 97 | { |
| 98 | struct ctf_field_class_array *array_fc = (void *) fc; |
| 99 | |
| 100 | if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) { |
| 101 | goto end; |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | /* fall-through */ |
| 106 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: |
| 107 | { |
| 108 | struct ctf_field_class_array_base *array_fc = (void *) fc; |
| 109 | |
| 110 | warn_meaningless_fields(array_fc->elem_fc, name, scope_name, |
| 111 | log_cfg); |
| 112 | break; |
| 113 | } |
| 114 | default: |
| 115 | abort(); |
| 116 | } |
| 117 | |
| 118 | end: |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | BT_HIDDEN |
| 123 | void ctf_trace_class_warn_meaningless_header_fields( |
| 124 | struct ctf_trace_class *ctf_tc, |
| 125 | struct meta_log_config *log_cfg) |
| 126 | { |
| 127 | uint64_t i; |
| 128 | |
| 129 | if (!ctf_tc->is_translated) { |
| 130 | warn_meaningless_fields( |
| 131 | ctf_tc->packet_header_fc, NULL, "packet header", |
| 132 | log_cfg); |
| 133 | } |
| 134 | |
| 135 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { |
| 136 | struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i]; |
| 137 | |
| 138 | if (!sc->is_translated) { |
| 139 | warn_meaningless_fields(sc->event_header_fc, NULL, |
| 140 | "event header", log_cfg); |
| 141 | } |
| 142 | } |
| 143 | } |