2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
15 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-MEANINGS"
18 #include <babeltrace/babeltrace.h>
19 #include <babeltrace/babeltrace-internal.h>
20 #include <babeltrace/assert-internal.h>
26 #include "ctf-meta-visitors.h"
29 int set_int_field_type_meaning_by_name(struct ctf_field_type
*ft
,
30 const char *field_name
, const char *id_name
,
31 enum ctf_field_type_meaning meaning
)
41 case CTF_FIELD_TYPE_ID_INT
:
42 case CTF_FIELD_TYPE_ID_ENUM
:
44 struct ctf_field_type_int
*int_ft
= (void *) ft
;
46 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
47 int_ft
->meaning
= meaning
;
52 case CTF_FIELD_TYPE_ID_STRUCT
:
54 struct ctf_field_type_struct
*struct_ft
= (void *) ft
;
56 for (i
= 0; i
< struct_ft
->members
->len
; i
++) {
57 struct ctf_named_field_type
*named_ft
=
58 ctf_field_type_struct_borrow_member_by_index(
61 ret
= set_int_field_type_meaning_by_name(named_ft
->ft
,
62 named_ft
->name
->str
, id_name
, meaning
);
70 case CTF_FIELD_TYPE_ID_VARIANT
:
72 struct ctf_field_type_variant
*var_ft
= (void *) ft
;
74 for (i
= 0; i
< var_ft
->options
->len
; i
++) {
75 struct ctf_named_field_type
*named_ft
=
76 ctf_field_type_variant_borrow_option_by_index(
79 ret
= set_int_field_type_meaning_by_name(named_ft
->ft
,
80 NULL
, id_name
, meaning
);
88 case CTF_FIELD_TYPE_ID_ARRAY
:
89 case CTF_FIELD_TYPE_ID_SEQUENCE
:
91 struct ctf_field_type_array_base
*array_ft
= (void *) ft
;
93 ret
= set_int_field_type_meaning_by_name(array_ft
->elem_ft
,
94 NULL
, id_name
, meaning
);
110 int update_stream_class_meanings(struct ctf_stream_class
*sc
)
113 struct ctf_field_type_int
*int_ft
;
116 if (!sc
->is_translated
) {
117 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
118 (void *) sc
->packet_context_ft
, "timestamp_begin");
120 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_PACKET_BEGINNING_TIME
;
123 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
124 (void *) sc
->packet_context_ft
, "timestamp_end");
126 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_PACKET_END_TIME
;
129 * Remove mapped clock class to avoid updating
130 * the clock immediately when decoding.
132 int_ft
->mapped_clock_class
= NULL
;
135 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
136 (void *) sc
->packet_context_ft
, "events_discarded");
138 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
141 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
142 (void *) sc
->packet_context_ft
, "packet_seq_num");
144 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_PACKET_COUNTER_SNAPSHOT
;
148 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
149 (void *) sc
->packet_context_ft
, "packet_size");
151 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_EXP_PACKET_TOTAL_SIZE
;
154 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
155 (void *) sc
->packet_context_ft
, "content_size");
157 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_EXP_PACKET_CONTENT_SIZE
;
160 ret
= set_int_field_type_meaning_by_name(
161 sc
->event_header_ft
, NULL
, "id",
162 CTF_FIELD_TYPE_MEANING_EVENT_CLASS_ID
);
168 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
169 struct ctf_event_class
*ec
= sc
->event_classes
->pdata
[i
];
171 if (ec
->is_translated
) {
181 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
184 struct ctf_field_type_int
*int_ft
;
185 struct ctf_named_field_type
*named_ft
;
188 if (!ctf_tc
->is_translated
) {
189 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
190 (void *) ctf_tc
->packet_header_ft
, "magic");
192 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_MAGIC
;
195 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
196 (void *) ctf_tc
->packet_header_ft
, "stream_id");
198 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_STREAM_CLASS_ID
;
201 int_ft
= ctf_field_type_struct_borrow_member_int_field_type_by_name(
202 (void *) ctf_tc
->packet_header_ft
,
203 "stream_instance_id");
205 int_ft
->meaning
= CTF_FIELD_TYPE_MEANING_DATA_STREAM_ID
;
208 named_ft
= ctf_field_type_struct_borrow_member_by_name(
209 (void *) ctf_tc
->packet_header_ft
, "uuid");
210 if (named_ft
&& named_ft
->ft
->id
== CTF_FIELD_TYPE_ID_ARRAY
) {
211 struct ctf_field_type_array
*array_ft
=
212 (void *) named_ft
->ft
;
214 array_ft
->meaning
= CTF_FIELD_TYPE_MEANING_UUID
;
218 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
219 ret
= update_stream_class_meanings(
220 ctf_tc
->stream_classes
->pdata
[i
]);