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