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-class-internal.h>
36 #include <babeltrace/ctf-ir/event-internal.h>
37 #include <babeltrace/ctf-ir/event-class.h>
38 #include <babeltrace/ctf-ir/event-class-internal.h>
39 #include <babeltrace/ctf-ir/stream-class.h>
40 #include <babeltrace/ctf-ir/stream-class-internal.h>
41 #include <babeltrace/ctf-ir/stream-internal.h>
42 #include <babeltrace/ctf-ir/packet.h>
43 #include <babeltrace/ctf-ir/packet-internal.h>
44 #include <babeltrace/ctf-ir/trace-internal.h>
45 #include <babeltrace/ctf-ir/validation-internal.h>
46 #include <babeltrace/ctf-ir/packet-internal.h>
47 #include <babeltrace/ctf-ir/utils.h>
48 #include <babeltrace/ctf-writer/serialize-internal.h>
49 #include <babeltrace/ref.h>
50 #include <babeltrace/ctf-ir/attributes-internal.h>
51 #include <babeltrace/compiler-internal.h>
55 void bt_ctf_event_destroy(struct bt_object
*obj
);
57 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
60 enum bt_ctf_validation_flag validation_flags
=
61 BT_CTF_VALIDATION_FLAG_STREAM
|
62 BT_CTF_VALIDATION_FLAG_EVENT
;
63 struct bt_ctf_event
*event
= NULL
;
64 struct bt_ctf_trace
*trace
= NULL
;
65 struct bt_ctf_stream_class
*stream_class
= NULL
;
66 struct bt_ctf_field_type
*packet_header_type
= NULL
;
67 struct bt_ctf_field_type
*packet_context_type
= NULL
;
68 struct bt_ctf_field_type
*event_header_type
= NULL
;
69 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
70 struct bt_ctf_field_type
*event_context_type
= NULL
;
71 struct bt_ctf_field_type
*event_payload_type
= NULL
;
72 struct bt_ctf_field
*event_header
= NULL
;
73 struct bt_ctf_field
*stream_event_context
= NULL
;
74 struct bt_ctf_field
*event_context
= NULL
;
75 struct bt_ctf_field
*event_payload
= NULL
;
76 struct bt_value
*environment
= NULL
;
77 struct bt_ctf_validation_output validation_output
= { 0 };
80 BT_LOGD("Creating event object: event-class-addr=%p, "
81 "event-class-name=\"%s\", event-class-id=%" PRId64
,
82 event_class
, bt_ctf_event_class_get_name(event_class
),
83 bt_ctf_event_class_get_id(event_class
));
86 BT_LOGW_STR("Invalid parameter: event class is NULL.");
90 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
93 * We disallow the creation of an event if its event class has not been
94 * associated to a stream class.
97 BT_LOGW("Event class is not part of a stream class: "
98 "addr=%p, event-class-name=\"%s\", "
99 "event-class-id=%" PRId64
,
100 event
, bt_ctf_event_class_get_name(event
->event_class
),
101 bt_ctf_event_class_get_id(event_class
));
105 /* A stream class should always have an existing event header type */
106 assert(stream_class
->event_header_type
);
108 /* The event class was frozen when added to its stream class */
109 assert(event_class
->frozen
);
111 /* Validate the trace (if any), the stream class, and the event class */
112 trace
= bt_ctf_stream_class_get_trace(stream_class
);
114 BT_LOGD("Event's class is part of a trace: "
115 "event-class-name=\"%s\", event-class-id=%" PRId64
,
116 bt_ctf_event_class_get_name(event_class
),
117 bt_ctf_event_class_get_id(event_class
));
118 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
119 trace_valid
= trace
->valid
;
121 environment
= trace
->environment
;
124 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(
126 event_header_type
= bt_ctf_stream_class_get_event_header_type(
128 stream_event_ctx_type
= bt_ctf_stream_class_get_event_context_type(
130 event_context_type
= bt_ctf_event_class_get_context_type(event_class
);
131 event_payload_type
= bt_ctf_event_class_get_payload_type(event_class
);
132 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
133 packet_context_type
, event_header_type
, stream_event_ctx_type
,
134 event_context_type
, event_payload_type
, trace_valid
,
135 stream_class
->valid
, event_class
->valid
,
136 &validation_output
, validation_flags
);
137 BT_PUT(packet_header_type
);
138 BT_PUT(packet_context_type
);
139 BT_PUT(event_header_type
);
140 BT_PUT(stream_event_ctx_type
);
141 BT_PUT(event_context_type
);
142 BT_PUT(event_payload_type
);
145 * This means something went wrong during the validation
146 * process, not that the objects are invalid.
148 BT_LOGE("Failed to validate event: addr=%p, event-class-name=\"%s\", "
149 "event-class-id=%" PRId64
,
150 event
, bt_ctf_event_class_get_name(event
->event_class
),
151 bt_ctf_event_class_get_id(event_class
));
155 if ((validation_output
.valid_flags
& validation_flags
) !=
157 /* Invalid trace/stream class/event class */
158 BT_LOGE("Invalid trace, stream class, or event class: "
159 "event-addr=%p, event-class-name=\"%s\", "
160 "event-class-id=%" PRId64
", valid-flags=0x%x",
161 event
, bt_ctf_event_class_get_name(event
->event_class
),
162 bt_ctf_event_class_get_id(event_class
),
163 validation_output
.valid_flags
);
168 * At this point we know the trace (if associated to the stream
169 * class), the stream class, and the event class, with their
170 * current types, are valid. We may proceed with creating
173 event
= g_new0(struct bt_ctf_event
, 1);
175 BT_LOGE_STR("Failed to allocate one event.");
179 bt_object_init(event
, bt_ctf_event_destroy
);
182 * event does not share a common ancestor with the event class; it has
183 * to guarantee its existence by holding a reference. This reference
184 * shall be released once the event is associated to a stream since,
185 * from that point, the event and its class will share the same
188 event
->event_class
= bt_get(event_class
);
189 event
->clock_values
= g_hash_table_new_full(g_direct_hash
,
190 g_direct_equal
, bt_put
, bt_put
);
192 bt_ctf_field_create(validation_output
.event_header_type
);
194 BT_LOGE_STR("Cannot create initial event header field object.");
198 if (validation_output
.stream_event_ctx_type
) {
199 stream_event_context
= bt_ctf_field_create(
200 validation_output
.stream_event_ctx_type
);
201 if (!stream_event_context
) {
202 BT_LOGE_STR("Cannot create initial stream event context field object.");
207 if (validation_output
.event_context_type
) {
208 event_context
= bt_ctf_field_create(
209 validation_output
.event_context_type
);
210 if (!event_context
) {
211 BT_LOGE_STR("Cannot create initial event context field object.");
216 if (validation_output
.event_payload_type
) {
217 event_payload
= bt_ctf_field_create(
218 validation_output
.event_payload_type
);
219 if (!event_payload
) {
220 BT_LOGE_STR("Cannot create initial event payload field object.");
226 * At this point all the fields are created, potentially from
227 * validated copies of field types, so that the field types and
228 * fields can be replaced in the trace, stream class,
229 * event class, and created event.
231 bt_ctf_validation_replace_types(trace
, stream_class
,
232 event_class
, &validation_output
, validation_flags
);
233 BT_MOVE(event
->event_header
, event_header
);
234 BT_MOVE(event
->stream_event_context
, stream_event_context
);
235 BT_MOVE(event
->context_payload
, event_context
);
236 BT_MOVE(event
->fields_payload
, event_payload
);
239 * Put what was not moved in bt_ctf_validation_replace_types().
241 bt_ctf_validation_output_put_types(&validation_output
);
244 * Freeze the stream class since the event header must not be changed
247 bt_ctf_stream_class_freeze(stream_class
);
250 * Mark stream class, and event class as valid since
251 * they're all frozen now.
253 stream_class
->valid
= 1;
254 event_class
->valid
= 1;
256 /* Put stuff we borrowed from the event class */
257 BT_PUT(stream_class
);
259 BT_LOGD("Created event object: addr=%p, event-class-name=\"%s\", "
260 "event-class-id=%" PRId64
,
261 event
, bt_ctf_event_class_get_name(event
->event_class
),
262 bt_ctf_event_class_get_id(event_class
));
266 bt_ctf_validation_output_put_types(&validation_output
);
268 BT_PUT(stream_class
);
270 BT_PUT(event_header
);
271 BT_PUT(stream_event_context
);
272 BT_PUT(event_context
);
273 BT_PUT(event_payload
);
274 assert(!packet_header_type
);
275 assert(!packet_context_type
);
276 assert(!event_header_type
);
277 assert(!stream_event_ctx_type
);
278 assert(!event_context_type
);
279 assert(!event_payload_type
);
284 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
286 struct bt_ctf_event_class
*event_class
= NULL
;
289 BT_LOGW_STR("Invalid parameter: event is NULL.");
293 event_class
= event
? bt_get(bt_ctf_event_borrow_event_class(event
)) :
299 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
301 struct bt_ctf_stream
*stream
= NULL
;
304 BT_LOGW_STR("Invalid parameter: event is NULL.");
309 * If the event has a parent, then this is its (writer) stream.
310 * If the event has no parent, then if it has a packet, this
311 * is its (non-writer) stream.
313 if (event
->base
.parent
) {
314 stream
= (struct bt_ctf_stream
*) bt_object_get_parent(event
);
317 stream
= bt_get(event
->packet
->stream
);
325 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
,
327 struct bt_ctf_field
*payload
)
331 if (!event
|| !payload
) {
332 BT_LOGW("Invalid parameter: event or payload field is NULL: "
333 "event-addr=%p, payload-field-addr=%p",
340 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
341 "event-class-name=\"%s\", event-class-id=%" PRId64
,
342 event
, bt_ctf_event_class_get_name(event
->event_class
),
343 bt_ctf_event_class_get_id(event
->event_class
));
349 ret
= bt_ctf_field_structure_set_field(event
->fields_payload
,
352 struct bt_ctf_field_type
*payload_type
;
354 payload_type
= bt_ctf_field_get_type(payload
);
356 if (bt_ctf_field_type_compare(payload_type
,
357 event
->event_class
->fields
) == 0) {
358 bt_put(event
->fields_payload
);
360 event
->fields_payload
= payload
;
362 BT_LOGW("Invalid parameter: payload field type is different from the expected field type: "
363 "event-addr=%p, event-class-name=\"%s\", "
364 "event-class-id=%" PRId64
,
366 bt_ctf_event_class_get_name(event
->event_class
),
367 bt_ctf_event_class_get_id(event
->event_class
));
371 bt_put(payload_type
);
375 BT_LOGW("Failed to set event's payload field: event-addr=%p, "
376 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
377 "payload-field-name=\"%s\", payload-field-addr=%p",
378 event
, bt_ctf_event_class_get_name(event
->event_class
),
379 bt_ctf_event_class_get_id(event
->event_class
),
382 BT_LOGV("Set event's payload field: event-addr=%p, "
383 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
384 "payload-field-name=\"%s\", payload-field-addr=%p",
385 event
, bt_ctf_event_class_get_name(event
->event_class
),
386 bt_ctf_event_class_get_id(event
->event_class
),
394 struct bt_ctf_field
*bt_ctf_event_get_event_payload(struct bt_ctf_event
*event
)
396 struct bt_ctf_field
*payload
= NULL
;
399 BT_LOGW_STR("Invalid parameter: event is NULL.");
403 if (!event
->fields_payload
) {
404 BT_LOGV("Event has no current payload field: addr=%p, "
405 "event-class-name=\"%s\", event-class-id=%" PRId64
,
406 event
, bt_ctf_event_class_get_name(event
->event_class
),
407 bt_ctf_event_class_get_id(event
->event_class
));
411 payload
= event
->fields_payload
;
417 int bt_ctf_event_set_event_payload(struct bt_ctf_event
*event
,
418 struct bt_ctf_field
*payload
)
420 return bt_ctf_event_set_payload(event
, NULL
, payload
);
423 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
426 struct bt_ctf_field
*field
= NULL
;
429 BT_LOGW_STR("Invalid parameter: event is NULL.");
434 field
= bt_ctf_field_structure_get_field(event
->fields_payload
,
437 field
= event
->fields_payload
;
444 struct bt_ctf_field
*bt_ctf_event_get_payload_by_index(
445 struct bt_ctf_event
*event
, uint64_t index
)
447 struct bt_ctf_field
*field
= NULL
;
450 BT_LOGW_STR("Invalid parameter: event is NULL.");
454 field
= bt_ctf_field_structure_get_field_by_index(event
->fields_payload
,
460 struct bt_ctf_field
*bt_ctf_event_get_header(
461 struct bt_ctf_event
*event
)
463 struct bt_ctf_field
*header
= NULL
;
466 BT_LOGW_STR("Invalid parameter: event is NULL.");
470 if (!event
->event_header
) {
471 BT_LOGV("Event has no current header field: addr=%p, "
472 "event-class-name=\"%s\", event-class-id=%" PRId64
,
473 event
, bt_ctf_event_class_get_name(event
->event_class
),
474 bt_ctf_event_class_get_id(event
->event_class
));
478 header
= event
->event_header
;
484 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
485 struct bt_ctf_field
*header
)
488 struct bt_ctf_field_type
*field_type
= NULL
;
489 struct bt_ctf_stream_class
*stream_class
= NULL
;
492 BT_LOGW_STR("Invalid parameter: event is NULL.");
498 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
499 "event-class-name=\"%s\", event-class-id=%" PRId64
,
500 event
, bt_ctf_event_class_get_name(event
->event_class
),
501 bt_ctf_event_class_get_id(event
->event_class
));
506 stream_class
= (struct bt_ctf_stream_class
*) bt_object_get_parent(
509 * Ensure the provided header's type matches the one registered to the
512 field_type
= bt_ctf_field_get_type(header
);
513 if (bt_ctf_field_type_compare(field_type
,
514 stream_class
->event_header_type
)) {
515 BT_LOGW("Invalid parameter: header field type is different from the expected field type: "
516 "event-addr=%p, event-class-name=\"%s\", "
517 "event-class-id=%" PRId64
,
519 bt_ctf_event_class_get_name(event
->event_class
),
520 bt_ctf_event_class_get_id(event
->event_class
));
525 bt_put(event
->event_header
);
526 event
->event_header
= bt_get(header
);
527 BT_LOGV("Set event's header field: event-addr=%p, "
528 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
529 "header-field-addr=%p",
530 event
, bt_ctf_event_class_get_name(event
->event_class
),
531 bt_ctf_event_class_get_id(event
->event_class
), header
);
533 bt_put(stream_class
);
538 struct bt_ctf_field
*bt_ctf_event_get_event_context(
539 struct bt_ctf_event
*event
)
541 struct bt_ctf_field
*context
= NULL
;
544 BT_LOGW_STR("Invalid parameter: event is NULL.");
548 if (!event
->context_payload
) {
549 BT_LOGV("Event has no current context field: addr=%p, "
550 "event-class-name=\"%s\", event-class-id=%" PRId64
,
551 event
, bt_ctf_event_class_get_name(event
->event_class
),
552 bt_ctf_event_class_get_id(event
->event_class
));
556 context
= event
->context_payload
;
562 int bt_ctf_event_set_event_context(struct bt_ctf_event
*event
,
563 struct bt_ctf_field
*context
)
566 struct bt_ctf_field_type
*field_type
= NULL
;
569 BT_LOGW_STR("Invalid parameter: event is NULL.");
575 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
576 "event-class-name=\"%s\", event-class-id=%" PRId64
,
577 event
, bt_ctf_event_class_get_name(event
->event_class
),
578 bt_ctf_event_class_get_id(event
->event_class
));
583 field_type
= bt_ctf_field_get_type(context
);
584 if (bt_ctf_field_type_compare(field_type
,
585 event
->event_class
->context
)) {
586 BT_LOGW("Invalid parameter: context field type is different from the expected field type: "
587 "event-addr=%p, event-class-name=\"%s\", "
588 "event-class-id=%" PRId64
,
590 bt_ctf_event_class_get_name(event
->event_class
),
591 bt_ctf_event_class_get_id(event
->event_class
));
596 bt_put(event
->context_payload
);
597 event
->context_payload
= bt_get(context
);
598 BT_LOGV("Set event's context field: event-addr=%p, "
599 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
600 "context-field-addr=%p",
601 event
, bt_ctf_event_class_get_name(event
->event_class
),
602 bt_ctf_event_class_get_id(event
->event_class
), context
);
608 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
609 struct bt_ctf_event
*event
)
611 struct bt_ctf_field
*stream_event_context
= NULL
;
614 BT_LOGW_STR("Invalid parameter: event is NULL.");
618 if (!event
->stream_event_context
) {
619 BT_LOGV("Event has no current stream event context field: addr=%p, "
620 "event-class-name=\"%s\", event-class-id=%" PRId64
,
621 event
, bt_ctf_event_class_get_name(event
->event_class
),
622 bt_ctf_event_class_get_id(event
->event_class
));
626 stream_event_context
= event
->stream_event_context
;
628 return bt_get(stream_event_context
);
631 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event
*event
,
632 struct bt_ctf_field
*stream_event_context
)
635 struct bt_ctf_field_type
*field_type
= NULL
;
636 struct bt_ctf_stream_class
*stream_class
= NULL
;
639 BT_LOGW_STR("Invalid parameter: event is NULL.");
645 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
646 "event-class-name=\"%s\", event-class-id=%" PRId64
,
647 event
, bt_ctf_event_class_get_name(event
->event_class
),
648 bt_ctf_event_class_get_id(event
->event_class
));
653 stream_class
= bt_ctf_event_class_get_stream_class(event
->event_class
);
655 * We should not have been able to create the event without associating
656 * the event class to a stream class.
658 assert(stream_class
);
660 field_type
= bt_ctf_field_get_type(stream_event_context
);
661 if (bt_ctf_field_type_compare(field_type
,
662 stream_class
->event_context_type
)) {
663 BT_LOGW("Invalid parameter: stream event context field type is different from the expected field type: "
664 "event-addr=%p, event-class-name=\"%s\", "
665 "event-class-id=%" PRId64
,
667 bt_ctf_event_class_get_name(event
->event_class
),
668 bt_ctf_event_class_get_id(event
->event_class
));
673 bt_get(stream_event_context
);
674 BT_MOVE(event
->stream_event_context
, stream_event_context
);
675 BT_LOGV("Set event's stream event context field: event-addr=%p, "
676 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
677 "stream-event-context-field-addr=%p",
678 event
, bt_ctf_event_class_get_name(event
->event_class
),
679 bt_ctf_event_class_get_id(event
->event_class
),
680 stream_event_context
);
682 BT_PUT(stream_class
);
687 /* Pre-2.0 CTF writer backward compatibility */
688 void bt_ctf_event_get(struct bt_ctf_event
*event
)
693 /* Pre-2.0 CTF writer backward compatibility */
694 void bt_ctf_event_put(struct bt_ctf_event
*event
)
699 void bt_ctf_event_destroy(struct bt_object
*obj
)
701 struct bt_ctf_event
*event
;
703 event
= container_of(obj
, struct bt_ctf_event
, base
);
704 BT_LOGD("Destroying event: addr=%p, "
705 "event-class-name=\"%s\", event-class-id=%" PRId64
,
706 event
, bt_ctf_event_class_get_name(event
->event_class
),
707 bt_ctf_event_class_get_id(event
->event_class
));
709 if (!event
->base
.parent
) {
711 * Event was keeping a reference to its class since it shared no
712 * common ancestor with it to guarantee they would both have the
715 bt_put(event
->event_class
);
717 g_hash_table_destroy(event
->clock_values
);
718 bt_put(event
->event_header
);
719 bt_put(event
->stream_event_context
);
720 bt_put(event
->context_payload
);
721 bt_put(event
->fields_payload
);
722 bt_put(event
->packet
);
726 struct bt_ctf_clock_value
*bt_ctf_event_get_clock_value(
727 struct bt_ctf_event
*event
, struct bt_ctf_clock_class
*clock_class
)
729 struct bt_ctf_clock_value
*clock_value
= NULL
;
731 if (!event
|| !clock_class
) {
732 BT_LOGW("Invalid parameter: event or clock class is NULL: "
733 "event-addr=%p, clock-class-addr=%p",
738 clock_value
= g_hash_table_lookup(event
->clock_values
, clock_class
);
740 BT_LOGV("No clock value associated to the given clock class: "
741 "event-addr=%p, event-class-name=\"%s\", "
742 "event-class-id=%" PRId64
", clock-class-addr=%p, "
743 "clock-class-name=\"%s\"", event
,
744 bt_ctf_event_class_get_name(event
->event_class
),
745 bt_ctf_event_class_get_id(event
->event_class
),
746 clock_class
, bt_ctf_clock_class_get_name(clock_class
));
755 int bt_ctf_event_set_clock_value(struct bt_ctf_event
*event
,
756 struct bt_ctf_clock_value
*value
)
759 struct bt_ctf_trace
*trace
;
760 struct bt_ctf_stream_class
*stream_class
;
761 struct bt_ctf_event_class
*event_class
;
762 struct bt_ctf_clock_class
*clock_class
= NULL
;
764 if (!event
|| !value
) {
765 BT_LOGW("Invalid parameter: event or clock value is NULL: "
766 "event-addr=%p, clock-value-addr=%p",
773 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
774 "event-class-name=\"%s\", event-class-id=%" PRId64
,
775 event
, bt_ctf_event_class_get_name(event
->event_class
),
776 bt_ctf_event_class_get_id(event
->event_class
));
781 clock_class
= bt_ctf_clock_value_get_class(value
);
782 event_class
= bt_ctf_event_borrow_event_class(event
);
784 stream_class
= bt_ctf_event_class_borrow_stream_class(event_class
);
785 assert(stream_class
);
786 trace
= bt_ctf_stream_class_borrow_trace(stream_class
);
789 if (!bt_ctf_trace_has_clock_class(trace
, clock_class
)) {
790 BT_LOGW("Invalid parameter: clock class is not part of event's trace: "
791 "event-addr=%p, event-class-name=\"%s\", "
792 "event-class-id=%" PRId64
", clock-class-addr=%p, "
793 "clock-class-name=\"%s\"",
794 event
, bt_ctf_event_class_get_name(event
->event_class
),
795 bt_ctf_event_class_get_id(event
->event_class
),
796 clock_class
, bt_ctf_clock_class_get_name(clock_class
));
801 g_hash_table_insert(event
->clock_values
, clock_class
, bt_get(value
));
802 BT_LOGV("Set event's clock value: "
803 "event-addr=%p, event-class-name=\"%s\", "
804 "event-class-id=%" PRId64
", clock-class-addr=%p, "
805 "clock-class-name=\"%s\", clock-value-addr=%p, "
806 "clock-value-cycles=%" PRIu64
,
807 event
, bt_ctf_event_class_get_name(event
->event_class
),
808 bt_ctf_event_class_get_id(event
->event_class
),
809 clock_class
, bt_ctf_clock_class_get_name(clock_class
),
810 value
, value
->value
);
819 int bt_ctf_event_validate(struct bt_ctf_event
*event
)
821 /* Make sure each field's payload has been set */
823 struct bt_ctf_stream_class
*stream_class
= NULL
;
826 ret
= bt_ctf_field_validate(event
->event_header
);
828 BT_LOGD("Invalid event's header field: "
829 "event-addr=%p, event-class-name=\"%s\", "
830 "event-class-id=%" PRId64
,
831 event
, bt_ctf_event_class_get_name(event
->event_class
),
832 bt_ctf_event_class_get_id(event
->event_class
));
836 stream_class
= bt_ctf_event_class_get_stream_class(event
->event_class
);
838 * We should not have been able to create the event without associating
839 * the event class to a stream class.
841 assert(stream_class
);
842 if (stream_class
->event_context_type
) {
843 ret
= bt_ctf_field_validate(event
->stream_event_context
);
845 BT_LOGD("Invalid event's stream event context field: "
846 "event-addr=%p, event-class-name=\"%s\", "
847 "event-class-id=%" PRId64
,
849 bt_ctf_event_class_get_name(event
->event_class
),
850 bt_ctf_event_class_get_id(event
->event_class
));
855 ret
= bt_ctf_field_validate(event
->fields_payload
);
857 BT_LOGD("Invalid event's payload field: "
858 "event-addr=%p, event-class-name=\"%s\", "
859 "event-class-id=%" PRId64
,
861 bt_ctf_event_class_get_name(event
->event_class
),
862 bt_ctf_event_class_get_id(event
->event_class
));
866 if (event
->event_class
->context
) {
867 BT_LOGD("Invalid event's context field: "
868 "event-addr=%p, event-class-name=\"%s\", "
869 "event-class-id=%" PRId64
,
871 bt_ctf_event_class_get_name(event
->event_class
),
872 bt_ctf_event_class_get_id(event
->event_class
));
873 ret
= bt_ctf_field_validate(event
->context_payload
);
876 bt_put(stream_class
);
881 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
882 struct bt_ctf_stream_pos
*pos
,
883 enum bt_ctf_byte_order native_byte_order
)
890 BT_LOGD("Serializing event: "
891 "event-addr=%p, event-class-name=\"%s\", "
892 "event-class-id=%" PRId64
", pos-addr=%p, "
894 event
, bt_ctf_event_class_get_name(event
->event_class
),
895 bt_ctf_event_class_get_id(event
->event_class
),
896 pos
, bt_ctf_field_type_byte_order_string(native_byte_order
));
898 if (event
->context_payload
) {
899 ret
= bt_ctf_field_serialize(event
->context_payload
, pos
,
902 BT_LOGE("Cannot serialize event's context field: "
903 "event-addr=%p, event-class-name=\"%s\", "
904 "event-class-id=%" PRId64
,
906 bt_ctf_event_class_get_name(event
->event_class
),
907 bt_ctf_event_class_get_id(event
->event_class
));
912 if (event
->fields_payload
) {
913 ret
= bt_ctf_field_serialize(event
->fields_payload
, pos
,
916 BT_LOGE("Cannot serialize event's payload field: "
917 "event-addr=%p, event-class-name=\"%s\", "
918 "event-class-id=%" PRId64
,
920 bt_ctf_event_class_get_name(event
->event_class
),
921 bt_ctf_event_class_get_id(event
->event_class
));
929 struct bt_ctf_packet
*bt_ctf_event_get_packet(struct bt_ctf_event
*event
)
931 struct bt_ctf_packet
*packet
= NULL
;
934 BT_LOGW_STR("Invalid parameter: event is NULL.");
938 if (!event
->packet
) {
939 BT_LOGV("Event has no current packet: addr=%p, "
940 "event-class-name=\"%s\", event-class-id=%" PRId64
,
941 event
, bt_ctf_event_class_get_name(event
->event_class
),
942 bt_ctf_event_class_get_id(event
->event_class
));
946 packet
= bt_get(event
->packet
);
951 int bt_ctf_event_set_packet(struct bt_ctf_event
*event
,
952 struct bt_ctf_packet
*packet
)
954 struct bt_ctf_stream_class
*event_stream_class
= NULL
;
955 struct bt_ctf_stream_class
*packet_stream_class
= NULL
;
956 struct bt_ctf_stream
*stream
= NULL
;
959 if (!event
|| !packet
) {
960 BT_LOGW("Invalid parameter: event or packet is NULL: "
961 "event-addr=%p, packet-addr=%p",
968 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
969 "event-class-name=\"%s\", event-class-id=%" PRId64
,
970 event
, bt_ctf_event_class_get_name(event
->event_class
),
971 bt_ctf_event_class_get_id(event
->event_class
));
977 * Make sure the new packet was created by this event's
978 * stream, if it is set.
980 stream
= bt_ctf_event_get_stream(event
);
982 if (packet
->stream
!= stream
) {
983 BT_LOGW("Invalid parameter: packet's stream and event's stream differ: "
984 "event-addr=%p, event-class-name=\"%s\", "
985 "event-class-id=%" PRId64
", packet-stream-addr=%p, "
986 "event-stream-addr=%p",
987 event
, bt_ctf_event_class_get_name(event
->event_class
),
988 bt_ctf_event_class_get_id(event
->event_class
),
989 packet
->stream
, stream
);
995 bt_ctf_event_class_get_stream_class(event
->event_class
);
996 packet_stream_class
=
997 bt_ctf_stream_get_class(packet
->stream
);
999 assert(event_stream_class
);
1000 assert(packet_stream_class
);
1002 if (event_stream_class
!= packet_stream_class
) {
1003 BT_LOGW("Invalid parameter: packet's stream class and event's stream class differ: "
1004 "event-addr=%p, event-class-name=\"%s\", "
1005 "event-class-id=%" PRId64
", packet-stream-class-addr=%p, "
1006 "event-stream-class-addr=%p",
1007 event
, bt_ctf_event_class_get_name(event
->event_class
),
1008 bt_ctf_event_class_get_id(event
->event_class
),
1009 packet_stream_class
, event_stream_class
);
1016 BT_MOVE(event
->packet
, packet
);
1017 BT_LOGV("Set event's packet: event-addr=%p, "
1018 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
1020 event
, bt_ctf_event_class_get_name(event
->event_class
),
1021 bt_ctf_event_class_get_id(event
->event_class
), packet
);
1025 BT_PUT(event_stream_class
);
1026 BT_PUT(packet_stream_class
);
1032 void bt_ctf_event_freeze(struct bt_ctf_event
*event
)
1036 if (event
->frozen
) {
1040 BT_LOGD("Freezing event: addr=%p, "
1041 "event-class-name=\"%s\", event-class-id=%" PRId64
,
1042 event
, bt_ctf_event_class_get_name(event
->event_class
),
1043 bt_ctf_event_class_get_id(event
->event_class
));
1044 bt_ctf_packet_freeze(event
->packet
);
1045 bt_ctf_field_freeze(event
->event_header
);
1046 bt_ctf_field_freeze(event
->stream_event_context
);
1047 bt_ctf_field_freeze(event
->context_payload
);
1048 bt_ctf_field_freeze(event
->fields_payload
);