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