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