Fix: src.ctf.fs: initialize the other_entry variable
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-warn-meaningless-header-fields.c
CommitLineData
83ebb7f1
PP
1/*
2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 */
14
f7b785ac
PP
15#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
16#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
350ad6c1 17#define BT_LOG_TAG "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"
d9c39b0a 18#include "logging/comp-logging.h"
83ebb7f1 19
3fadfbc0 20#include <babeltrace2/babeltrace.h>
91d81473 21#include "common/macros.h"
578e048b 22#include "common/assert.h"
83ebb7f1
PP
23#include <glib.h>
24#include <stdint.h>
25#include <string.h>
26#include <inttypes.h>
27
28#include "ctf-meta-visitors.h"
f7b785ac 29#include "logging.h"
83ebb7f1
PP
30
31static inline
0746848c 32void warn_meaningless_field(const char *name, const char *scope_name,
f7b785ac 33 struct meta_log_config *log_cfg)
83ebb7f1 34{
74ad166b 35 BT_ASSERT(name);
f7b785ac 36 BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"",
83ebb7f1
PP
37 scope_name, name);
38}
39
40static inline
41void warn_meaningless_fields(struct ctf_field_class *fc, const char *name,
f7b785ac 42 const char *scope_name, struct meta_log_config *log_cfg)
83ebb7f1
PP
43{
44 uint64_t i;
45
46 if (!fc) {
47 goto end;
48 }
49
74ad166b
JG
50 /*
51 * 'name' is guaranteed to be non-NULL whenever the field class is not a
52 * structure. In the case of a structure field class, its members' names
53 * are used.
54 */
83ebb7f1
PP
55 switch (fc->type) {
56 case CTF_FIELD_CLASS_TYPE_FLOAT:
57 case CTF_FIELD_CLASS_TYPE_STRING:
f7b785ac 58 warn_meaningless_field(name, scope_name, log_cfg);
83ebb7f1
PP
59 break;
60 case CTF_FIELD_CLASS_TYPE_INT:
61 case CTF_FIELD_CLASS_TYPE_ENUM:
62 {
63 struct ctf_field_class_int *int_fc = (void *) fc;
64
65 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE &&
66 !int_fc->mapped_clock_class) {
f7b785ac 67 warn_meaningless_field(name, scope_name, log_cfg);
83ebb7f1
PP
68 }
69
70 break;
71 }
72 case CTF_FIELD_CLASS_TYPE_STRUCT:
73 {
74 struct ctf_field_class_struct *struct_fc = (void *) fc;
75
76 for (i = 0; i < struct_fc->members->len; i++) {
77 struct ctf_named_field_class *named_fc =
78 ctf_field_class_struct_borrow_member_by_index(
79 struct_fc, i);
80
81 warn_meaningless_fields(named_fc->fc,
f7b785ac 82 named_fc->name->str, scope_name, log_cfg);
83ebb7f1
PP
83 }
84
85 break;
86 }
87 case CTF_FIELD_CLASS_TYPE_VARIANT:
88 {
89 struct ctf_field_class_variant *var_fc = (void *) fc;
90
91 for (i = 0; i < var_fc->options->len; i++) {
92 struct ctf_named_field_class *named_fc =
93 ctf_field_class_variant_borrow_option_by_index(
94 var_fc, i);
95
96 warn_meaningless_fields(named_fc->fc,
f7b785ac 97 named_fc->name->str, scope_name, log_cfg);
83ebb7f1
PP
98 }
99
100 break;
101 }
102 case CTF_FIELD_CLASS_TYPE_ARRAY:
103 {
104 struct ctf_field_class_array *array_fc = (void *) fc;
105
106 if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) {
107 goto end;
108 }
109
83ebb7f1 110 }
2f69c7e7 111 /* fall-through */
83ebb7f1
PP
112 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
113 {
114 struct ctf_field_class_array_base *array_fc = (void *) fc;
115
0746848c 116 warn_meaningless_fields(array_fc->elem_fc, name, scope_name,
f7b785ac 117 log_cfg);
83ebb7f1
PP
118 break;
119 }
120 default:
498e7994 121 bt_common_abort();
83ebb7f1
PP
122 }
123
124end:
125 return;
126}
127
128BT_HIDDEN
129void ctf_trace_class_warn_meaningless_header_fields(
0746848c 130 struct ctf_trace_class *ctf_tc,
f7b785ac 131 struct meta_log_config *log_cfg)
83ebb7f1
PP
132{
133 uint64_t i;
134
135 if (!ctf_tc->is_translated) {
136 warn_meaningless_fields(
0746848c 137 ctf_tc->packet_header_fc, NULL, "packet header",
f7b785ac 138 log_cfg);
83ebb7f1
PP
139 }
140
141 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
142 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
143
144 if (!sc->is_translated) {
145 warn_meaningless_fields(sc->event_header_fc, NULL,
f7b785ac 146 "event header", log_cfg);
83ebb7f1
PP
147 }
148 }
149}
This page took 0.061078 seconds and 4 git commands to generate.