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