4 * Babeltrace CTF IR - Event
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "EVENT"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/ctf-ir/fields-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-ir/clock-class.h>
35 #include <babeltrace/ctf-ir/clock-value.h>
36 #include <babeltrace/ctf-ir/clock-value-internal.h>
37 #include <babeltrace/ctf-ir/clock-class-internal.h>
38 #include <babeltrace/ctf-ir/event-internal.h>
39 #include <babeltrace/ctf-ir/event-class.h>
40 #include <babeltrace/ctf-ir/event-class-internal.h>
41 #include <babeltrace/ctf-ir/stream-class.h>
42 #include <babeltrace/ctf-ir/stream-class-internal.h>
43 #include <babeltrace/ctf-ir/stream-internal.h>
44 #include <babeltrace/ctf-ir/packet.h>
45 #include <babeltrace/ctf-ir/packet-internal.h>
46 #include <babeltrace/ctf-ir/trace-internal.h>
47 #include <babeltrace/ctf-ir/validation-internal.h>
48 #include <babeltrace/ctf-ir/packet-internal.h>
49 #include <babeltrace/ctf-ir/utils.h>
50 #include <babeltrace/ctf-writer/serialize-internal.h>
51 #include <babeltrace/ctf-writer/clock-internal.h>
52 #include <babeltrace/ref.h>
53 #include <babeltrace/ctf-ir/attributes-internal.h>
54 #include <babeltrace/compiler-internal.h>
55 #include <babeltrace/assert-internal.h>
56 #include <babeltrace/assert-pre-internal.h>
59 #define BT_ASSERT_PRE_EVENT_HOT(_event, _name) \
60 BT_ASSERT_PRE_HOT((_event), (_name), ": +%!+e", (_event))
63 void bt_event_destroy(struct bt_object
*obj
);
65 struct bt_event
*bt_event_create(struct bt_event_class
*event_class
)
68 enum bt_validation_flag validation_flags
=
69 BT_VALIDATION_FLAG_STREAM
|
70 BT_VALIDATION_FLAG_EVENT
;
71 struct bt_event
*event
= NULL
;
72 struct bt_trace
*trace
= NULL
;
73 struct bt_stream_class
*stream_class
= NULL
;
74 struct bt_field_type
*packet_header_type
= NULL
;
75 struct bt_field_type
*packet_context_type
= NULL
;
76 struct bt_field_type
*event_header_type
= NULL
;
77 struct bt_field_type
*stream_event_ctx_type
= NULL
;
78 struct bt_field_type
*event_context_type
= NULL
;
79 struct bt_field_type
*event_payload_type
= NULL
;
80 struct bt_field
*event_header
= NULL
;
81 struct bt_field
*stream_event_context
= NULL
;
82 struct bt_field
*event_context
= NULL
;
83 struct bt_field
*event_payload
= NULL
;
84 struct bt_value
*environment
= NULL
;
85 struct bt_validation_output validation_output
= { 0 };
87 struct bt_clock_class
*expected_clock_class
= NULL
;
89 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
90 BT_LOGD("Creating event object: event-class-addr=%p, "
91 "event-class-name=\"%s\", event-class-id=%" PRId64
,
92 event_class
, bt_event_class_get_name(event_class
),
93 bt_event_class_get_id(event_class
));
95 stream_class
= bt_event_class_get_stream_class(event_class
);
96 BT_ASSERT_PRE(stream_class
,
97 "Event class is not part of a stream class: %!+E", event_class
);
99 /* The event class was frozen when added to its stream class */
100 BT_ASSERT(event_class
->frozen
);
102 if (!stream_class
->frozen
) {
103 if (stream_class
->clock
) {
104 expected_clock_class
=
105 bt_get(stream_class
->clock
->clock_class
);
109 * Because this function freezes the stream class,
110 * validate that this stream class contains at most a
111 * single clock class so that we set its expected clock
112 * class for future checks.
114 ret
= bt_stream_class_validate_single_clock_class(
115 stream_class
, &expected_clock_class
);
117 BT_LOGW("Event class's stream class or one of its event "
118 "classes contains a field type which is not "
119 "recursively mapped to the expected "
121 "stream-class-addr=%p, "
122 "stream-class-id=%" PRId64
", "
123 "stream-class-name=\"%s\", "
124 "expected-clock-class-addr=%p, "
125 "expected-clock-class-name=\"%s\"",
126 stream_class
, bt_stream_class_get_id(stream_class
),
127 bt_stream_class_get_name(stream_class
),
128 expected_clock_class
,
129 expected_clock_class
?
130 bt_clock_class_get_name(expected_clock_class
) :
136 /* Validate the trace (if any), the stream class, and the event class */
137 trace
= bt_stream_class_get_trace(stream_class
);
139 BT_LOGD_STR("Event's class is part of a trace.");
140 packet_header_type
= bt_trace_get_packet_header_type(trace
);
141 trace_valid
= trace
->valid
;
142 BT_ASSERT(trace_valid
);
143 environment
= trace
->environment
;
146 packet_context_type
= bt_stream_class_get_packet_context_type(
148 event_header_type
= bt_stream_class_get_event_header_type(
150 stream_event_ctx_type
= bt_stream_class_get_event_context_type(
152 event_context_type
= bt_event_class_get_context_type(event_class
);
153 event_payload_type
= bt_event_class_get_payload_type(event_class
);
154 ret
= bt_validate_class_types(environment
, packet_header_type
,
155 packet_context_type
, event_header_type
, stream_event_ctx_type
,
156 event_context_type
, event_payload_type
, trace_valid
,
157 stream_class
->valid
, event_class
->valid
,
158 &validation_output
, validation_flags
);
159 BT_PUT(packet_header_type
);
160 BT_PUT(packet_context_type
);
161 BT_PUT(event_header_type
);
162 BT_PUT(stream_event_ctx_type
);
163 BT_PUT(event_context_type
);
164 BT_PUT(event_payload_type
);
167 * This means something went wrong during the validation
168 * process, not that the objects are invalid.
170 BT_LOGE("Failed to validate event and parents: ret=%d", ret
);
174 if ((validation_output
.valid_flags
& validation_flags
) !=
176 /* Invalid trace/stream class/event class */
177 BT_LOGW("Invalid trace, stream class, or event class: "
178 "valid-flags=0x%x", validation_output
.valid_flags
);
183 * Safe to automatically map selected fields to the stream's
184 * clock's class here because the stream class is about to be
187 if (bt_stream_class_map_clock_class(stream_class
,
188 validation_output
.packet_context_type
,
189 validation_output
.event_header_type
)) {
190 BT_LOGW_STR("Cannot automatically map selected stream class's "
191 "field types to stream class's clock's class.");
196 * At this point we know the trace (if associated to the stream
197 * class), the stream class, and the event class, with their
198 * current types, are valid. We may proceed with creating
201 event
= g_new0(struct bt_event
, 1);
203 BT_LOGE_STR("Failed to allocate one event.");
207 bt_object_init(event
, bt_event_destroy
);
210 * event does not share a common ancestor with the event class; it has
211 * to guarantee its existence by holding a reference. This reference
212 * shall be released once the event is associated to a stream since,
213 * from that point, the event and its class will share the same
216 event
->event_class
= bt_get(event_class
);
217 event
->clock_values
= g_hash_table_new_full(g_direct_hash
,
218 g_direct_equal
, bt_put
, bt_put
);
220 if (validation_output
.event_header_type
) {
221 BT_LOGD("Creating initial event header field: ft-addr=%p",
222 validation_output
.event_header_type
);
224 bt_field_create(validation_output
.event_header_type
);
226 BT_LOGE_STR("Cannot create initial event header field object.");
231 if (validation_output
.stream_event_ctx_type
) {
232 BT_LOGD("Creating initial stream event context field: ft-addr=%p",
233 validation_output
.stream_event_ctx_type
);
234 stream_event_context
= bt_field_create(
235 validation_output
.stream_event_ctx_type
);
236 if (!stream_event_context
) {
237 BT_LOGE_STR("Cannot create initial stream event context field object.");
242 if (validation_output
.event_context_type
) {
243 BT_LOGD("Creating initial event context field: ft-addr=%p",
244 validation_output
.event_context_type
);
245 event_context
= bt_field_create(
246 validation_output
.event_context_type
);
247 if (!event_context
) {
248 BT_LOGE_STR("Cannot create initial event context field object.");
253 if (validation_output
.event_payload_type
) {
254 BT_LOGD("Creating initial event payload field: ft-addr=%p",
255 validation_output
.event_payload_type
);
256 event_payload
= bt_field_create(
257 validation_output
.event_payload_type
);
258 if (!event_payload
) {
259 BT_LOGE_STR("Cannot create initial event payload field object.");
265 * At this point all the fields are created, potentially from
266 * validated copies of field types, so that the field types and
267 * fields can be replaced in the trace, stream class,
268 * event class, and created event.
270 bt_validation_replace_types(trace
, stream_class
,
271 event_class
, &validation_output
, validation_flags
);
272 BT_MOVE(event
->event_header
, event_header
);
273 BT_MOVE(event
->stream_event_context
, stream_event_context
);
274 BT_MOVE(event
->context_payload
, event_context
);
275 BT_MOVE(event
->fields_payload
, event_payload
);
278 * Put what was not moved in bt_validation_replace_types().
280 bt_validation_output_put_types(&validation_output
);
283 * Freeze the stream class since the event header must not be changed
286 bt_stream_class_freeze(stream_class
);
289 * It is safe to set the stream class's unique clock class
290 * now because the stream class is frozen.
292 if (expected_clock_class
) {
293 BT_MOVE(stream_class
->clock_class
, expected_clock_class
);
297 * Mark stream class, and event class as valid since
298 * they're all frozen now.
300 stream_class
->valid
= 1;
301 event_class
->valid
= 1;
303 /* Put stuff we borrowed from the event class */
304 BT_PUT(stream_class
);
306 BT_LOGD("Created event object: addr=%p, event-class-name=\"%s\", "
307 "event-class-id=%" PRId64
,
308 event
, bt_event_class_get_name(event
->event_class
),
309 bt_event_class_get_id(event_class
));
313 bt_validation_output_put_types(&validation_output
);
315 BT_PUT(stream_class
);
317 BT_PUT(event_header
);
318 BT_PUT(stream_event_context
);
319 BT_PUT(event_context
);
320 BT_PUT(event_payload
);
321 bt_put(expected_clock_class
);
322 BT_ASSERT(!packet_header_type
);
323 BT_ASSERT(!packet_context_type
);
324 BT_ASSERT(!event_header_type
);
325 BT_ASSERT(!stream_event_ctx_type
);
326 BT_ASSERT(!event_context_type
);
327 BT_ASSERT(!event_payload_type
);
331 struct bt_event_class
*bt_event_get_class(struct bt_event
*event
)
333 BT_ASSERT_PRE_NON_NULL(event
, "Event");
334 return bt_get(bt_event_borrow_event_class(event
));
338 struct bt_stream
*bt_event_borrow_stream(struct bt_event
*event
)
340 struct bt_stream
*stream
= NULL
;
345 * If the event has a parent, then this is its (writer) stream.
346 * If the event has no parent, then if it has a packet, this
347 * is its (non-writer) stream.
349 if (event
->base
.parent
) {
350 stream
= (struct bt_stream
*) bt_object_borrow_parent(event
);
353 stream
= event
->packet
->stream
;
360 struct bt_stream
*bt_event_get_stream(struct bt_event
*event
)
362 BT_ASSERT_PRE_NON_NULL(event
, "Event");
363 return bt_get(bt_event_borrow_stream(event
));
366 int bt_event_set_payload(struct bt_event
*event
, const char *name
,
367 struct bt_field
*payload
)
371 BT_ASSERT_PRE_NON_NULL(event
, "Event");
372 BT_ASSERT_PRE_NON_NULL(payload
, "Payload field");
373 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
376 ret
= bt_field_structure_set_field_by_name(
377 event
->fields_payload
, name
, payload
);
379 BT_ASSERT_PRE(bt_field_type_compare(payload
->type
,
380 event
->event_class
->fields
) == 0,
381 "Payload field's type is different from the "
382 "expected field type: %![event-]+e, %![ft-]+F, "
383 "%![expected-ft-]+F",
384 event
, payload
->type
, event
->event_class
->fields
);
386 bt_put(event
->fields_payload
);
388 event
->fields_payload
= payload
;
392 BT_LOGW("Failed to set event's payload field: event-addr=%p, "
393 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
394 "payload-field-name=\"%s\", payload-field-addr=%p",
395 event
, bt_event_class_get_name(event
->event_class
),
396 bt_event_class_get_id(event
->event_class
),
399 BT_LOGV("Set event's payload field: event-addr=%p, "
400 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
401 "payload-field-name=\"%s\", payload-field-addr=%p",
402 event
, bt_event_class_get_name(event
->event_class
),
403 bt_event_class_get_id(event
->event_class
),
410 struct bt_field
*bt_event_get_event_payload(struct bt_event
*event
)
412 struct bt_field
*payload
= NULL
;
414 BT_ASSERT_PRE_NON_NULL(event
, "Event");
416 if (!event
->fields_payload
) {
417 BT_LOGV("Event has no current payload field: addr=%p, "
418 "event-class-name=\"%s\", event-class-id=%" PRId64
,
419 event
, bt_event_class_get_name(event
->event_class
),
420 bt_event_class_get_id(event
->event_class
));
424 payload
= event
->fields_payload
;
431 int bt_event_set_event_payload(struct bt_event
*event
,
432 struct bt_field
*payload
)
434 return bt_event_set_payload(event
, NULL
, payload
);
437 struct bt_field
*bt_event_get_payload(struct bt_event
*event
,
440 struct bt_field
*field
= NULL
;
442 BT_ASSERT_PRE_NON_NULL(event
, "Event");
445 field
= bt_field_structure_get_field_by_name(
446 event
->fields_payload
, name
);
448 field
= event
->fields_payload
;
455 struct bt_field
*bt_event_get_payload_by_index(
456 struct bt_event
*event
, uint64_t index
)
458 struct bt_field
*field
= NULL
;
460 BT_ASSERT_PRE_NON_NULL(event
, "Event");
461 field
= bt_field_structure_get_field_by_index(event
->fields_payload
,
467 struct bt_field
*bt_event_get_header(struct bt_event
*event
)
469 struct bt_field
*header
= NULL
;
471 BT_ASSERT_PRE_NON_NULL(event
, "Event");
473 if (!event
->event_header
) {
474 BT_LOGV("Event has no current header field: addr=%p, "
475 "event-class-name=\"%s\", event-class-id=%" PRId64
,
476 event
, bt_event_class_get_name(event
->event_class
),
477 bt_event_class_get_id(event
->event_class
));
481 header
= event
->event_header
;
488 int bt_event_set_header(struct bt_event
*event
, struct bt_field
*header
)
490 BT_ASSERT_PRE_NON_NULL(event
, "Event");
491 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
494 * Ensure the provided header's type matches the one registered to the
498 BT_ASSERT_PRE(bt_field_type_compare(header
->type
,
499 bt_event_class_borrow_stream_class(event
->event_class
)->event_header_type
) == 0,
500 "Header field's type is different from the "
501 "expected field type: %![event-]+e, %![ft-]+F, "
502 "%![expected-ft-]+F",
504 bt_event_class_borrow_stream_class(event
->event_class
)->event_header_type
);
506 BT_ASSERT_PRE(!bt_event_class_borrow_stream_class(event
->event_class
)->event_header_type
,
507 "Setting no event header field, "
508 "but event header field type is not NULL: ",
509 "%![event-]+e, %![header-ft-]+F",
511 bt_event_class_borrow_stream_class(event
->event_class
)->event_header_type
);
514 bt_put(event
->event_header
);
515 event
->event_header
= bt_get(header
);
516 BT_LOGV("Set event's header field: event-addr=%p, "
517 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
518 "header-field-addr=%p",
519 event
, bt_event_class_get_name(event
->event_class
),
520 bt_event_class_get_id(event
->event_class
), header
);
524 struct bt_field
*bt_event_get_event_context(struct bt_event
*event
)
526 struct bt_field
*context
= NULL
;
528 BT_ASSERT_PRE_NON_NULL(event
, "Event");
530 if (!event
->context_payload
) {
531 BT_LOGV("Event has no current context field: addr=%p, "
532 "event-class-name=\"%s\", event-class-id=%" PRId64
,
533 event
, bt_event_class_get_name(event
->event_class
),
534 bt_event_class_get_id(event
->event_class
));
538 context
= event
->context_payload
;
545 int bt_event_set_event_context(struct bt_event
*event
, struct bt_field
*context
)
547 BT_ASSERT_PRE_NON_NULL(event
, "Event");
548 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
551 BT_ASSERT_PRE(bt_field_type_compare(context
->type
,
552 event
->event_class
->context
) == 0,
553 "Context field's type is different from the "
554 "expected field type: %![event-]+e, %![ft-]+F, "
555 "%![expected-ft-]+F",
556 event
, context
->type
, event
->event_class
->context
);
558 BT_ASSERT_PRE(!event
->event_class
->context
,
559 "Setting no event context field, "
560 "but event context field type is not NULL: ",
561 "%![event-]+e, %![context-ft-]+F",
562 event
, event
->event_class
->context
);
565 bt_put(event
->context_payload
);
566 event
->context_payload
= bt_get(context
);
567 BT_LOGV("Set event's context field: event-addr=%p, "
568 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
569 "context-field-addr=%p",
570 event
, bt_event_class_get_name(event
->event_class
),
571 bt_event_class_get_id(event
->event_class
), context
);
575 struct bt_field
*bt_event_get_stream_event_context(
576 struct bt_event
*event
)
578 struct bt_field
*stream_event_context
= NULL
;
580 BT_ASSERT_PRE_NON_NULL(event
, "Event");
582 if (!event
->stream_event_context
) {
583 BT_LOGV("Event has no current stream event context field: addr=%p, "
584 "event-class-name=\"%s\", event-class-id=%" PRId64
,
585 event
, bt_event_class_get_name(event
->event_class
),
586 bt_event_class_get_id(event
->event_class
));
590 stream_event_context
= event
->stream_event_context
;
593 return bt_get(stream_event_context
);
596 int bt_event_set_stream_event_context(struct bt_event
*event
,
597 struct bt_field
*stream_event_context
)
599 BT_ASSERT_PRE_NON_NULL(event
, "Event");
600 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
602 if (stream_event_context
) {
603 BT_ASSERT_PRE(bt_field_type_compare(stream_event_context
->type
,
604 bt_event_class_borrow_stream_class(event
->event_class
)->event_context_type
) == 0,
605 "Stream event context field's type is different from the "
606 "expected field type: %![event-]+e, %![ft-]+F, "
607 "%![expected-ft-]+F",
608 event
, stream_event_context
->type
,
609 bt_event_class_borrow_stream_class(event
->event_class
)->event_context_type
);
611 BT_ASSERT_PRE(!bt_event_class_borrow_stream_class(event
->event_class
)->event_context_type
,
612 "Setting no stream event context field, "
613 "but stream event context field type is not NULL: ",
614 "%![event-]+e, %![context-ft-]+F",
616 bt_event_class_borrow_stream_class(event
->event_class
)->event_context_type
);
619 bt_get(stream_event_context
);
620 BT_MOVE(event
->stream_event_context
, stream_event_context
);
621 BT_LOGV("Set event's stream event context field: event-addr=%p, "
622 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
623 "stream-event-context-field-addr=%p",
624 event
, bt_event_class_get_name(event
->event_class
),
625 bt_event_class_get_id(event
->event_class
),
626 stream_event_context
);
630 /* Pre-2.0 CTF writer backward compatibility */
631 void bt_ctf_event_get(struct bt_event
*event
)
636 /* Pre-2.0 CTF writer backward compatibility */
637 void bt_ctf_event_put(struct bt_event
*event
)
642 void bt_event_destroy(struct bt_object
*obj
)
644 struct bt_event
*event
;
646 event
= container_of(obj
, struct bt_event
, base
);
647 BT_LOGD("Destroying event: addr=%p, "
648 "event-class-name=\"%s\", event-class-id=%" PRId64
,
649 event
, bt_event_class_get_name(event
->event_class
),
650 bt_event_class_get_id(event
->event_class
));
652 if (!event
->base
.parent
) {
654 * Event was keeping a reference to its class since it shared no
655 * common ancestor with it to guarantee they would both have the
658 bt_put(event
->event_class
);
660 g_hash_table_destroy(event
->clock_values
);
661 BT_LOGD_STR("Putting event's header field.");
662 bt_put(event
->event_header
);
663 BT_LOGD_STR("Putting event's stream event context field.");
664 bt_put(event
->stream_event_context
);
665 BT_LOGD_STR("Putting event's context field.");
666 bt_put(event
->context_payload
);
667 BT_LOGD_STR("Putting event's payload field.");
668 bt_put(event
->fields_payload
);
669 BT_LOGD_STR("Putting event's packet.");
670 bt_put(event
->packet
);
674 struct bt_clock_value
*bt_event_get_clock_value(
675 struct bt_event
*event
, struct bt_clock_class
*clock_class
)
677 struct bt_clock_value
*clock_value
= NULL
;
679 BT_ASSERT_PRE_NON_NULL(event
, "Event");
680 BT_ASSERT_PRE_NON_NULL(clock_class
, "Clock class");
681 clock_value
= g_hash_table_lookup(event
->clock_values
, clock_class
);
683 BT_LOGV("No clock value associated to the given clock class: "
684 "event-addr=%p, event-class-name=\"%s\", "
685 "event-class-id=%" PRId64
", clock-class-addr=%p, "
686 "clock-class-name=\"%s\"", event
,
687 bt_event_class_get_name(event
->event_class
),
688 bt_event_class_get_id(event
->event_class
),
689 clock_class
, bt_clock_class_get_name(clock_class
));
699 int bt_event_set_clock_value(struct bt_event
*event
,
700 struct bt_clock_value
*value
)
702 struct bt_trace
*trace
;
703 struct bt_stream_class
*stream_class
;
704 struct bt_event_class
*event_class
;
705 struct bt_clock_class
*clock_class
= NULL
;
707 BT_ASSERT_PRE_NON_NULL(event
, "Event");
708 BT_ASSERT_PRE_NON_NULL(value
, "Clock value");
709 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
710 clock_class
= bt_clock_value_get_class(value
);
711 event_class
= bt_event_borrow_event_class(event
);
712 BT_ASSERT(event_class
);
713 stream_class
= bt_event_class_borrow_stream_class(event_class
);
714 BT_ASSERT(stream_class
);
715 trace
= bt_stream_class_borrow_trace(stream_class
);
717 BT_ASSERT_PRE(bt_trace_has_clock_class(trace
, clock_class
),
718 "Clock class is not part of event's trace: "
719 "%![event-]+e, %![clock-class-]+K",
721 g_hash_table_insert(event
->clock_values
, clock_class
, bt_get(value
));
722 BT_LOGV("Set event's clock value: "
723 "event-addr=%p, event-class-name=\"%s\", "
724 "event-class-id=%" PRId64
", clock-class-addr=%p, "
725 "clock-class-name=\"%s\", clock-value-addr=%p, "
726 "clock-value-cycles=%" PRIu64
,
727 event
, bt_event_class_get_name(event
->event_class
),
728 bt_event_class_get_id(event
->event_class
),
729 clock_class
, bt_clock_class_get_name(clock_class
),
730 value
, value
->value
);
737 int _bt_event_validate(struct bt_event
*event
)
740 struct bt_stream_class
*stream_class
;
743 if (event
->event_header
) {
744 ret
= bt_field_validate_recursive(event
->event_header
);
746 BT_ASSERT_PRE_MSG("Invalid event's header field: "
747 "%![event-]+e, %![field-]+f",
748 event
, event
->event_header
);
753 stream_class
= bt_event_class_borrow_stream_class(event
->event_class
);
756 * We should not have been able to create the event without associating
757 * the event class to a stream class.
759 BT_ASSERT(stream_class
);
761 if (stream_class
->event_context_type
) {
762 ret
= bt_field_validate_recursive(event
->stream_event_context
);
764 BT_ASSERT_PRE_MSG("Invalid event's stream event context field: "
765 "%![event-]+e, %![field-]+f",
766 event
, event
->stream_event_context
);
771 if (event
->event_class
->context
) {
772 ret
= bt_field_validate_recursive(event
->context_payload
);
774 BT_ASSERT_PRE_MSG("Invalid event's payload field: "
775 "%![event-]+e, %![field-]+f",
776 event
, event
->context_payload
);
781 ret
= bt_field_validate_recursive(event
->fields_payload
);
783 BT_ASSERT_PRE_MSG("Invalid event's payload field: "
784 "%![event-]+e, %![field-]+f",
785 event
, event
->fields_payload
);
794 int bt_event_serialize(struct bt_event
*event
, struct bt_stream_pos
*pos
,
795 enum bt_byte_order native_byte_order
)
802 BT_LOGV_STR("Serializing event's context field.");
803 if (event
->context_payload
) {
804 ret
= bt_field_serialize_recursive(event
->context_payload
, pos
,
807 BT_LOGW("Cannot serialize event's context field: "
808 "event-addr=%p, event-class-name=\"%s\", "
809 "event-class-id=%" PRId64
,
811 bt_event_class_get_name(event
->event_class
),
812 bt_event_class_get_id(event
->event_class
));
817 BT_LOGV_STR("Serializing event's payload field.");
818 if (event
->fields_payload
) {
819 ret
= bt_field_serialize_recursive(event
->fields_payload
, pos
,
822 BT_LOGW("Cannot serialize event's payload field: "
823 "event-addr=%p, event-class-name=\"%s\", "
824 "event-class-id=%" PRId64
,
826 bt_event_class_get_name(event
->event_class
),
827 bt_event_class_get_id(event
->event_class
));
835 struct bt_packet
*bt_event_get_packet(struct bt_event
*event
)
837 struct bt_packet
*packet
= NULL
;
839 BT_ASSERT_PRE_NON_NULL(event
, "Event");
840 if (!event
->packet
) {
841 BT_LOGV("Event has no current packet: addr=%p, "
842 "event-class-name=\"%s\", event-class-id=%" PRId64
,
843 event
, bt_event_class_get_name(event
->event_class
),
844 bt_event_class_get_id(event
->event_class
));
848 packet
= bt_get(event
->packet
);
854 int bt_event_set_packet(struct bt_event
*event
,
855 struct bt_packet
*packet
)
857 BT_ASSERT_PRE_NON_NULL(event
, "Event");
858 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
859 BT_ASSERT_PRE_EVENT_HOT(event
, "Event");
862 * Make sure the new packet was created by this event's
863 * stream, if it is set.
865 if (bt_event_borrow_stream(event
)) {
866 BT_ASSERT_PRE(packet
->stream
== bt_event_borrow_stream(event
),
867 "Packet's stream and event's stream differ: "
868 "%![event-]+e, %![packet-]+a",
871 BT_ASSERT_PRE(bt_event_class_borrow_stream_class(event
->event_class
) ==
872 packet
->stream
->stream_class
,
873 "Packet's stream class and event's stream class differ: "
874 "%![event-]+e, %![packet-]+a",
879 BT_MOVE(event
->packet
, packet
);
880 BT_LOGV("Set event's packet: event-addr=%p, "
881 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
883 event
, bt_event_class_get_name(event
->event_class
),
884 bt_event_class_get_id(event
->event_class
), packet
);
889 void _bt_event_freeze(struct bt_event
*event
)
897 BT_LOGD("Freezing event: addr=%p, "
898 "event-class-name=\"%s\", event-class-id=%" PRId64
,
899 event
, bt_event_class_get_name(event
->event_class
),
900 bt_event_class_get_id(event
->event_class
));
901 bt_packet_freeze(event
->packet
);
902 BT_LOGD_STR("Freezing event's header field.");
903 bt_field_freeze_recursive(event
->event_header
);
904 BT_LOGD_STR("Freezing event's stream event context field.");
905 bt_field_freeze_recursive(event
->stream_event_context
);
906 BT_LOGD_STR("Freezing event's context field.");
907 bt_field_freeze_recursive(event
->context_payload
);
908 BT_LOGD_STR("Freezing event's payload field.");
909 bt_field_freeze_recursive(event
->fields_payload
);