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"
17 static int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
, const char *field_name
,
19 enum ctf_field_class_meaning meaning
)
29 case CTF_FIELD_CLASS_TYPE_INT
:
30 case CTF_FIELD_CLASS_TYPE_ENUM
:
32 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(fc
);
34 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
35 int_fc
->meaning
= meaning
;
40 case CTF_FIELD_CLASS_TYPE_STRUCT
:
42 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
44 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
45 struct ctf_named_field_class
*named_fc
=
46 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
48 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, named_fc
->name
->str
, id_name
,
57 case CTF_FIELD_CLASS_TYPE_VARIANT
:
59 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
61 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
62 struct ctf_named_field_class
*named_fc
=
63 ctf_field_class_variant_borrow_option_by_index(var_fc
, i
);
65 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, NULL
, id_name
, meaning
);
73 case CTF_FIELD_CLASS_TYPE_ARRAY
:
74 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
76 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
78 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
, NULL
, id_name
, meaning
);
93 static int update_stream_class_meanings(struct ctf_stream_class
*sc
)
96 struct ctf_field_class_int
*int_fc
;
99 if (!sc
->is_translated
) {
100 if (sc
->packet_context_fc
) {
101 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
102 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
104 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
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_end");
110 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
113 * Remove mapped clock class to avoid updating
114 * the clock immediately when decoding.
116 int_fc
->mapped_clock_class
= NULL
;
119 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
120 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
122 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
125 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
126 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
128 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_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_size");
134 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
137 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
138 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
140 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
144 if (sc
->event_header_fc
) {
145 ret
= set_int_field_class_meaning_by_name(sc
->event_header_fc
, NULL
, "id",
146 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
153 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
154 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[i
];
156 if (ec
->is_translated
) {
165 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
168 struct ctf_field_class_int
*int_fc
;
169 struct ctf_named_field_class
*named_fc
;
172 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
173 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
174 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
176 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
179 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
180 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
182 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
185 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
186 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
188 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
191 named_fc
= ctf_field_class_struct_borrow_member_by_name(
192 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
193 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
194 struct ctf_field_class_array
*array_fc
= ctf_field_class_as_array(named_fc
->fc
);
196 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
200 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
201 ret
= update_stream_class_meanings((ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
]);