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