Trace IR and notification APIs: split into private and public APIs
[babeltrace.git] / lib / trace-ir / trace.c
1 /*
2 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #define BT_LOG_TAG "TRACE"
26 #include <babeltrace/lib-logging-internal.h>
27
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/trace-ir/private-trace.h>
30 #include <babeltrace/trace-ir/trace-internal.h>
31 #include <babeltrace/trace-ir/clock-class-internal.h>
32 #include <babeltrace/trace-ir/stream-internal.h>
33 #include <babeltrace/trace-ir/stream-class-internal.h>
34 #include <babeltrace/trace-ir/event-internal.h>
35 #include <babeltrace/trace-ir/event-class.h>
36 #include <babeltrace/trace-ir/event-class-internal.h>
37 #include <babeltrace/ctf-writer/functor-internal.h>
38 #include <babeltrace/ctf-writer/clock-internal.h>
39 #include <babeltrace/trace-ir/field-wrapper-internal.h>
40 #include <babeltrace/trace-ir/field-classes-internal.h>
41 #include <babeltrace/trace-ir/attributes-internal.h>
42 #include <babeltrace/trace-ir/utils-internal.h>
43 #include <babeltrace/trace-ir/resolve-field-path-internal.h>
44 #include <babeltrace/compiler-internal.h>
45 #include <babeltrace/values.h>
46 #include <babeltrace/private-values.h>
47 #include <babeltrace/values-internal.h>
48 #include <babeltrace/object.h>
49 #include <babeltrace/types.h>
50 #include <babeltrace/endian-internal.h>
51 #include <babeltrace/assert-internal.h>
52 #include <babeltrace/compat/glib-internal.h>
53 #include <inttypes.h>
54 #include <stdint.h>
55 #include <string.h>
56 #include <stdlib.h>
57
58 struct bt_trace_is_static_listener_elem {
59 bt_private_trace_is_static_listener func;
60 bt_private_trace_listener_removed removed;
61 void *data;
62 };
63
64 #define BT_ASSERT_PRE_TRACE_HOT(_trace) \
65 BT_ASSERT_PRE_HOT((_trace), "Trace", ": %!+t", (_trace))
66
67 static
68 void destroy_trace(struct bt_object *obj)
69 {
70 struct bt_trace *trace = (void *) obj;
71
72 BT_LIB_LOGD("Destroying trace object: %!+t", trace);
73
74 /*
75 * Call remove listeners first so that everything else still
76 * exists in the trace.
77 */
78 if (trace->is_static_listeners) {
79 size_t i;
80
81 for (i = 0; i < trace->is_static_listeners->len; i++) {
82 struct bt_trace_is_static_listener_elem elem =
83 g_array_index(trace->is_static_listeners,
84 struct bt_trace_is_static_listener_elem, i);
85
86 if (elem.removed) {
87 elem.removed((void *) trace, elem.data);
88 }
89 }
90
91 g_array_free(trace->is_static_listeners, TRUE);
92 }
93
94 bt_object_pool_finalize(&trace->packet_header_field_pool);
95
96 if (trace->environment) {
97 BT_LOGD_STR("Destroying environment attributes.");
98 bt_attributes_destroy(trace->environment);
99 }
100
101 if (trace->name.str) {
102 g_string_free(trace->name.str, TRUE);
103 }
104
105 if (trace->streams) {
106 BT_LOGD_STR("Destroying streams.");
107 g_ptr_array_free(trace->streams, TRUE);
108 }
109
110 if (trace->stream_classes) {
111 BT_LOGD_STR("Destroying stream classes.");
112 g_ptr_array_free(trace->stream_classes, TRUE);
113 }
114
115 if (trace->stream_classes_stream_count) {
116 g_hash_table_destroy(trace->stream_classes_stream_count);
117 }
118
119 BT_LOGD_STR("Putting packet header field classe.");
120 bt_object_put_ref(trace->packet_header_fc);
121 g_free(trace);
122 }
123
124 static
125 void free_packet_header_field(struct bt_field_wrapper *field_wrapper,
126 struct bt_trace *trace)
127 {
128 bt_field_wrapper_destroy(field_wrapper);
129 }
130
131 struct bt_private_trace *bt_private_trace_create(void)
132 {
133 struct bt_trace *trace = NULL;
134 int ret;
135
136 BT_LOGD_STR("Creating default trace object.");
137 trace = g_new0(struct bt_trace, 1);
138 if (!trace) {
139 BT_LOGE_STR("Failed to allocate one trace.");
140 goto error;
141 }
142
143 bt_object_init_shared_with_parent(&trace->base, destroy_trace);
144 trace->streams = g_ptr_array_new_with_free_func(
145 (GDestroyNotify) bt_object_try_spec_release);
146 if (!trace->streams) {
147 BT_LOGE_STR("Failed to allocate one GPtrArray.");
148 goto error;
149 }
150
151 trace->stream_classes = g_ptr_array_new_with_free_func(
152 (GDestroyNotify) bt_object_try_spec_release);
153 if (!trace->stream_classes) {
154 BT_LOGE_STR("Failed to allocate one GPtrArray.");
155 goto error;
156 }
157
158 trace->stream_classes_stream_count = g_hash_table_new(g_direct_hash,
159 g_direct_equal);
160 if (!trace->stream_classes_stream_count) {
161 BT_LOGE_STR("Failed to allocate one GHashTable.");
162 goto error;
163 }
164
165 trace->name.str = g_string_new(NULL);
166 if (!trace->name.str) {
167 BT_LOGE_STR("Failed to allocate one GString.");
168 goto error;
169 }
170
171 trace->environment = bt_attributes_create();
172 if (!trace->environment) {
173 BT_LOGE_STR("Cannot create empty attributes object.");
174 goto error;
175 }
176
177 trace->is_static_listeners = g_array_new(FALSE, TRUE,
178 sizeof(struct bt_trace_is_static_listener_elem));
179 if (!trace->is_static_listeners) {
180 BT_LOGE_STR("Failed to allocate one GArray.");
181 goto error;
182 }
183
184 trace->assigns_automatic_stream_class_id = true;
185 ret = bt_object_pool_initialize(&trace->packet_header_field_pool,
186 (bt_object_pool_new_object_func) bt_field_wrapper_new,
187 (bt_object_pool_destroy_object_func) free_packet_header_field,
188 trace);
189 if (ret) {
190 BT_LOGE("Failed to initialize packet header field pool: ret=%d",
191 ret);
192 goto error;
193 }
194
195 BT_LIB_LOGD("Created trace object: %!+t", trace);
196 goto end;
197
198 error:
199 BT_OBJECT_PUT_REF_AND_RESET(trace);
200
201 end:
202 return (void *) trace;
203 }
204
205 const char *bt_trace_get_name(struct bt_trace *trace)
206 {
207 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
208 return trace->name.value;
209 }
210
211 int bt_private_trace_set_name(struct bt_private_trace *priv_trace,
212 const char *name)
213 {
214 struct bt_trace *trace = (void *) priv_trace;
215
216 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
217 BT_ASSERT_PRE_NON_NULL(name, "Name");
218 BT_ASSERT_PRE_TRACE_HOT(trace);
219 g_string_assign(trace->name.str, name);
220 trace->name.value = trace->name.str->str;
221 BT_LIB_LOGV("Set trace's name: %!+t", trace);
222 return 0;
223 }
224
225 bt_uuid bt_trace_get_uuid(struct bt_trace *trace)
226 {
227 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
228 return trace->uuid.value;
229 }
230
231 int bt_private_trace_set_uuid(struct bt_private_trace *priv_trace, bt_uuid uuid)
232 {
233 struct bt_trace *trace = (void *) priv_trace;
234
235 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
236 BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
237 BT_ASSERT_PRE_TRACE_HOT(trace);
238 memcpy(trace->uuid.uuid, uuid, BABELTRACE_UUID_LEN);
239 trace->uuid.value = trace->uuid.uuid;
240 BT_LIB_LOGV("Set trace's UUID: %!+t", trace);
241 return 0;
242 }
243
244 BT_ASSERT_FUNC
245 static
246 bool trace_has_environment_entry(struct bt_trace *trace, const char *name)
247 {
248 BT_ASSERT(trace);
249
250 return bt_attributes_borrow_field_value_by_name(
251 trace->environment, name) != NULL;
252 }
253
254 static
255 int set_environment_entry(struct bt_trace *trace, const char *name,
256 struct bt_private_value *value)
257 {
258 int ret;
259
260 BT_ASSERT(trace);
261 BT_ASSERT(name);
262 BT_ASSERT(value);
263 BT_ASSERT_PRE(!trace->frozen ||
264 !trace_has_environment_entry(trace, name),
265 "Trace is frozen: cannot replace environment entry: "
266 "%![trace-]+t, entry-name=\"%s\"", trace, name);
267 ret = bt_attributes_set_field_value(trace->environment, name,
268 value);
269 bt_value_freeze(bt_value_borrow_from_private(value));
270 if (ret) {
271 BT_LIB_LOGE("Cannot set trace's environment entry: "
272 "%![trace-]+t, entry-name=\"%s\"", trace, name);
273 } else {
274 BT_LIB_LOGV("Set trace's environment entry: "
275 "%![trace-]+t, entry-name=\"%s\"", trace, name);
276 }
277
278 return ret;
279 }
280
281 int bt_private_trace_set_private_environment_entry_string(
282 struct bt_private_trace *priv_trace,
283 const char *name, const char *value)
284 {
285 int ret;
286 struct bt_private_value *value_obj;
287 struct bt_trace *trace = (void *) priv_trace;
288
289 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
290 BT_ASSERT_PRE_NON_NULL(name, "Name");
291 BT_ASSERT_PRE_NON_NULL(value, "Value");
292 value_obj = bt_private_value_string_create_init(value);
293 if (!value_obj) {
294 BT_LOGE_STR("Cannot create a string value object.");
295 ret = -1;
296 goto end;
297 }
298
299 /* set_environment_entry() logs errors */
300 ret = set_environment_entry(trace, name, value_obj);
301
302 end:
303 bt_object_put_ref(value_obj);
304 return ret;
305 }
306
307 int bt_private_trace_set_private_environment_entry_integer(
308 struct bt_private_trace *priv_trace,
309 const char *name, int64_t value)
310 {
311 int ret;
312 struct bt_private_value *value_obj;
313 struct bt_trace *trace = (void *) priv_trace;
314
315 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
316 BT_ASSERT_PRE_NON_NULL(name, "Name");
317 value_obj = bt_private_value_integer_create_init(value);
318 if (!value_obj) {
319 BT_LOGE_STR("Cannot create an integer value object.");
320 ret = -1;
321 goto end;
322 }
323
324 /* set_environment_entry() logs errors */
325 ret = set_environment_entry(trace, name, value_obj);
326
327 end:
328 bt_object_put_ref(value_obj);
329 return ret;
330 }
331
332 uint64_t bt_trace_get_environment_entry_count(struct bt_trace *trace)
333 {
334 int64_t ret;
335
336 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
337 ret = bt_attributes_get_count(trace->environment);
338 BT_ASSERT(ret >= 0);
339 return (uint64_t) ret;
340 }
341
342 void bt_trace_borrow_environment_entry_by_index(
343 struct bt_trace *trace, uint64_t index,
344 const char **name, struct bt_value **value)
345 {
346 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
347 BT_ASSERT_PRE_NON_NULL(name, "Name");
348 BT_ASSERT_PRE_NON_NULL(value, "Value");
349 BT_ASSERT_PRE_VALID_INDEX(index,
350 bt_attributes_get_count(trace->environment));
351 *value = bt_value_borrow_from_private(
352 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 void bt_private_trace_borrow_private_environment_entry_by_index(
359 struct bt_private_trace *trace, uint64_t index,
360 const char **name, struct bt_private_value **value)
361 {
362 bt_trace_borrow_environment_entry_by_index((void *) trace,
363 index, name, (void *) value);
364 }
365
366 struct bt_value *bt_trace_borrow_environment_entry_value_by_name(
367 struct bt_trace *trace, const char *name)
368 {
369 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
370 BT_ASSERT_PRE_NON_NULL(name, "Name");
371 return bt_value_borrow_from_private(
372 bt_attributes_borrow_field_value_by_name(trace->environment,
373 name));
374 }
375
376 struct bt_private_value *
377 bt_private_trace_borrow_private_environment_entry_value_by_name(
378 struct bt_private_trace *trace, const char *name)
379 {
380 return (void *) bt_trace_borrow_environment_entry_value_by_name(
381 (void *) trace, name);
382 }
383
384 uint64_t bt_trace_get_stream_count(struct bt_trace *trace)
385 {
386 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
387 return (uint64_t) trace->streams->len;
388 }
389
390 struct bt_stream *bt_trace_borrow_stream_by_index(
391 struct bt_trace *trace, uint64_t index)
392 {
393 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
394 BT_ASSERT_PRE_VALID_INDEX(index, trace->streams->len);
395 return g_ptr_array_index(trace->streams, index);
396 }
397
398 struct bt_private_stream *bt_private_trace_borrow_private_stream_by_index(
399 struct bt_private_trace *trace, uint64_t index)
400 {
401 return (void *) bt_trace_borrow_stream_by_index((void *) trace, index);
402 }
403
404 struct bt_stream *bt_trace_borrow_stream_by_id(
405 struct bt_trace *trace, uint64_t id)
406 {
407 struct bt_stream *stream = NULL;
408 uint64_t i;
409
410 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
411
412 for (i = 0; i < trace->streams->len; i++) {
413 struct bt_stream *stream_candidate =
414 g_ptr_array_index(trace->streams, i);
415
416 if (stream_candidate->id == id) {
417 stream = stream_candidate;
418 goto end;
419 }
420 }
421
422 end:
423 return stream;
424 }
425
426 struct bt_private_stream *bt_private_trace_borrow_private_stream_by_id(
427 struct bt_private_trace *trace, uint64_t id)
428 {
429 return (void *) bt_trace_borrow_stream_by_id((void *) trace, id);
430 }
431
432 uint64_t bt_trace_get_stream_class_count(struct bt_trace *trace)
433 {
434 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
435 return (uint64_t) trace->stream_classes->len;
436 }
437
438 struct bt_stream_class *bt_trace_borrow_stream_class_by_index(
439 struct bt_trace *trace, uint64_t index)
440 {
441 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
442 BT_ASSERT_PRE_VALID_INDEX(index, trace->stream_classes->len);
443 return g_ptr_array_index(trace->stream_classes, index);
444 }
445
446 struct bt_private_stream_class *
447 bt_private_trace_borrow_private_stream_class_by_index(
448 struct bt_private_trace *trace, uint64_t index)
449 {
450 return (void *) bt_trace_borrow_stream_class_by_index(
451 (void *) trace, index);
452 }
453
454 struct bt_stream_class *bt_trace_borrow_stream_class_by_id(
455 struct bt_trace *trace, uint64_t id)
456 {
457 struct bt_stream_class *stream_class = NULL;
458 uint64_t i;
459
460 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
461
462 for (i = 0; i < trace->stream_classes->len; i++) {
463 struct bt_stream_class *stream_class_candidate =
464 g_ptr_array_index(trace->stream_classes, i);
465
466 if (stream_class_candidate->id == id) {
467 stream_class = stream_class_candidate;
468 goto end;
469 }
470 }
471
472 end:
473 return stream_class;
474 }
475
476 struct bt_private_stream_class *
477 bt_private_trace_borrow_private_stream_class_by_id(
478 struct bt_private_trace *trace, uint64_t id)
479 {
480 return (void *) bt_trace_borrow_stream_class_by_id((void *) trace, id);
481 }
482
483 struct bt_field_class *bt_trace_borrow_packet_header_field_class(
484 struct bt_trace *trace)
485 {
486 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
487 return trace->packet_header_fc;
488 }
489
490 int bt_private_trace_set_packet_header_private_field_class(
491 struct bt_private_trace *priv_trace,
492 struct bt_private_field_class *priv_field_class)
493 {
494 int ret;
495 struct bt_trace *trace = (void *) priv_trace;
496 struct bt_field_class *field_class = (void *) priv_field_class;
497 struct bt_resolve_field_path_context resolve_ctx = {
498 .packet_header = field_class,
499 .packet_context = NULL,
500 .event_header = NULL,
501 .event_common_context = NULL,
502 .event_specific_context = NULL,
503 .event_payload = NULL,
504 };
505
506 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
507 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
508 BT_ASSERT_PRE_TRACE_HOT(trace);
509 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
510 BT_FIELD_CLASS_TYPE_STRUCTURE,
511 "Packet header field classe is not a structure field classe: %!+F",
512 field_class);
513 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
514 if (ret) {
515 goto end;
516 }
517
518 bt_field_class_make_part_of_trace(field_class);
519 bt_object_put_ref(trace->packet_header_fc);
520 trace->packet_header_fc = bt_object_get_ref(field_class);
521 bt_field_class_freeze(field_class);
522 BT_LIB_LOGV("Set trace's packet header field classe: %!+t", trace);
523
524 end:
525 return ret;
526 }
527
528 bt_bool bt_trace_is_static(struct bt_trace *trace)
529 {
530 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
531 return (bt_bool) trace->is_static;
532 }
533
534 int bt_private_trace_make_static(struct bt_private_trace *priv_trace)
535 {
536 struct bt_trace *trace = (void *) priv_trace;
537 uint64_t i;
538
539 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
540 trace->is_static = true;
541 bt_trace_freeze(trace);
542 BT_LIB_LOGV("Trace is now static: %!+t", trace);
543
544 /* Call all the "trace is static" listeners */
545 for (i = 0; i < trace->is_static_listeners->len; i++) {
546 struct bt_trace_is_static_listener_elem elem =
547 g_array_index(trace->is_static_listeners,
548 struct bt_trace_is_static_listener_elem, i);
549
550 if (elem.func) {
551 elem.func((void *) trace, elem.data);
552 }
553 }
554
555 return 0;
556 }
557
558 int bt_private_trace_add_is_static_listener(
559 struct bt_private_trace *priv_trace,
560 bt_private_trace_is_static_listener listener,
561 bt_private_trace_listener_removed listener_removed, void *data,
562 uint64_t *listener_id)
563 {
564 struct bt_trace *trace = (void *) priv_trace;
565 uint64_t i;
566 struct bt_trace_is_static_listener_elem new_elem = {
567 .func = listener,
568 .removed = listener_removed,
569 .data = data,
570 };
571
572 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
573 BT_ASSERT_PRE_NON_NULL(listener, "Listener");
574 BT_ASSERT_PRE(!trace->is_static,
575 "Trace is already static: %!+t", trace);
576 BT_ASSERT_PRE(trace->in_remove_listener,
577 "Cannot call this function while executing a "
578 "remove listener: %!+t", trace);
579
580 /* Find the next available spot */
581 for (i = 0; i < trace->is_static_listeners->len; i++) {
582 struct bt_trace_is_static_listener_elem elem =
583 g_array_index(trace->is_static_listeners,
584 struct bt_trace_is_static_listener_elem, i);
585
586 if (!elem.func) {
587 break;
588 }
589 }
590
591 if (i == trace->is_static_listeners->len) {
592 g_array_append_val(trace->is_static_listeners, new_elem);
593 } else {
594 g_array_insert_val(trace->is_static_listeners, i, new_elem);
595 }
596
597 if (listener_id) {
598 *listener_id = i;
599 }
600
601 BT_LIB_LOGV("Added \"trace is static\" listener: "
602 "%![trace-]+t, listener-id=%" PRIu64, trace, i);
603 return 0;
604 }
605
606 BT_ASSERT_PRE_FUNC
607 static
608 bool has_listener_id(struct bt_trace *trace, uint64_t listener_id)
609 {
610 BT_ASSERT(listener_id < trace->is_static_listeners->len);
611 return (&g_array_index(trace->is_static_listeners,
612 struct bt_trace_is_static_listener_elem,
613 listener_id))->func != NULL;
614 }
615
616 int bt_private_trace_remove_is_static_listener(
617 struct bt_private_trace *priv_trace, uint64_t listener_id)
618 {
619 struct bt_trace *trace = (void *) priv_trace;
620 struct bt_trace_is_static_listener_elem *elem;
621
622 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
623 BT_ASSERT_PRE(!trace->is_static,
624 "Trace is already static: %!+t", trace);
625 BT_ASSERT_PRE(trace->in_remove_listener,
626 "Cannot call this function while executing a "
627 "remove listener: %!+t", trace);
628 BT_ASSERT_PRE(has_listener_id(trace, listener_id),
629 "Trace has no such \"trace is static\" listener ID: "
630 "%![trace-]+t, %" PRIu64, trace, listener_id);
631 elem = &g_array_index(trace->is_static_listeners,
632 struct bt_trace_is_static_listener_elem,
633 listener_id);
634 BT_ASSERT(elem->func);
635
636 if (elem->removed) {
637 /* Call remove listener */
638 BT_LIB_LOGV("Calling remove listener: "
639 "%![trace-]+t, listener-id=%" PRIu64,
640 trace, listener_id);
641 trace->in_remove_listener = true;
642 elem->removed((void *) trace, elem->data);
643 trace->in_remove_listener = false;
644 }
645
646 elem->func = NULL;
647 elem->removed = NULL;
648 elem->data = NULL;
649 BT_LIB_LOGV("Removed \"trace is static\" listener: "
650 "%![trace-]+t, listener-id=%" PRIu64,
651 trace, listener_id);
652 return 0;
653 }
654
655 BT_HIDDEN
656 void _bt_trace_freeze(struct bt_trace *trace)
657 {
658 /* The packet header field classe is already frozen */
659 BT_ASSERT(trace);
660 BT_LIB_LOGD("Freezing trace: %!+t", trace);
661 trace->frozen = true;
662 }
663
664 bt_bool bt_trace_assigns_automatic_stream_class_id(struct bt_trace *trace)
665 {
666 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
667 return (bt_bool) trace->assigns_automatic_stream_class_id;
668 }
669
670 int bt_private_trace_set_assigns_automatic_stream_class_id(
671 struct bt_private_trace *priv_trace, bt_bool value)
672 {
673 struct bt_trace *trace = (void *) priv_trace;
674
675 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
676 BT_ASSERT_PRE_TRACE_HOT(trace);
677 trace->assigns_automatic_stream_class_id = (bool) value;
678 BT_LIB_LOGV("Set trace's automatic stream class ID "
679 "assignment property: %!+t", trace);
680 return 0;
681 }
682
683 BT_HIDDEN
684 void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream)
685 {
686 guint count = 0;
687
688 bt_object_set_parent(&stream->base, &trace->base);
689 g_ptr_array_add(trace->streams, stream);
690 bt_trace_freeze(trace);
691
692 if (bt_g_hash_table_contains(trace->stream_classes_stream_count,
693 stream->class)) {
694 count = GPOINTER_TO_UINT(g_hash_table_lookup(
695 trace->stream_classes_stream_count, stream->class));
696 }
697
698 g_hash_table_insert(trace->stream_classes_stream_count,
699 stream->class, GUINT_TO_POINTER(count + 1));
700 }
701
702 BT_HIDDEN
703 uint64_t bt_trace_get_automatic_stream_id(struct bt_trace *trace,
704 struct bt_stream_class *stream_class)
705 {
706 gpointer orig_key;
707 gpointer value;
708 uint64_t id = 0;
709
710 BT_ASSERT(stream_class);
711 BT_ASSERT(trace);
712 if (g_hash_table_lookup_extended(trace->stream_classes_stream_count,
713 stream_class, &orig_key, &value)) {
714 id = (uint64_t) GPOINTER_TO_UINT(value);
715 }
716
717 return id;
718 }
This page took 0.04398 seconds and 4 git commands to generate.