Commit | Line | Data |
---|---|---|
bc37ae52 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
bc37ae52 JG |
3 | * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
bc37ae52 JG |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
b03487ab | 24 | #define BT_LOG_TAG "LIB/TRACE" |
1633ef46 | 25 | #include "lib/logging.h" |
e011d2c1 | 26 | |
57952005 | 27 | #include "lib/assert-pre.h" |
727170fc | 28 | #include "lib/assert-post.h" |
71c5da58 | 29 | #include <babeltrace2/trace-ir/trace.h> |
71c5da58 | 30 | #include <babeltrace2/trace-ir/trace-const.h> |
71c5da58 | 31 | #include <babeltrace2/trace-ir/event-class.h> |
57952005 MJ |
32 | #include "ctf-writer/functor.h" |
33 | #include "ctf-writer/clock.h" | |
34 | #include "compat/compiler.h" | |
71c5da58 MJ |
35 | #include <babeltrace2/value.h> |
36 | #include <babeltrace2/value-const.h> | |
57952005 | 37 | #include "lib/value.h" |
71c5da58 | 38 | #include <babeltrace2/types.h> |
57952005 MJ |
39 | #include "compat/endian.h" |
40 | #include "common/assert.h" | |
41 | #include "compat/glib.h" | |
dc3fffef | 42 | #include <inttypes.h> |
544d0515 | 43 | #include <stdint.h> |
4a32fda0 | 44 | #include <string.h> |
0fbb9a9f | 45 | #include <stdlib.h> |
bc37ae52 | 46 | |
57952005 MJ |
47 | #include "attributes.h" |
48 | #include "clock-class.h" | |
49 | #include "event-class.h" | |
50 | #include "event.h" | |
51 | #include "field-class.h" | |
52 | #include "field-wrapper.h" | |
53 | #include "resolve-field-path.h" | |
54 | #include "stream-class.h" | |
55 | #include "stream.h" | |
56 | #include "trace-class.h" | |
57 | #include "trace.h" | |
58 | #include "utils.h" | |
af90138b | 59 | #include "lib/value.h" |
fb25b9e3 | 60 | #include "lib/func-status.h" |
57952005 | 61 | |
1122415c FD |
62 | struct bt_trace_destruction_listener_elem { |
63 | bt_trace_destruction_listener_func func; | |
3602afb0 PP |
64 | void *data; |
65 | }; | |
66 | ||
fa6cfec3 PP |
67 | #define BT_ASSERT_PRE_DEV_TRACE_HOT(_trace) \ |
68 | BT_ASSERT_PRE_DEV_HOT((_trace), "Trace", ": %!+t", (_trace)) | |
18acc6f8 | 69 | |
bc37ae52 | 70 | static |
7b33a0e0 | 71 | void destroy_trace(struct bt_object *obj) |
8deee039 PP |
72 | { |
73 | struct bt_trace *trace = (void *) obj; | |
bc37ae52 | 74 | |
7b33a0e0 | 75 | BT_LIB_LOGD("Destroying trace object: %!+t", trace); |
af90138b | 76 | BT_OBJECT_PUT_REF_AND_RESET(trace->user_attributes); |
bc37ae52 | 77 | |
8deee039 | 78 | /* |
1122415c FD |
79 | * Call destruction listener functions so that everything else |
80 | * still exists in the trace. | |
8deee039 | 81 | */ |
1122415c FD |
82 | if (trace->destruction_listeners) { |
83 | uint64_t i; | |
a684a357 | 84 | BT_LIB_LOGD("Calling trace destruction listener(s): %!+t", trace); |
69868f44 SM |
85 | |
86 | /* | |
87 | * The trace's reference count is 0 if we're here. Increment | |
88 | * it to avoid a double-destroy (possibly infinitely recursive). | |
89 | * This could happen for example if a destruction listener did | |
90 | * bt_object_get_ref() (or anything that causes | |
91 | * bt_object_get_ref() to be called) on the trace (ref. | |
92 | * count goes from 0 to 1), and then bt_object_put_ref(): the | |
93 | * reference count would go from 1 to 0 again and this function | |
94 | * would be called again. | |
95 | */ | |
96 | trace->base.ref_count++; | |
97 | ||
1122415c FD |
98 | /* Call all the trace destruction listeners */ |
99 | for (i = 0; i < trace->destruction_listeners->len; i++) { | |
100 | struct bt_trace_destruction_listener_elem elem = | |
101 | g_array_index(trace->destruction_listeners, | |
102 | struct bt_trace_destruction_listener_elem, i); | |
103 | ||
104 | if (elem.func) { | |
105 | elem.func(trace, elem.data); | |
8deee039 | 106 | } |
69868f44 SM |
107 | |
108 | /* | |
109 | * The destruction listener should not have kept a | |
110 | * reference to the trace. | |
111 | */ | |
727170fc | 112 | BT_ASSERT_POST(trace->base.ref_count == 1, "Destruction listener kept a reference to the trace being destroyed: %![trace-]+t", trace); |
8deee039 | 113 | } |
1122415c FD |
114 | g_array_free(trace->destruction_listeners, TRUE); |
115 | trace->destruction_listeners = NULL; | |
bc37ae52 JG |
116 | } |
117 | ||
7b33a0e0 PP |
118 | if (trace->name.str) { |
119 | g_string_free(trace->name.str, TRUE); | |
1248f5ea PP |
120 | trace->name.str = NULL; |
121 | trace->name.value = NULL; | |
95c09b3a PP |
122 | } |
123 | ||
cd03c43c PP |
124 | if (trace->environment) { |
125 | BT_LOGD_STR("Destroying environment attributes."); | |
126 | bt_attributes_destroy(trace->environment); | |
127 | trace->environment = NULL; | |
128 | } | |
129 | ||
7b33a0e0 PP |
130 | if (trace->streams) { |
131 | BT_LOGD_STR("Destroying streams."); | |
132 | g_ptr_array_free(trace->streams, TRUE); | |
1248f5ea | 133 | trace->streams = NULL; |
bc37ae52 JG |
134 | } |
135 | ||
7b33a0e0 PP |
136 | if (trace->stream_classes_stream_count) { |
137 | g_hash_table_destroy(trace->stream_classes_stream_count); | |
1248f5ea | 138 | trace->stream_classes_stream_count = NULL; |
7b33a0e0 | 139 | } |
8deee039 | 140 | |
10b7a2e4 PP |
141 | BT_LOGD_STR("Putting trace's class."); |
142 | bt_object_put_ref(trace->class); | |
143 | trace->class = NULL; | |
7b33a0e0 | 144 | g_free(trace); |
8deee039 PP |
145 | } |
146 | ||
10b7a2e4 | 147 | struct bt_trace *bt_trace_create(struct bt_trace_class *tc) |
8deee039 PP |
148 | { |
149 | struct bt_trace *trace = NULL; | |
8deee039 | 150 | |
10b7a2e4 | 151 | BT_LIB_LOGD("Creating trace object: %![tc-]+T", tc); |
8deee039 PP |
152 | trace = g_new0(struct bt_trace, 1); |
153 | if (!trace) { | |
a8f90e5d | 154 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one trace."); |
8deee039 PP |
155 | goto error; |
156 | } | |
157 | ||
10b7a2e4 | 158 | bt_object_init_shared(&trace->base, destroy_trace); |
af90138b PP |
159 | trace->user_attributes = bt_value_map_create(); |
160 | if (!trace->user_attributes) { | |
161 | BT_LIB_LOGE_APPEND_CAUSE( | |
162 | "Failed to create a map value object."); | |
163 | goto error; | |
164 | } | |
165 | ||
7b33a0e0 PP |
166 | trace->streams = g_ptr_array_new_with_free_func( |
167 | (GDestroyNotify) bt_object_try_spec_release); | |
168 | if (!trace->streams) { | |
a8f90e5d | 169 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray."); |
8deee039 PP |
170 | goto error; |
171 | } | |
172 | ||
7b33a0e0 PP |
173 | trace->stream_classes_stream_count = g_hash_table_new(g_direct_hash, |
174 | g_direct_equal); | |
175 | if (!trace->stream_classes_stream_count) { | |
a8f90e5d | 176 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GHashTable."); |
7b33a0e0 PP |
177 | goto error; |
178 | } | |
179 | ||
180 | trace->name.str = g_string_new(NULL); | |
181 | if (!trace->name.str) { | |
a8f90e5d | 182 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString."); |
7b33a0e0 PP |
183 | goto error; |
184 | } | |
185 | ||
cd03c43c PP |
186 | trace->environment = bt_attributes_create(); |
187 | if (!trace->environment) { | |
188 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object."); | |
189 | goto error; | |
190 | } | |
191 | ||
1122415c FD |
192 | trace->destruction_listeners = g_array_new(FALSE, TRUE, |
193 | sizeof(struct bt_trace_destruction_listener_elem)); | |
194 | if (!trace->destruction_listeners) { | |
a8f90e5d | 195 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray."); |
3602afb0 PP |
196 | goto error; |
197 | } | |
198 | ||
10b7a2e4 | 199 | trace->class = tc; |
864aa43f | 200 | bt_object_get_ref_no_null_check(trace->class); |
7b33a0e0 PP |
201 | BT_LIB_LOGD("Created trace object: %!+t", trace); |
202 | goto end; | |
bc37ae52 | 203 | |
bc37ae52 | 204 | error: |
8138bfe1 | 205 | BT_OBJECT_PUT_REF_AND_RESET(trace); |
7b33a0e0 PP |
206 | |
207 | end: | |
10b7a2e4 | 208 | return trace; |
bc37ae52 JG |
209 | } |
210 | ||
78cf9df6 | 211 | const char *bt_trace_get_name(const struct bt_trace *trace) |
e96045d4 | 212 | { |
fa6cfec3 | 213 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
7b33a0e0 | 214 | return trace->name.value; |
e96045d4 JG |
215 | } |
216 | ||
fb25b9e3 PP |
217 | enum bt_trace_set_name_status bt_trace_set_name(struct bt_trace *trace, |
218 | const char *name) | |
e96045d4 | 219 | { |
7b33a0e0 PP |
220 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); |
221 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
fa6cfec3 | 222 | BT_ASSERT_PRE_DEV_TRACE_HOT(trace); |
7b33a0e0 PP |
223 | g_string_assign(trace->name.str, name); |
224 | trace->name.value = trace->name.str->str; | |
a684a357 | 225 | BT_LIB_LOGD("Set trace's name: %!+t", trace); |
fb25b9e3 | 226 | return BT_FUNC_STATUS_OK; |
e96045d4 JG |
227 | } |
228 | ||
cd03c43c PP |
229 | bt_uuid bt_trace_get_uuid(const struct bt_trace *trace) |
230 | { | |
fa6cfec3 | 231 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
cd03c43c PP |
232 | return trace->uuid.value; |
233 | } | |
234 | ||
235 | void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid) | |
236 | { | |
237 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); | |
238 | BT_ASSERT_PRE_NON_NULL(uuid, "UUID"); | |
fa6cfec3 | 239 | BT_ASSERT_PRE_DEV_TRACE_HOT(trace); |
d126826c | 240 | bt_uuid_copy(trace->uuid.uuid, uuid); |
cd03c43c PP |
241 | trace->uuid.value = trace->uuid.uuid; |
242 | BT_LIB_LOGD("Set trace's UUID: %!+t", trace); | |
243 | } | |
244 | ||
cd03c43c PP |
245 | static |
246 | bool trace_has_environment_entry(const struct bt_trace *trace, const char *name) | |
247 | { | |
248 | BT_ASSERT(trace); | |
249 | ||
250 | return bt_attributes_borrow_field_value_by_name( | |
8e01f2d9 | 251 | trace->environment, name); |
cd03c43c PP |
252 | } |
253 | ||
254 | static | |
255 | enum bt_trace_set_environment_entry_status set_environment_entry( | |
256 | struct bt_trace *trace, | |
257 | const char *name, struct bt_value *value) | |
258 | { | |
259 | int ret; | |
260 | ||
261 | BT_ASSERT(trace); | |
262 | BT_ASSERT(name); | |
263 | BT_ASSERT(value); | |
264 | BT_ASSERT_PRE(!trace->frozen || | |
265 | !trace_has_environment_entry(trace, name), | |
266 | "Trace is frozen: cannot replace environment entry: " | |
267 | "%![trace-]+t, entry-name=\"%s\"", trace, name); | |
268 | ret = bt_attributes_set_field_value(trace->environment, name, | |
269 | value); | |
270 | if (ret) { | |
271 | ret = BT_FUNC_STATUS_MEMORY_ERROR; | |
272 | BT_LIB_LOGE_APPEND_CAUSE( | |
273 | "Cannot set trace's environment entry: " | |
274 | "%![trace-]+t, entry-name=\"%s\"", trace, name); | |
275 | } else { | |
276 | bt_value_freeze(value); | |
277 | BT_LIB_LOGD("Set trace's environment entry: " | |
278 | "%![trace-]+t, entry-name=\"%s\"", trace, name); | |
279 | } | |
280 | ||
281 | return ret; | |
282 | } | |
283 | ||
284 | enum bt_trace_set_environment_entry_status | |
285 | bt_trace_set_environment_entry_string( | |
286 | struct bt_trace *trace, const char *name, const char *value) | |
287 | { | |
288 | int ret; | |
289 | struct bt_value *value_obj; | |
290 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); | |
291 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
292 | BT_ASSERT_PRE_NON_NULL(value, "Value"); | |
293 | value_obj = bt_value_string_create_init(value); | |
294 | if (!value_obj) { | |
295 | BT_LIB_LOGE_APPEND_CAUSE( | |
296 | "Cannot create a string value object."); | |
297 | ret = -1; | |
298 | goto end; | |
299 | } | |
300 | ||
301 | /* set_environment_entry() logs errors */ | |
302 | ret = set_environment_entry(trace, name, value_obj); | |
303 | ||
304 | end: | |
305 | bt_object_put_ref(value_obj); | |
306 | return ret; | |
307 | } | |
308 | ||
309 | enum bt_trace_set_environment_entry_status | |
310 | bt_trace_set_environment_entry_integer( | |
311 | struct bt_trace *trace, const char *name, int64_t value) | |
312 | { | |
313 | int ret; | |
314 | struct bt_value *value_obj; | |
315 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); | |
316 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
60bbfc7c | 317 | value_obj = bt_value_integer_signed_create_init(value); |
cd03c43c PP |
318 | if (!value_obj) { |
319 | BT_LIB_LOGE_APPEND_CAUSE( | |
320 | "Cannot create an integer value object."); | |
321 | ret = BT_FUNC_STATUS_MEMORY_ERROR; | |
322 | goto end; | |
323 | } | |
324 | ||
325 | /* set_environment_entry() logs errors */ | |
326 | ret = set_environment_entry(trace, name, value_obj); | |
327 | ||
328 | end: | |
329 | bt_object_put_ref(value_obj); | |
330 | return ret; | |
331 | } | |
332 | ||
333 | uint64_t bt_trace_get_environment_entry_count(const struct bt_trace *trace) | |
334 | { | |
335 | int64_t ret; | |
336 | ||
fa6cfec3 | 337 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
cd03c43c PP |
338 | ret = bt_attributes_get_count(trace->environment); |
339 | BT_ASSERT(ret >= 0); | |
340 | return (uint64_t) ret; | |
341 | } | |
342 | ||
343 | void bt_trace_borrow_environment_entry_by_index_const( | |
344 | const struct bt_trace *trace, uint64_t index, | |
345 | const char **name, const struct bt_value **value) | |
346 | { | |
fa6cfec3 PP |
347 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
348 | BT_ASSERT_PRE_DEV_NON_NULL(name, "Name"); | |
349 | BT_ASSERT_PRE_DEV_NON_NULL(value, "Value"); | |
350 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, | |
cd03c43c PP |
351 | bt_attributes_get_count(trace->environment)); |
352 | *value = bt_attributes_borrow_field_value(trace->environment, index); | |
353 | BT_ASSERT(*value); | |
354 | *name = bt_attributes_get_field_name(trace->environment, index); | |
355 | BT_ASSERT(*name); | |
356 | } | |
357 | ||
358 | const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const( | |
359 | const struct bt_trace *trace, const char *name) | |
360 | { | |
fa6cfec3 PP |
361 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
362 | BT_ASSERT_PRE_DEV_NON_NULL(name, "Name"); | |
cd03c43c PP |
363 | return bt_attributes_borrow_field_value_by_name(trace->environment, |
364 | name); | |
365 | } | |
366 | ||
78cf9df6 | 367 | uint64_t bt_trace_get_stream_count(const struct bt_trace *trace) |
bc37ae52 | 368 | { |
fa6cfec3 | 369 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
7b33a0e0 PP |
370 | return (uint64_t) trace->streams->len; |
371 | } | |
95c09b3a | 372 | |
7b33a0e0 PP |
373 | struct bt_stream *bt_trace_borrow_stream_by_index( |
374 | struct bt_trace *trace, uint64_t index) | |
375 | { | |
fa6cfec3 PP |
376 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
377 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, trace->streams->len); | |
7b33a0e0 PP |
378 | return g_ptr_array_index(trace->streams, index); |
379 | } | |
18acc6f8 | 380 | |
78cf9df6 PP |
381 | const struct bt_stream *bt_trace_borrow_stream_by_index_const( |
382 | const struct bt_trace *trace, uint64_t index) | |
9e550e5f | 383 | { |
78cf9df6 | 384 | return bt_trace_borrow_stream_by_index((void *) trace, index); |
9e550e5f PP |
385 | } |
386 | ||
78cf9df6 PP |
387 | struct bt_stream *bt_trace_borrow_stream_by_id(struct bt_trace *trace, |
388 | uint64_t id) | |
7b33a0e0 PP |
389 | { |
390 | struct bt_stream *stream = NULL; | |
391 | uint64_t i; | |
bc37ae52 | 392 | |
fa6cfec3 | 393 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
bc37ae52 | 394 | |
7b33a0e0 PP |
395 | for (i = 0; i < trace->streams->len; i++) { |
396 | struct bt_stream *stream_candidate = | |
397 | g_ptr_array_index(trace->streams, i); | |
cfeb617e | 398 | |
7b33a0e0 PP |
399 | if (stream_candidate->id == id) { |
400 | stream = stream_candidate; | |
401 | goto end; | |
402 | } | |
6474e016 | 403 | } |
95c09b3a | 404 | |
bc37ae52 | 405 | end: |
7b33a0e0 | 406 | return stream; |
bc37ae52 JG |
407 | } |
408 | ||
78cf9df6 PP |
409 | const struct bt_stream *bt_trace_borrow_stream_by_id_const( |
410 | const struct bt_trace *trace, uint64_t id) | |
9e550e5f | 411 | { |
78cf9df6 | 412 | return bt_trace_borrow_stream_by_id((void *) trace, id); |
9e550e5f PP |
413 | } |
414 | ||
fb25b9e3 | 415 | enum bt_trace_add_listener_status bt_trace_add_destruction_listener( |
78cf9df6 | 416 | const struct bt_trace *c_trace, |
1122415c | 417 | bt_trace_destruction_listener_func listener, |
eba7ea21 | 418 | void *data, bt_listener_id *listener_id) |
3602afb0 | 419 | { |
78cf9df6 | 420 | struct bt_trace *trace = (void *) c_trace; |
7b33a0e0 | 421 | uint64_t i; |
1122415c | 422 | struct bt_trace_destruction_listener_elem new_elem = { |
3602afb0 PP |
423 | .func = listener, |
424 | .data = data, | |
425 | }; | |
426 | ||
7b33a0e0 PP |
427 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); |
428 | BT_ASSERT_PRE_NON_NULL(listener, "Listener"); | |
9962ad4b | 429 | |
3602afb0 | 430 | /* Find the next available spot */ |
1122415c FD |
431 | for (i = 0; i < trace->destruction_listeners->len; i++) { |
432 | struct bt_trace_destruction_listener_elem elem = | |
433 | g_array_index(trace->destruction_listeners, | |
434 | struct bt_trace_destruction_listener_elem, i); | |
3602afb0 PP |
435 | |
436 | if (!elem.func) { | |
437 | break; | |
438 | } | |
439 | } | |
440 | ||
1122415c FD |
441 | if (i == trace->destruction_listeners->len) { |
442 | g_array_append_val(trace->destruction_listeners, new_elem); | |
3602afb0 | 443 | } else { |
1122415c | 444 | g_array_insert_val(trace->destruction_listeners, i, new_elem); |
3602afb0 PP |
445 | } |
446 | ||
7b33a0e0 PP |
447 | if (listener_id) { |
448 | *listener_id = i; | |
449 | } | |
3602afb0 | 450 | |
a684a357 | 451 | BT_LIB_LOGD("Added destruction listener: " "%![trace-]+t, " |
1122415c | 452 | "listener-id=%" PRIu64, trace, i); |
fb25b9e3 | 453 | return BT_FUNC_STATUS_OK; |
7b33a0e0 PP |
454 | } |
455 | ||
7b33a0e0 | 456 | static |
78cf9df6 | 457 | bool has_listener_id(const struct bt_trace *trace, uint64_t listener_id) |
7b33a0e0 | 458 | { |
1122415c FD |
459 | BT_ASSERT(listener_id < trace->destruction_listeners->len); |
460 | return (&g_array_index(trace->destruction_listeners, | |
461 | struct bt_trace_destruction_listener_elem, | |
8e01f2d9 | 462 | listener_id))->func; |
3602afb0 PP |
463 | } |
464 | ||
fb25b9e3 | 465 | enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener( |
eba7ea21 | 466 | const struct bt_trace *c_trace, bt_listener_id listener_id) |
3602afb0 | 467 | { |
78cf9df6 | 468 | struct bt_trace *trace = (void *) c_trace; |
1122415c | 469 | struct bt_trace_destruction_listener_elem *elem; |
3602afb0 | 470 | |
7b33a0e0 | 471 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); |
7b33a0e0 | 472 | BT_ASSERT_PRE(has_listener_id(trace, listener_id), |
1122415c | 473 | "Trace has no such trace destruction listener ID: " |
7b33a0e0 | 474 | "%![trace-]+t, %" PRIu64, trace, listener_id); |
1122415c FD |
475 | elem = &g_array_index(trace->destruction_listeners, |
476 | struct bt_trace_destruction_listener_elem, | |
3602afb0 | 477 | listener_id); |
7b33a0e0 | 478 | BT_ASSERT(elem->func); |
3602afb0 PP |
479 | |
480 | elem->func = NULL; | |
481 | elem->data = NULL; | |
a684a357 | 482 | BT_LIB_LOGD("Removed \"trace destruction listener: " |
7b33a0e0 PP |
483 | "%![trace-]+t, listener-id=%" PRIu64, |
484 | trace, listener_id); | |
fb25b9e3 | 485 | return BT_FUNC_STATUS_OK; |
7b33a0e0 | 486 | } |
3602afb0 | 487 | |
7b33a0e0 | 488 | BT_HIDDEN |
78cf9df6 | 489 | void _bt_trace_freeze(const struct bt_trace *trace) |
7b33a0e0 | 490 | { |
7b33a0e0 | 491 | BT_ASSERT(trace); |
10b7a2e4 PP |
492 | BT_LIB_LOGD("Freezing trace's class: %!+T", trace->class); |
493 | bt_trace_class_freeze(trace->class); | |
af90138b PP |
494 | BT_LIB_LOGD("Freezing trace's user attributes: %!+v", |
495 | trace->user_attributes); | |
496 | bt_value_freeze(trace->user_attributes); | |
7b33a0e0 | 497 | BT_LIB_LOGD("Freezing trace: %!+t", trace); |
78cf9df6 | 498 | ((struct bt_trace *) trace)->frozen = true; |
5acf2ae6 | 499 | } |
a6918753 | 500 | |
7b33a0e0 PP |
501 | BT_HIDDEN |
502 | void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream) | |
503 | { | |
504 | guint count = 0; | |
505 | ||
506 | bt_object_set_parent(&stream->base, &trace->base); | |
507 | g_ptr_array_add(trace->streams, stream); | |
18acc6f8 | 508 | bt_trace_freeze(trace); |
a6918753 | 509 | |
7b33a0e0 PP |
510 | if (bt_g_hash_table_contains(trace->stream_classes_stream_count, |
511 | stream->class)) { | |
512 | count = GPOINTER_TO_UINT(g_hash_table_lookup( | |
513 | trace->stream_classes_stream_count, stream->class)); | |
a6918753 PP |
514 | } |
515 | ||
7b33a0e0 PP |
516 | g_hash_table_insert(trace->stream_classes_stream_count, |
517 | stream->class, GUINT_TO_POINTER(count + 1)); | |
518 | } | |
519 | ||
520 | BT_HIDDEN | |
78cf9df6 PP |
521 | uint64_t bt_trace_get_automatic_stream_id(const struct bt_trace *trace, |
522 | const struct bt_stream_class *stream_class) | |
7b33a0e0 PP |
523 | { |
524 | gpointer orig_key; | |
525 | gpointer value; | |
526 | uint64_t id = 0; | |
527 | ||
528 | BT_ASSERT(stream_class); | |
529 | BT_ASSERT(trace); | |
530 | if (g_hash_table_lookup_extended(trace->stream_classes_stream_count, | |
531 | stream_class, &orig_key, &value)) { | |
532 | id = (uint64_t) GPOINTER_TO_UINT(value); | |
533 | } | |
534 | ||
535 | return id; | |
a6918753 | 536 | } |
10b7a2e4 PP |
537 | |
538 | struct bt_trace_class *bt_trace_borrow_class(struct bt_trace *trace) | |
539 | { | |
fa6cfec3 | 540 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); |
10b7a2e4 PP |
541 | return trace->class; |
542 | } | |
543 | ||
544 | const struct bt_trace_class *bt_trace_borrow_class_const( | |
545 | const struct bt_trace *trace) | |
546 | { | |
547 | return bt_trace_borrow_class((void *) trace); | |
548 | } | |
8c6884d9 | 549 | |
af90138b PP |
550 | const struct bt_value *bt_trace_borrow_user_attributes_const( |
551 | const struct bt_trace *trace) | |
552 | { | |
553 | BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace"); | |
554 | return trace->user_attributes; | |
555 | } | |
556 | ||
557 | struct bt_value *bt_trace_borrow_user_attributes(struct bt_trace *trace) | |
558 | { | |
559 | return (void *) bt_trace_borrow_user_attributes_const((void *) trace); | |
560 | } | |
561 | ||
562 | void bt_trace_set_user_attributes( | |
563 | struct bt_trace *trace, | |
564 | const struct bt_value *user_attributes) | |
565 | { | |
566 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); | |
567 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
568 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
569 | "User attributes object is not a map value object."); | |
570 | BT_ASSERT_PRE_DEV_TRACE_HOT(trace); | |
864aa43f | 571 | bt_object_put_ref_no_null_check(trace->user_attributes); |
af90138b | 572 | trace->user_attributes = (void *) user_attributes; |
864aa43f | 573 | bt_object_get_ref_no_null_check(trace->user_attributes); |
af90138b PP |
574 | } |
575 | ||
8c6884d9 PP |
576 | void bt_trace_get_ref(const struct bt_trace *trace) |
577 | { | |
578 | bt_object_get_ref(trace); | |
579 | } | |
580 | ||
581 | void bt_trace_put_ref(const struct bt_trace *trace) | |
582 | { | |
583 | bt_object_put_ref(trace); | |
584 | } |