`ctf` plugin: `bt_msg_iter`: use BT_COMP_LOG*() instead of BT_LOG*()
[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
0746848c 15#define BT_LOG_OUTPUT_LEVEL log_level
350ad6c1 16#define BT_LOG_TAG "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"
0746848c 17#include "logging/log.h"
83ebb7f1 18
3fadfbc0 19#include <babeltrace2/babeltrace.h>
91d81473 20#include "common/macros.h"
578e048b 21#include "common/assert.h"
83ebb7f1
PP
22#include <glib.h>
23#include <stdint.h>
24#include <string.h>
25#include <inttypes.h>
26
27#include "ctf-meta-visitors.h"
28
29static inline
0746848c
PP
30void warn_meaningless_field(const char *name, const char *scope_name,
31 bt_logging_level log_level)
83ebb7f1
PP
32{
33 BT_LOGW("User field found in %s: ignoring: name=\"%s\"",
34 scope_name, name);
35}
36
37static inline
38void warn_meaningless_fields(struct ctf_field_class *fc, const char *name,
0746848c 39 const char *scope_name, bt_logging_level log_level)
83ebb7f1
PP
40{
41 uint64_t i;
42
43 if (!fc) {
44 goto end;
45 }
46
47 switch (fc->type) {
48 case CTF_FIELD_CLASS_TYPE_FLOAT:
49 case CTF_FIELD_CLASS_TYPE_STRING:
0746848c 50 warn_meaningless_field(name, scope_name, log_level);
83ebb7f1
PP
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 = (void *) fc;
56
57 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE &&
58 !int_fc->mapped_clock_class) {
0746848c 59 warn_meaningless_field(name, scope_name, log_level);
83ebb7f1
PP
60 }
61
62 break;
63 }
64 case CTF_FIELD_CLASS_TYPE_STRUCT:
65 {
66 struct ctf_field_class_struct *struct_fc = (void *) 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,
0746848c 74 named_fc->name->str, scope_name, log_level);
83ebb7f1
PP
75 }
76
77 break;
78 }
79 case CTF_FIELD_CLASS_TYPE_VARIANT:
80 {
81 struct ctf_field_class_variant *var_fc = (void *) 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,
0746848c 89 named_fc->name->str, scope_name, log_level);
83ebb7f1
PP
90 }
91
92 break;
93 }
94 case CTF_FIELD_CLASS_TYPE_ARRAY:
95 {
96 struct ctf_field_class_array *array_fc = (void *) fc;
97
98 if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) {
99 goto end;
100 }
101
83ebb7f1 102 }
2f69c7e7 103 /* fall-through */
83ebb7f1
PP
104 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
105 {
106 struct ctf_field_class_array_base *array_fc = (void *) fc;
107
0746848c
PP
108 warn_meaningless_fields(array_fc->elem_fc, name, scope_name,
109 log_level);
83ebb7f1
PP
110 break;
111 }
112 default:
113 abort();
114 }
115
116end:
117 return;
118}
119
120BT_HIDDEN
121void ctf_trace_class_warn_meaningless_header_fields(
0746848c
PP
122 struct ctf_trace_class *ctf_tc,
123 bt_logging_level log_level)
83ebb7f1
PP
124{
125 uint64_t i;
126
127 if (!ctf_tc->is_translated) {
128 warn_meaningless_fields(
0746848c
PP
129 ctf_tc->packet_header_fc, NULL, "packet header",
130 log_level);
83ebb7f1
PP
131 }
132
133 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
134 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
135
136 if (!sc->is_translated) {
137 warn_meaningless_fields(sc->event_header_fc, NULL,
0746848c 138 "event header", log_level);
83ebb7f1
PP
139 }
140 }
141}
This page took 0.034759 seconds and 4 git commands to generate.