2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
12 #include <babeltrace2/babeltrace.h>
14 #include "common/assert.h"
15 #include "common/macros.h"
17 #include "ctf-meta-visitors.hpp"
19 static int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
, const char *field_name
,
21 enum ctf_field_class_meaning meaning
)
31 case CTF_FIELD_CLASS_TYPE_INT
:
32 case CTF_FIELD_CLASS_TYPE_ENUM
:
34 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(fc
);
36 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
37 int_fc
->meaning
= meaning
;
42 case CTF_FIELD_CLASS_TYPE_STRUCT
:
44 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
46 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
47 struct ctf_named_field_class
*named_fc
=
48 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
50 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, named_fc
->name
->str
, id_name
,
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(var_fc
, i
);
67 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, NULL
, id_name
, meaning
);
75 case CTF_FIELD_CLASS_TYPE_ARRAY
:
76 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
78 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
80 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
, NULL
, id_name
, meaning
);
95 static int update_stream_class_meanings(struct ctf_stream_class
*sc
)
98 struct ctf_field_class_int
*int_fc
;
101 if (!sc
->is_translated
) {
102 if (sc
->packet_context_fc
) {
103 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
104 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
106 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
109 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
110 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
112 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
115 * Remove mapped clock class to avoid updating
116 * the clock immediately when decoding.
118 int_fc
->mapped_clock_class
= NULL
;
121 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
122 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
124 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
127 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
128 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
130 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
;
133 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
134 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
136 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
139 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
140 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
142 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
146 if (sc
->event_header_fc
) {
147 ret
= set_int_field_class_meaning_by_name(sc
->event_header_fc
, NULL
, "id",
148 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
155 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
156 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[i
];
158 if (ec
->is_translated
) {
167 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
170 struct ctf_field_class_int
*int_fc
;
171 struct ctf_named_field_class
*named_fc
;
174 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
175 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
176 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
178 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
181 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
182 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
184 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
187 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
188 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
190 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
193 named_fc
= ctf_field_class_struct_borrow_member_by_name(
194 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
195 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
196 struct ctf_field_class_array
*array_fc
= ctf_field_class_as_array(named_fc
->fc
);
198 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
202 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
203 ret
= update_stream_class_meanings((ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
]);