Cleanup: remove private babeltrace.h
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-warn-meaningless-header-fields.c
CommitLineData
0476f6f7
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
15#define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-WARN-MEANINGLESS-HEADER-FIELDS"
16#include "logging.h"
17
71c5da58 18#include <babeltrace2/babeltrace.h>
85e7137b 19#include "common/macros.h"
57952005 20#include "common/assert.h"
0476f6f7
PP
21#include <glib.h>
22#include <stdint.h>
23#include <string.h>
24#include <inttypes.h>
25
26#include "ctf-meta-visitors.h"
27
28static inline
29void warn_meaningless_field(const char *name, const char *scope_name)
30{
31 BT_LOGW("User field found in %s: ignoring: name=\"%s\"",
32 scope_name, name);
33}
34
35static inline
36void warn_meaningless_fields(struct ctf_field_class *fc, const char *name,
37 const char *scope_name)
38{
39 uint64_t i;
40
41 if (!fc) {
42 goto end;
43 }
44
45 switch (fc->type) {
46 case CTF_FIELD_CLASS_TYPE_FLOAT:
47 case CTF_FIELD_CLASS_TYPE_STRING:
48 warn_meaningless_field(name, scope_name);
49 break;
50 case CTF_FIELD_CLASS_TYPE_INT:
51 case CTF_FIELD_CLASS_TYPE_ENUM:
52 {
53 struct ctf_field_class_int *int_fc = (void *) fc;
54
55 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE &&
56 !int_fc->mapped_clock_class) {
57 warn_meaningless_field(name, scope_name);
58 }
59
60 break;
61 }
62 case CTF_FIELD_CLASS_TYPE_STRUCT:
63 {
64 struct ctf_field_class_struct *struct_fc = (void *) 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(
69 struct_fc, i);
70
71 warn_meaningless_fields(named_fc->fc,
72 named_fc->name->str, scope_name);
73 }
74
75 break;
76 }
77 case CTF_FIELD_CLASS_TYPE_VARIANT:
78 {
79 struct ctf_field_class_variant *var_fc = (void *) fc;
80
81 for (i = 0; i < var_fc->options->len; i++) {
82 struct ctf_named_field_class *named_fc =
83 ctf_field_class_variant_borrow_option_by_index(
84 var_fc, i);
85
86 warn_meaningless_fields(named_fc->fc,
87 named_fc->name->str, scope_name);
88 }
89
90 break;
91 }
92 case CTF_FIELD_CLASS_TYPE_ARRAY:
93 {
94 struct ctf_field_class_array *array_fc = (void *) fc;
95
96 if (array_fc->meaning != CTF_FIELD_CLASS_MEANING_NONE) {
97 goto end;
98 }
99
0476f6f7 100 }
7f7f3101 101 /* fall-through */
0476f6f7
PP
102 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
103 {
104 struct ctf_field_class_array_base *array_fc = (void *) fc;
105
106 warn_meaningless_fields(array_fc->elem_fc, name, scope_name);
107 break;
108 }
109 default:
110 abort();
111 }
112
113end:
114 return;
115}
116
117BT_HIDDEN
118void ctf_trace_class_warn_meaningless_header_fields(
119 struct ctf_trace_class *ctf_tc)
120{
121 uint64_t i;
122
123 if (!ctf_tc->is_translated) {
124 warn_meaningless_fields(
125 ctf_tc->packet_header_fc, NULL, "packet header");
126 }
127
128 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
129 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
130
131 if (!sc->is_translated) {
132 warn_meaningless_fields(sc->event_header_fc, NULL,
133 "event header");
134 }
135 }
136}
This page took 0.032577 seconds and 4 git commands to generate.