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 <babeltrace2/babeltrace.h>
19 #include <babeltrace2/babeltrace-internal.h>
20 #include <babeltrace2/assert-internal.h>
26 #include "ctf-meta-visitors.h"
29 int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
,
30 const char *field_name
, const char *id_name
,
31 enum ctf_field_class_meaning meaning
)
41 case CTF_FIELD_CLASS_TYPE_INT
:
42 case CTF_FIELD_CLASS_TYPE_ENUM
:
44 struct ctf_field_class_int
*int_fc
= (void *) fc
;
46 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
47 int_fc
->meaning
= meaning
;
52 case CTF_FIELD_CLASS_TYPE_STRUCT
:
54 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
56 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
57 struct ctf_named_field_class
*named_fc
=
58 ctf_field_class_struct_borrow_member_by_index(
61 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
62 named_fc
->name
->str
, id_name
, meaning
);
70 case CTF_FIELD_CLASS_TYPE_VARIANT
:
72 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
74 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
75 struct ctf_named_field_class
*named_fc
=
76 ctf_field_class_variant_borrow_option_by_index(
79 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
80 NULL
, id_name
, meaning
);
88 case CTF_FIELD_CLASS_TYPE_ARRAY
:
89 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
91 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
93 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
,
94 NULL
, id_name
, meaning
);
110 int update_stream_class_meanings(struct ctf_stream_class
*sc
)
113 struct ctf_field_class_int
*int_fc
;
116 if (!sc
->is_translated
) {
117 if (sc
->packet_context_fc
) {
118 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
119 (void *) sc
->packet_context_fc
, "timestamp_begin");
121 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
124 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
125 (void *) sc
->packet_context_fc
, "timestamp_end");
127 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
130 * Remove mapped clock class to avoid updating
131 * the clock immediately when decoding.
133 int_fc
->mapped_clock_class
= NULL
;
136 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
137 (void *) sc
->packet_context_fc
, "events_discarded");
139 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
142 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
143 (void *) sc
->packet_context_fc
, "packet_seq_num");
145 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
;
149 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
150 (void *) sc
->packet_context_fc
, "packet_size");
152 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
155 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
156 (void *) sc
->packet_context_fc
, "content_size");
158 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
162 if (sc
->event_header_fc
) {
163 ret
= set_int_field_class_meaning_by_name(
164 sc
->event_header_fc
, NULL
, "id",
165 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
172 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
173 struct ctf_event_class
*ec
= sc
->event_classes
->pdata
[i
];
175 if (ec
->is_translated
) {
185 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
188 struct ctf_field_class_int
*int_fc
;
189 struct ctf_named_field_class
*named_fc
;
192 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
193 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
194 (void *) ctf_tc
->packet_header_fc
, "magic");
196 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
199 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
200 (void *) ctf_tc
->packet_header_fc
, "stream_id");
202 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
205 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
206 (void *) ctf_tc
->packet_header_fc
,
207 "stream_instance_id");
209 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
212 named_fc
= ctf_field_class_struct_borrow_member_by_name(
213 (void *) ctf_tc
->packet_header_fc
, "uuid");
214 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
215 struct ctf_field_class_array
*array_fc
=
216 (void *) named_fc
->fc
;
218 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
222 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
223 ret
= update_stream_class_meanings(
224 ctf_tc
->stream_classes
->pdata
[i
]);