a9b1f1735d06fed6a82b6b5ff1d40007b3f60d03
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-meanings.c
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 #include <babeltrace2/babeltrace.h>
16 #include "common/macros.h"
17 #include "common/assert.h"
18 #include <glib.h>
19 #include <stdint.h>
20 #include <string.h>
21 #include <inttypes.h>
22
23 #include "ctf-meta-visitors.h"
24
25 static
26 int set_int_field_class_meaning_by_name(struct ctf_field_class *fc,
27 const char *field_name, const char *id_name,
28 enum ctf_field_class_meaning meaning)
29 {
30 int ret = 0;
31 uint64_t i;
32
33 if (!fc) {
34 goto end;
35 }
36
37 switch (fc->type) {
38 case CTF_FIELD_CLASS_TYPE_INT:
39 case CTF_FIELD_CLASS_TYPE_ENUM:
40 {
41 struct ctf_field_class_int *int_fc = (void *) fc;
42
43 if (field_name && strcmp(field_name, id_name) == 0) {
44 int_fc->meaning = meaning;
45 }
46
47 break;
48 }
49 case CTF_FIELD_CLASS_TYPE_STRUCT:
50 {
51 struct ctf_field_class_struct *struct_fc = (void *) fc;
52
53 for (i = 0; i < struct_fc->members->len; i++) {
54 struct ctf_named_field_class *named_fc =
55 ctf_field_class_struct_borrow_member_by_index(
56 struct_fc, i);
57
58 ret = set_int_field_class_meaning_by_name(named_fc->fc,
59 named_fc->name->str, id_name, meaning);
60 if (ret) {
61 goto end;
62 }
63 }
64
65 break;
66 }
67 case CTF_FIELD_CLASS_TYPE_VARIANT:
68 {
69 struct ctf_field_class_variant *var_fc = (void *) fc;
70
71 for (i = 0; i < var_fc->options->len; i++) {
72 struct ctf_named_field_class *named_fc =
73 ctf_field_class_variant_borrow_option_by_index(
74 var_fc, i);
75
76 ret = set_int_field_class_meaning_by_name(named_fc->fc,
77 NULL, id_name, meaning);
78 if (ret) {
79 goto end;
80 }
81 }
82
83 break;
84 }
85 case CTF_FIELD_CLASS_TYPE_ARRAY:
86 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
87 {
88 struct ctf_field_class_array_base *array_fc = (void *) fc;
89
90 ret = set_int_field_class_meaning_by_name(array_fc->elem_fc,
91 NULL, id_name, meaning);
92 if (ret) {
93 goto end;
94 }
95
96 break;
97 }
98 default:
99 break;
100 }
101
102 end:
103 return ret;
104 }
105
106 static
107 int update_stream_class_meanings(struct ctf_stream_class *sc)
108 {
109 int ret = 0;
110 struct ctf_field_class_int *int_fc;
111 uint64_t i;
112
113 if (!sc->is_translated) {
114 if (sc->packet_context_fc) {
115 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
116 (void *) sc->packet_context_fc, "timestamp_begin");
117 if (int_fc) {
118 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME;
119 }
120
121 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
122 (void *) sc->packet_context_fc, "timestamp_end");
123 if (int_fc) {
124 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_END_TIME;
125
126 /*
127 * Remove mapped clock class to avoid updating
128 * the clock immediately when decoding.
129 */
130 int_fc->mapped_clock_class = NULL;
131 }
132
133 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
134 (void *) sc->packet_context_fc, "events_discarded");
135 if (int_fc) {
136 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT;
137 }
138
139 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
140 (void *) sc->packet_context_fc, "packet_seq_num");
141 if (int_fc) {
142 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT;
143
144 }
145
146 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
147 (void *) sc->packet_context_fc, "packet_size");
148 if (int_fc) {
149 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE;
150 }
151
152 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
153 (void *) sc->packet_context_fc, "content_size");
154 if (int_fc) {
155 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE;
156 }
157 }
158
159 if (sc->event_header_fc) {
160 ret = set_int_field_class_meaning_by_name(
161 sc->event_header_fc, NULL, "id",
162 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID);
163 if (ret) {
164 goto end;
165 }
166 }
167 }
168
169 for (i = 0; i < sc->event_classes->len; i++) {
170 struct ctf_event_class *ec = sc->event_classes->pdata[i];
171
172 if (ec->is_translated) {
173 continue;
174 }
175 }
176
177 end:
178 return ret;
179 }
180
181 BT_HIDDEN
182 int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc)
183 {
184 int ret = 0;
185 struct ctf_field_class_int *int_fc;
186 struct ctf_named_field_class *named_fc;
187 uint64_t i;
188
189 if (!ctf_tc->is_translated && ctf_tc->packet_header_fc) {
190 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
191 (void *) ctf_tc->packet_header_fc, "magic");
192 if (int_fc) {
193 int_fc->meaning = CTF_FIELD_CLASS_MEANING_MAGIC;
194 }
195
196 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
197 (void *) ctf_tc->packet_header_fc, "stream_id");
198 if (int_fc) {
199 int_fc->meaning = CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID;
200 }
201
202 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
203 (void *) ctf_tc->packet_header_fc,
204 "stream_instance_id");
205 if (int_fc) {
206 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID;
207 }
208
209 named_fc = ctf_field_class_struct_borrow_member_by_name(
210 (void *) ctf_tc->packet_header_fc, "uuid");
211 if (named_fc && named_fc->fc->type == CTF_FIELD_CLASS_TYPE_ARRAY) {
212 struct ctf_field_class_array *array_fc =
213 (void *) named_fc->fc;
214
215 array_fc->meaning = CTF_FIELD_CLASS_MEANING_UUID;
216 }
217 }
218
219 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
220 ret = update_stream_class_meanings(
221 ctf_tc->stream_classes->pdata[i]);
222 if (ret) {
223 goto end;
224 }
225 }
226
227 end:
228 return ret;
229 }
This page took 0.033429 seconds and 3 git commands to generate.