2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #include <babeltrace2/babeltrace.h>
8 #include "common/macros.h"
9 #include "common/assert.h"
15 #include "ctf-meta-visitors.hpp"
18 int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
,
19 const char *field_name
, const char *id_name
,
20 enum ctf_field_class_meaning meaning
)
30 case CTF_FIELD_CLASS_TYPE_INT
:
31 case CTF_FIELD_CLASS_TYPE_ENUM
:
33 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(fc
);
35 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
36 int_fc
->meaning
= meaning
;
41 case CTF_FIELD_CLASS_TYPE_STRUCT
:
43 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
45 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
46 struct ctf_named_field_class
*named_fc
=
47 ctf_field_class_struct_borrow_member_by_index(
50 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
51 named_fc
->name
->str
, id_name
, meaning
);
59 case CTF_FIELD_CLASS_TYPE_VARIANT
:
61 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
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(
68 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
69 NULL
, id_name
, meaning
);
77 case CTF_FIELD_CLASS_TYPE_ARRAY
:
78 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
80 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
82 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
,
83 NULL
, id_name
, meaning
);
99 int update_stream_class_meanings(struct ctf_stream_class
*sc
)
102 struct ctf_field_class_int
*int_fc
;
105 if (!sc
->is_translated
) {
106 if (sc
->packet_context_fc
) {
107 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
108 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
110 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
113 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
114 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
116 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
119 * Remove mapped clock class to avoid updating
120 * the clock immediately when decoding.
122 int_fc
->mapped_clock_class
= NULL
;
125 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
126 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
128 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
131 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
132 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
134 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
;
138 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
139 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
141 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
144 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
145 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
147 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
151 if (sc
->event_header_fc
) {
152 ret
= set_int_field_class_meaning_by_name(
153 sc
->event_header_fc
, NULL
, "id",
154 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
161 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
162 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[i
];
164 if (ec
->is_translated
) {
174 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
177 struct ctf_field_class_int
*int_fc
;
178 struct ctf_named_field_class
*named_fc
;
181 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
182 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
183 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
185 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
188 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
189 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
191 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
194 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
195 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
),
196 "stream_instance_id");
198 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
201 named_fc
= ctf_field_class_struct_borrow_member_by_name(
202 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
203 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
204 struct ctf_field_class_array
*array_fc
=
205 ctf_field_class_as_array(named_fc
->fc
);
207 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
211 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
212 ret
= update_stream_class_meanings(
213 (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
]);