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