Commit | Line | Data |
---|---|---|
44c440bc PP |
1 | /* |
2 | * Copyright 2018 - Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | */ | |
14 | ||
15 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-VALUE-STORING-INDEXES" | |
16 | #include "logging.h" | |
17 | ||
18 | #include <babeltrace/babeltrace.h> | |
19 | #include <babeltrace/babeltrace-internal.h> | |
20 | #include <babeltrace/assert-internal.h> | |
21 | #include <glib.h> | |
22 | #include <stdint.h> | |
23 | #include <string.h> | |
24 | #include <inttypes.h> | |
25 | ||
26 | #include "ctf-meta-visitors.h" | |
27 | ||
28 | static | |
29 | int update_field_type_stored_value_index(struct ctf_field_type *ft, | |
30 | struct ctf_trace_class *tc, | |
31 | struct ctf_stream_class *sc, | |
32 | struct ctf_event_class *ec) | |
33 | { | |
34 | int ret = 0; | |
35 | uint64_t i; | |
36 | struct ctf_field_path *field_path = NULL; | |
37 | struct ctf_field_type_int *tgt_ft = NULL; | |
38 | uint64_t *stored_value_index = NULL; | |
39 | ||
40 | if (!ft) { | |
41 | goto end; | |
42 | } | |
43 | ||
44 | switch (ft->id) { | |
45 | case CTF_FIELD_TYPE_ID_VARIANT: | |
46 | { | |
47 | struct ctf_field_type_variant *var_ft = (void *) ft; | |
48 | ||
49 | field_path = &var_ft->tag_path; | |
50 | stored_value_index = &var_ft->stored_tag_index; | |
51 | tgt_ft = (void *) var_ft->tag_ft; | |
52 | break; | |
53 | } | |
54 | case CTF_FIELD_TYPE_ID_SEQUENCE: | |
55 | { | |
56 | struct ctf_field_type_sequence *seq_ft = (void *) ft; | |
57 | ||
58 | field_path = &seq_ft->length_path; | |
59 | stored_value_index = &seq_ft->stored_length_index; | |
60 | tgt_ft = seq_ft->length_ft; | |
61 | break; | |
62 | } | |
63 | default: | |
64 | break; | |
65 | } | |
66 | ||
67 | if (field_path) { | |
68 | BT_ASSERT(tgt_ft); | |
69 | BT_ASSERT(tgt_ft->base.base.id == CTF_FIELD_TYPE_ID_INT || | |
70 | tgt_ft->base.base.id == CTF_FIELD_TYPE_ID_ENUM); | |
71 | if (tgt_ft->storing_index >= 0) { | |
72 | /* Already storing its value */ | |
73 | *stored_value_index = (uint64_t) tgt_ft->storing_index; | |
74 | } else { | |
75 | /* Not storing its value: allocate new index */ | |
76 | tgt_ft->storing_index = tc->stored_value_count; | |
77 | *stored_value_index = (uint64_t) tgt_ft->storing_index; | |
78 | tc->stored_value_count++; | |
79 | } | |
80 | } | |
81 | ||
82 | switch (ft->id) { | |
83 | case CTF_FIELD_TYPE_ID_STRUCT: | |
84 | { | |
85 | struct ctf_field_type_struct *struct_ft = (void *) ft; | |
86 | ||
87 | for (i = 0; i < struct_ft->members->len; i++) { | |
88 | struct ctf_named_field_type *named_ft = | |
89 | ctf_field_type_struct_borrow_member_by_index( | |
90 | struct_ft, i); | |
91 | ||
92 | ret = update_field_type_stored_value_index(named_ft->ft, | |
93 | tc, sc, ec); | |
94 | if (ret) { | |
95 | goto end; | |
96 | } | |
97 | } | |
98 | ||
99 | break; | |
100 | } | |
101 | case CTF_FIELD_TYPE_ID_VARIANT: | |
102 | { | |
103 | struct ctf_field_type_variant *var_ft = (void *) ft; | |
104 | ||
105 | for (i = 0; i < var_ft->options->len; i++) { | |
106 | struct ctf_named_field_type *named_ft = | |
107 | ctf_field_type_variant_borrow_option_by_index( | |
108 | var_ft, i); | |
109 | ||
110 | ret = update_field_type_stored_value_index(named_ft->ft, | |
111 | tc, sc, ec); | |
112 | if (ret) { | |
113 | goto end; | |
114 | } | |
115 | } | |
116 | ||
117 | break; | |
118 | } | |
119 | case CTF_FIELD_TYPE_ID_ARRAY: | |
120 | case CTF_FIELD_TYPE_ID_SEQUENCE: | |
121 | { | |
122 | struct ctf_field_type_array_base *array_ft = (void *) ft; | |
123 | ||
124 | ret = update_field_type_stored_value_index(array_ft->elem_ft, | |
125 | tc, sc, ec); | |
126 | if (ret) { | |
127 | goto end; | |
128 | } | |
129 | ||
130 | break; | |
131 | } | |
132 | default: | |
133 | break; | |
134 | } | |
135 | ||
136 | end: | |
137 | return ret; | |
138 | } | |
139 | ||
140 | BT_HIDDEN | |
141 | int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class *ctf_tc) | |
142 | { | |
143 | uint64_t i; | |
144 | ||
145 | if (!ctf_tc->is_translated) { | |
146 | update_field_type_stored_value_index( | |
147 | ctf_tc->packet_header_ft, ctf_tc, NULL, NULL); | |
148 | } | |
149 | ||
150 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
151 | uint64_t j; | |
152 | struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i]; | |
153 | ||
154 | if (!sc->is_translated) { | |
155 | update_field_type_stored_value_index(sc->packet_context_ft, | |
156 | ctf_tc, sc, NULL); | |
157 | update_field_type_stored_value_index(sc->event_header_ft, | |
158 | ctf_tc, sc, NULL); | |
159 | update_field_type_stored_value_index( | |
160 | sc->event_common_context_ft, ctf_tc, sc, NULL); | |
161 | } | |
162 | ||
163 | for (j = 0; j < sc->event_classes->len; j++) { | |
164 | struct ctf_event_class *ec = | |
165 | sc->event_classes->pdata[j]; | |
166 | ||
167 | if (!ec->is_translated) { | |
168 | update_field_type_stored_value_index( | |
169 | ec->spec_context_ft, ctf_tc, sc, ec); | |
170 | update_field_type_stored_value_index( | |
171 | ec->payload_ft, ctf_tc, sc, ec); | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
176 | return 0; | |
177 | } |