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