03daddf96a2d1928a21e6568999f5d31be82e1a2
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-warn-meaningless-header-fields.cpp
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
24 void warn_meaningless_field(const char *name, const char *scope_name,
25 struct meta_log_config *log_cfg)
26 {
27 BT_ASSERT(name);
28 BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"",
29 scope_name, name);
30 }
31
32 static inline
33 void warn_meaningless_fields(struct ctf_field_class *fc, const char *name,
34 const char *scope_name, struct meta_log_config *log_cfg)
35 {
36 uint64_t i;
37
38 if (!fc) {
39 goto end;
40 }
41
42 /*
43 * 'name' is guaranteed to be non-NULL whenever the field class is not a
44 * structure. In the case of a structure field class, its members' names
45 * are used.
46 */
47 switch (fc->type) {
48 case CTF_FIELD_CLASS_TYPE_FLOAT:
49 case CTF_FIELD_CLASS_TYPE_STRING:
50 warn_meaningless_field(name, scope_name, log_cfg);
51 break;
52 case CTF_FIELD_CLASS_TYPE_INT:
53 case CTF_FIELD_CLASS_TYPE_ENUM:
54 {
55 struct ctf_field_class_int *int_fc = ctf_field_class_as_int(fc);
56
57 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE &&
58 !int_fc->mapped_clock_class) {
59 warn_meaningless_field(name, scope_name, log_cfg);
60 }
61
62 break;
63 }
64 case CTF_FIELD_CLASS_TYPE_STRUCT:
65 {
66 struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc);
67
68 for (i = 0; i < struct_fc->members->len; i++) {
69 struct ctf_named_field_class *named_fc =
70 ctf_field_class_struct_borrow_member_by_index(
71 struct_fc, i);
72
73 warn_meaningless_fields(named_fc->fc,
74 named_fc->name->str, scope_name, log_cfg);
75 }
76
77 break;
78 }
79 case CTF_FIELD_CLASS_TYPE_VARIANT:
80 {
81 struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc);
82
83 for (i = 0; i < var_fc->options->len; i++) {
84 struct ctf_named_field_class *named_fc =
85 ctf_field_class_variant_borrow_option_by_index(
86 var_fc, i);
87
88 warn_meaningless_fields(named_fc->fc,
89 named_fc->name->str, scope_name, log_cfg);
90 }
91
92 break;
93 }
94 case CTF_FIELD_CLASS_TYPE_ARRAY:
95 {
96 struct ctf_field_class_array *array_fc = ctf_field_class_as_array(fc);
97
98 if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) {
99 goto end;
100 }
101
102 }
103 /* fall-through */
104 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
105 {
106 struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc);
107
108 warn_meaningless_fields(array_fc->elem_fc, name, scope_name,
109 log_cfg);
110 break;
111 }
112 default:
113 bt_common_abort();
114 }
115
116 end:
117 return;
118 }
119
120 BT_HIDDEN
121 void ctf_trace_class_warn_meaningless_header_fields(
122 struct ctf_trace_class *ctf_tc,
123 struct meta_log_config *log_cfg)
124 {
125 uint64_t i;
126
127 if (!ctf_tc->is_translated) {
128 warn_meaningless_fields(
129 ctf_tc->packet_header_fc, NULL, "packet header",
130 log_cfg);
131 }
132
133 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
134 ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i];
135
136 if (!sc->is_translated) {
137 warn_meaningless_fields(sc->event_header_fc, NULL,
138 "event header", log_cfg);
139 }
140 }
141 }
This page took 0.030701 seconds and 3 git commands to generate.