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