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 | ||
0f5c5d5c | 7 | #include <babeltrace2/babeltrace.h> |
83ebb7f1 | 8 | |
578e048b | 9 | #include "common/assert.h" |
0f5c5d5c | 10 | #include "cpp-common/bt2c/logging.hpp" |
83ebb7f1 | 11 | |
087cd0f5 | 12 | #include "ctf-meta-visitors.hpp" |
83ebb7f1 | 13 | |
4164020e | 14 | static inline void warn_meaningless_field(const char *name, const char *scope_name, |
0f5c5d5c | 15 | const bt2c::Logger& logger) |
83ebb7f1 | 16 | { |
4164020e | 17 | BT_ASSERT(name); |
0f5c5d5c | 18 | BT_CPPLOGW_SPEC(logger, "User field found in {}: ignoring: name=\"{}\"", scope_name, name); |
83ebb7f1 PP |
19 | } |
20 | ||
4164020e | 21 | static inline void warn_meaningless_fields(struct ctf_field_class *fc, const char *name, |
0f5c5d5c | 22 | const char *scope_name, const bt2c::Logger& logger) |
83ebb7f1 | 23 | { |
4164020e SM |
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: | |
0f5c5d5c | 38 | warn_meaningless_field(name, scope_name, logger); |
4164020e SM |
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) { | |
0f5c5d5c | 46 | warn_meaningless_field(name, scope_name, logger); |
4164020e SM |
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 | ||
0f5c5d5c | 59 | warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); |
4164020e SM |
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 | ||
0f5c5d5c | 72 | warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); |
4164020e SM |
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 | ||
0f5c5d5c | 90 | warn_meaningless_fields(array_fc->elem_fc, name, scope_name, logger); |
4164020e SM |
91 | break; |
92 | } | |
93 | default: | |
94 | bt_common_abort(); | |
95 | } | |
83ebb7f1 PP |
96 | |
97 | end: | |
4164020e | 98 | return; |
83ebb7f1 PP |
99 | } |
100 | ||
4164020e | 101 | void ctf_trace_class_warn_meaningless_header_fields(struct ctf_trace_class *ctf_tc, |
0f5c5d5c | 102 | const bt2c::Logger& parentLogger) |
83ebb7f1 | 103 | { |
4164020e | 104 | uint64_t i; |
0f5c5d5c | 105 | bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"}; |
4164020e SM |
106 | |
107 | if (!ctf_tc->is_translated) { | |
0f5c5d5c | 108 | warn_meaningless_fields(ctf_tc->packet_header_fc, NULL, "packet header", logger); |
4164020e SM |
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) { | |
0f5c5d5c | 115 | warn_meaningless_fields(sc->event_header_fc, NULL, "event header", logger); |
4164020e SM |
116 | } |
117 | } | |
83ebb7f1 | 118 | } |