Commit | Line | Data |
---|---|---|
7b33a0e0 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 | ||
16699f85 PP |
15 | #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) |
16 | #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) | |
b03487ab | 17 | #define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC" |
3fa1b6a3 | 18 | #include "logging/comp-logging.h" |
7b33a0e0 | 19 | |
71c5da58 | 20 | #include <babeltrace2/babeltrace.h> |
85e7137b | 21 | #include "common/macros.h" |
57952005 | 22 | #include "common/assert.h" |
7b33a0e0 PP |
23 | #include <glib.h> |
24 | #include <stdint.h> | |
25 | #include <string.h> | |
26 | #include <inttypes.h> | |
27 | ||
28 | #include "ctf-meta-visitors.h" | |
16699f85 | 29 | #include "logging.h" |
7b33a0e0 PP |
30 | |
31 | static inline | |
939190b3 | 32 | int find_mapped_clock_class(struct ctf_field_class *fc, |
1f1f2720 | 33 | struct ctf_clock_class **clock_class, |
16699f85 | 34 | struct meta_log_config *log_cfg) |
7b33a0e0 PP |
35 | { |
36 | int ret = 0; | |
37 | uint64_t i; | |
38 | ||
939190b3 | 39 | if (!fc) { |
7b33a0e0 PP |
40 | goto end; |
41 | } | |
42 | ||
af0c18e3 PP |
43 | switch (fc->type) { |
44 | case CTF_FIELD_CLASS_TYPE_INT: | |
45 | case CTF_FIELD_CLASS_TYPE_ENUM: | |
7b33a0e0 | 46 | { |
939190b3 | 47 | struct ctf_field_class_int *int_fc = (void *) fc; |
7b33a0e0 | 48 | |
939190b3 | 49 | if (int_fc->mapped_clock_class) { |
7b33a0e0 | 50 | if (*clock_class && *clock_class != |
939190b3 | 51 | int_fc->mapped_clock_class) { |
16699f85 | 52 | BT_COMP_LOGE("Stream class contains more than one " |
7b33a0e0 PP |
53 | "clock class: expected-cc-name=\"%s\", " |
54 | "other-cc-name=\"%s\"", | |
35fa110e PP |
55 | (*clock_class)->name->str, |
56 | int_fc->mapped_clock_class->name->str); | |
7b33a0e0 PP |
57 | ret = -1; |
58 | goto end; | |
59 | } | |
60 | ||
939190b3 | 61 | *clock_class = int_fc->mapped_clock_class; |
7b33a0e0 PP |
62 | } |
63 | ||
64 | break; | |
65 | } | |
af0c18e3 | 66 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
7b33a0e0 | 67 | { |
939190b3 | 68 | struct ctf_field_class_struct *struct_fc = (void *) fc; |
7b33a0e0 | 69 | |
939190b3 PP |
70 | for (i = 0; i < struct_fc->members->len; i++) { |
71 | struct ctf_named_field_class *named_fc = | |
72 | ctf_field_class_struct_borrow_member_by_index( | |
73 | struct_fc, i); | |
7b33a0e0 | 74 | |
939190b3 | 75 | ret = find_mapped_clock_class(named_fc->fc, |
16699f85 | 76 | clock_class, log_cfg); |
7b33a0e0 PP |
77 | if (ret) { |
78 | goto end; | |
79 | } | |
80 | } | |
81 | ||
82 | break; | |
83 | } | |
af0c18e3 | 84 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
7b33a0e0 | 85 | { |
939190b3 | 86 | struct ctf_field_class_variant *var_fc = (void *) fc; |
7b33a0e0 | 87 | |
939190b3 PP |
88 | for (i = 0; i < var_fc->options->len; i++) { |
89 | struct ctf_named_field_class *named_fc = | |
90 | ctf_field_class_variant_borrow_option_by_index( | |
91 | var_fc, i); | |
7b33a0e0 | 92 | |
939190b3 | 93 | ret = find_mapped_clock_class(named_fc->fc, |
16699f85 | 94 | clock_class, log_cfg); |
7b33a0e0 PP |
95 | if (ret) { |
96 | goto end; | |
97 | } | |
98 | } | |
99 | ||
100 | break; | |
101 | } | |
af0c18e3 PP |
102 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
103 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
7b33a0e0 | 104 | { |
939190b3 | 105 | struct ctf_field_class_array_base *array_fc = (void *) fc; |
7b33a0e0 | 106 | |
1f1f2720 | 107 | ret = find_mapped_clock_class(array_fc->elem_fc, clock_class, |
16699f85 | 108 | log_cfg); |
7b33a0e0 PP |
109 | if (ret) { |
110 | goto end; | |
111 | } | |
112 | ||
113 | break; | |
114 | } | |
115 | default: | |
116 | break; | |
117 | } | |
118 | ||
119 | end: | |
120 | return ret; | |
121 | } | |
122 | ||
123 | static inline | |
124 | int update_stream_class_default_clock_class( | |
1f1f2720 | 125 | struct ctf_stream_class *stream_class, |
16699f85 | 126 | struct meta_log_config *log_cfg) |
7b33a0e0 PP |
127 | { |
128 | int ret = 0; | |
35fa110e | 129 | struct ctf_clock_class *clock_class = |
9e550e5f | 130 | stream_class->default_clock_class; |
7b33a0e0 PP |
131 | uint64_t i; |
132 | ||
939190b3 | 133 | ret = find_mapped_clock_class(stream_class->packet_context_fc, |
16699f85 | 134 | &clock_class, log_cfg); |
7b33a0e0 PP |
135 | if (ret) { |
136 | goto end; | |
137 | } | |
138 | ||
939190b3 | 139 | ret = find_mapped_clock_class(stream_class->event_header_fc, |
16699f85 | 140 | &clock_class, log_cfg); |
7b33a0e0 PP |
141 | if (ret) { |
142 | goto end; | |
143 | } | |
144 | ||
939190b3 | 145 | ret = find_mapped_clock_class(stream_class->event_common_context_fc, |
16699f85 | 146 | &clock_class, log_cfg); |
7b33a0e0 PP |
147 | if (ret) { |
148 | goto end; | |
149 | } | |
150 | ||
151 | for (i = 0; i < stream_class->event_classes->len; i++) { | |
152 | struct ctf_event_class *event_class = | |
153 | stream_class->event_classes->pdata[i]; | |
154 | ||
939190b3 | 155 | ret = find_mapped_clock_class(event_class->spec_context_fc, |
16699f85 | 156 | &clock_class, log_cfg); |
7b33a0e0 PP |
157 | if (ret) { |
158 | goto end; | |
159 | } | |
160 | ||
939190b3 | 161 | ret = find_mapped_clock_class(event_class->payload_fc, |
16699f85 | 162 | &clock_class, log_cfg); |
7b33a0e0 PP |
163 | if (ret) { |
164 | goto end; | |
165 | } | |
166 | } | |
167 | ||
168 | if (!stream_class->default_clock_class) { | |
4b70020d | 169 | stream_class->default_clock_class = clock_class; |
7b33a0e0 PP |
170 | } |
171 | ||
172 | end: | |
173 | return ret; | |
174 | } | |
175 | ||
176 | BT_HIDDEN | |
1f1f2720 | 177 | int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc, |
16699f85 | 178 | struct meta_log_config *log_cfg) |
7b33a0e0 PP |
179 | { |
180 | uint64_t i; | |
181 | int ret = 0; | |
35fa110e | 182 | struct ctf_clock_class *clock_class = NULL; |
7b33a0e0 | 183 | |
1f1f2720 | 184 | ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class, |
16699f85 | 185 | log_cfg); |
7b33a0e0 PP |
186 | if (ret) { |
187 | goto end; | |
188 | } | |
189 | ||
190 | if (clock_class) { | |
191 | ret = -1; | |
192 | goto end; | |
193 | } | |
194 | ||
195 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
196 | struct ctf_stream_class *sc = | |
197 | ctf_tc->stream_classes->pdata[i]; | |
198 | ||
199 | ret = update_stream_class_default_clock_class( | |
16699f85 | 200 | ctf_tc->stream_classes->pdata[i], log_cfg); |
7b33a0e0 | 201 | if (ret) { |
16699f85 | 202 | BT_COMP_LOGE("Stream class contains more than one " |
7b33a0e0 PP |
203 | "clock class: stream-class-id=%" PRIu64, |
204 | sc->id); | |
205 | goto end; | |
206 | } | |
207 | } | |
208 | ||
209 | end: | |
210 | return ret; | |
211 | } |