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