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