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-VALUE-STORING-INDEXES"
18 #include <babeltrace2/babeltrace.h>
19 #include "common/babeltrace.h"
20 #include "common/assert.h"
26 #include "ctf-meta-visitors.h"
29 int update_field_class_stored_value_index(struct ctf_field_class
*fc
,
30 struct ctf_trace_class
*tc
,
31 struct ctf_stream_class
*sc
,
32 struct ctf_event_class
*ec
)
36 struct ctf_field_path
*field_path
= NULL
;
37 struct ctf_field_class_int
*tgt_fc
= NULL
;
38 uint64_t *stored_value_index
= NULL
;
45 case CTF_FIELD_CLASS_TYPE_VARIANT
:
47 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
49 field_path
= &var_fc
->tag_path
;
50 stored_value_index
= &var_fc
->stored_tag_index
;
51 tgt_fc
= (void *) var_fc
->tag_fc
;
54 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
56 struct ctf_field_class_sequence
*seq_fc
= (void *) fc
;
58 field_path
= &seq_fc
->length_path
;
59 stored_value_index
= &seq_fc
->stored_length_index
;
60 tgt_fc
= seq_fc
->length_fc
;
69 BT_ASSERT(tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_INT
||
70 tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_ENUM
);
71 if (tgt_fc
->storing_index
>= 0) {
72 /* Already storing its value */
73 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
75 /* Not storing its value: allocate new index */
76 tgt_fc
->storing_index
= tc
->stored_value_count
;
77 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
78 tc
->stored_value_count
++;
83 case CTF_FIELD_CLASS_TYPE_STRUCT
:
85 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
87 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
88 struct ctf_named_field_class
*named_fc
=
89 ctf_field_class_struct_borrow_member_by_index(
92 ret
= update_field_class_stored_value_index(named_fc
->fc
,
101 case CTF_FIELD_CLASS_TYPE_VARIANT
:
103 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
105 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
106 struct ctf_named_field_class
*named_fc
=
107 ctf_field_class_variant_borrow_option_by_index(
110 ret
= update_field_class_stored_value_index(named_fc
->fc
,
119 case CTF_FIELD_CLASS_TYPE_ARRAY
:
120 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
122 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
124 ret
= update_field_class_stored_value_index(array_fc
->elem_fc
,
141 int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class
*ctf_tc
)
145 if (!ctf_tc
->is_translated
) {
146 update_field_class_stored_value_index(
147 ctf_tc
->packet_header_fc
, ctf_tc
, NULL
, NULL
);
150 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
152 struct ctf_stream_class
*sc
= ctf_tc
->stream_classes
->pdata
[i
];
154 if (!sc
->is_translated
) {
155 update_field_class_stored_value_index(sc
->packet_context_fc
,
157 update_field_class_stored_value_index(sc
->event_header_fc
,
159 update_field_class_stored_value_index(
160 sc
->event_common_context_fc
, ctf_tc
, sc
, NULL
);
163 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
164 struct ctf_event_class
*ec
=
165 sc
->event_classes
->pdata
[j
];
167 if (!ec
->is_translated
) {
168 update_field_class_stored_value_index(
169 ec
->spec_context_fc
, ctf_tc
, sc
, ec
);
170 update_field_class_stored_value_index(
171 ec
->payload_fc
, ctf_tc
, sc
, ec
);