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 | ||
15 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-MEANINGS" | |
16 | #include "logging.h" | |
17 | ||
18 | #include <babeltrace/babeltrace.h> | |
19 | #include <babeltrace/babeltrace-internal.h> | |
20 | #include <babeltrace/assert-internal.h> | |
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) { | |
5cd6d0e5 PP |
117 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
118 | (void *) sc->packet_context_fc, "timestamp_begin"); | |
119 | if (int_fc) { | |
120 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME; | |
44c440bc PP |
121 | } |
122 | ||
5cd6d0e5 PP |
123 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
124 | (void *) sc->packet_context_fc, "timestamp_end"); | |
125 | if (int_fc) { | |
126 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_END_TIME; | |
44c440bc PP |
127 | |
128 | /* | |
129 | * Remove mapped clock class to avoid updating | |
130 | * the clock immediately when decoding. | |
131 | */ | |
5cd6d0e5 | 132 | int_fc->mapped_clock_class = NULL; |
44c440bc PP |
133 | } |
134 | ||
5cd6d0e5 PP |
135 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
136 | (void *) sc->packet_context_fc, "events_discarded"); | |
137 | if (int_fc) { | |
138 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT; | |
44c440bc PP |
139 | } |
140 | ||
5cd6d0e5 PP |
141 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
142 | (void *) sc->packet_context_fc, "packet_seq_num"); | |
143 | if (int_fc) { | |
144 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT; | |
44c440bc PP |
145 | |
146 | } | |
147 | ||
5cd6d0e5 PP |
148 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
149 | (void *) sc->packet_context_fc, "packet_size"); | |
150 | if (int_fc) { | |
151 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE; | |
44c440bc PP |
152 | } |
153 | ||
5cd6d0e5 PP |
154 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
155 | (void *) sc->packet_context_fc, "content_size"); | |
156 | if (int_fc) { | |
157 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE; | |
44c440bc PP |
158 | } |
159 | ||
5cd6d0e5 PP |
160 | ret = set_int_field_class_meaning_by_name( |
161 | sc->event_header_fc, NULL, "id", | |
162 | CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID); | |
44c440bc PP |
163 | if (ret) { |
164 | goto end; | |
165 | } | |
166 | } | |
167 | ||
168 | for (i = 0; i < sc->event_classes->len; i++) { | |
169 | struct ctf_event_class *ec = sc->event_classes->pdata[i]; | |
170 | ||
171 | if (ec->is_translated) { | |
172 | continue; | |
173 | } | |
174 | } | |
175 | ||
176 | end: | |
177 | return ret; | |
178 | } | |
179 | ||
180 | BT_HIDDEN | |
181 | int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc) | |
182 | { | |
183 | int ret = 0; | |
5cd6d0e5 PP |
184 | struct ctf_field_class_int *int_fc; |
185 | struct ctf_named_field_class *named_fc; | |
44c440bc PP |
186 | uint64_t i; |
187 | ||
188 | if (!ctf_tc->is_translated) { | |
5cd6d0e5 PP |
189 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
190 | (void *) ctf_tc->packet_header_fc, "magic"); | |
191 | if (int_fc) { | |
192 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_MAGIC; | |
44c440bc PP |
193 | } |
194 | ||
5cd6d0e5 PP |
195 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
196 | (void *) ctf_tc->packet_header_fc, "stream_id"); | |
197 | if (int_fc) { | |
198 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID; | |
44c440bc PP |
199 | } |
200 | ||
5cd6d0e5 PP |
201 | int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name( |
202 | (void *) ctf_tc->packet_header_fc, | |
44c440bc | 203 | "stream_instance_id"); |
5cd6d0e5 PP |
204 | if (int_fc) { |
205 | int_fc->meaning = CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID; | |
44c440bc PP |
206 | } |
207 | ||
5cd6d0e5 PP |
208 | named_fc = ctf_field_class_struct_borrow_member_by_name( |
209 | (void *) ctf_tc->packet_header_fc, "uuid"); | |
864cad70 | 210 | if (named_fc && named_fc->fc->type == CTF_FIELD_CLASS_TYPE_ARRAY) { |
5cd6d0e5 PP |
211 | struct ctf_field_class_array *array_fc = |
212 | (void *) named_fc->fc; | |
44c440bc | 213 | |
5cd6d0e5 | 214 | array_fc->meaning = CTF_FIELD_CLASS_MEANING_UUID; |
44c440bc PP |
215 | } |
216 | } | |
217 | ||
218 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
219 | ret = update_stream_class_meanings( | |
220 | ctf_tc->stream_classes->pdata[i]); | |
221 | if (ret) { | |
222 | goto end; | |
223 | } | |
224 | } | |
225 | ||
226 | end: | |
227 | return ret; | |
228 | } |