Sort includes in C++ files
[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 #include <glib.h>
8 #include <inttypes.h>
9 #include <stdint.h>
10 #include <string.h>
11
12 #include <babeltrace2/babeltrace.h>
13
14 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
15 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
16 #define BT_LOG_TAG "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"
17 #include "logging.hpp"
18 #include "logging/comp-logging.h"
19
20 #include "common/assert.h"
21 #include "common/macros.h"
22
23 #include "ctf-meta-visitors.hpp"
24
25 static inline void warn_meaningless_field(const char *name, const char *scope_name,
26 struct meta_log_config *log_cfg)
27 {
28 BT_ASSERT(name);
29 BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"", scope_name, name);
30 }
31
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)
34 {
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 }
107
108 end:
109 return;
110 }
111
112 void ctf_trace_class_warn_meaningless_header_fields(struct ctf_trace_class *ctf_tc,
113 struct meta_log_config *log_cfg)
114 {
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 }
128 }
This page took 0.032113 seconds and 4 git commands to generate.