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