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_STR("Event class is not part of a stream class.");
101 /* A stream class should always have an existing event header type */
102 assert(stream_class
->event_header_type
);
104 /* The event class was frozen when added to its stream class */
105 assert(event_class
->frozen
);
107 /* Validate the trace (if any), the stream class, and the event class */
108 trace
= bt_ctf_stream_class_get_trace(stream_class
);
110 BT_LOGD_STR("Event's class is part of a trace.");
111 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
112 trace_valid
= trace
->valid
;
114 environment
= trace
->environment
;
117 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(
119 event_header_type
= bt_ctf_stream_class_get_event_header_type(
121 stream_event_ctx_type
= bt_ctf_stream_class_get_event_context_type(
123 event_context_type
= bt_ctf_event_class_get_context_type(event_class
);
124 event_payload_type
= bt_ctf_event_class_get_payload_type(event_class
);
125 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
126 packet_context_type
, event_header_type
, stream_event_ctx_type
,
127 event_context_type
, event_payload_type
, trace_valid
,
128 stream_class
->valid
, event_class
->valid
,
129 &validation_output
, validation_flags
);
130 BT_PUT(packet_header_type
);
131 BT_PUT(packet_context_type
);
132 BT_PUT(event_header_type
);
133 BT_PUT(stream_event_ctx_type
);
134 BT_PUT(event_context_type
);
135 BT_PUT(event_payload_type
);
138 * This means something went wrong during the validation
139 * process, not that the objects are invalid.
141 BT_LOGE("Failed to validate event and parents: ret=%d", ret
);
145 if ((validation_output
.valid_flags
& validation_flags
) !=
147 /* Invalid trace/stream class/event class */
148 BT_LOGE("Invalid trace, stream class, or event class: "
149 "valid-flags=0x%x", validation_output
.valid_flags
);
154 * At this point we know the trace (if associated to the stream
155 * class), the stream class, and the event class, with their
156 * current types, are valid. We may proceed with creating
159 event
= g_new0(struct bt_ctf_event
, 1);
161 BT_LOGE_STR("Failed to allocate one event.");
165 bt_object_init(event
, bt_ctf_event_destroy
);
168 * event does not share a common ancestor with the event class; it has
169 * to guarantee its existence by holding a reference. This reference
170 * shall be released once the event is associated to a stream since,
171 * from that point, the event and its class will share the same
174 event
->event_class
= bt_get(event_class
);
175 event
->clock_values
= g_hash_table_new_full(g_direct_hash
,
176 g_direct_equal
, bt_put
, bt_put
);
178 bt_ctf_field_create(validation_output
.event_header_type
);
180 BT_LOGE_STR("Cannot create initial event header field object.");
184 if (validation_output
.stream_event_ctx_type
) {
185 stream_event_context
= bt_ctf_field_create(
186 validation_output
.stream_event_ctx_type
);
187 if (!stream_event_context
) {
188 BT_LOGE_STR("Cannot create initial stream event context field object.");
193 if (validation_output
.event_context_type
) {
194 event_context
= bt_ctf_field_create(
195 validation_output
.event_context_type
);
196 if (!event_context
) {
197 BT_LOGE_STR("Cannot create initial event context field object.");
202 if (validation_output
.event_payload_type
) {
203 event_payload
= bt_ctf_field_create(
204 validation_output
.event_payload_type
);
205 if (!event_payload
) {
206 BT_LOGE_STR("Cannot create initial event payload field object.");
212 * At this point all the fields are created, potentially from
213 * validated copies of field types, so that the field types and
214 * fields can be replaced in the trace, stream class,
215 * event class, and created event.
217 bt_ctf_validation_replace_types(trace
, stream_class
,
218 event_class
, &validation_output
, validation_flags
);
219 BT_MOVE(event
->event_header
, event_header
);
220 BT_MOVE(event
->stream_event_context
, stream_event_context
);
221 BT_MOVE(event
->context_payload
, event_context
);
222 BT_MOVE(event
->fields_payload
, event_payload
);
225 * Put what was not moved in bt_ctf_validation_replace_types().
227 bt_ctf_validation_output_put_types(&validation_output
);
230 * Freeze the stream class since the event header must not be changed
233 bt_ctf_stream_class_freeze(stream_class
);
236 * Mark stream class, and event class as valid since
237 * they're all frozen now.
239 stream_class
->valid
= 1;
240 event_class
->valid
= 1;
242 /* Put stuff we borrowed from the event class */
243 BT_PUT(stream_class
);
245 BT_LOGD("Created event object: addr=%p, event-class-name=\"%s\", "
246 "event-class-id=%" PRId64
,
247 event
, bt_ctf_event_class_get_name(event
->event_class
),
248 bt_ctf_event_class_get_id(event_class
));
252 bt_ctf_validation_output_put_types(&validation_output
);
254 BT_PUT(stream_class
);
256 BT_PUT(event_header
);
257 BT_PUT(stream_event_context
);
258 BT_PUT(event_context
);
259 BT_PUT(event_payload
);
260 assert(!packet_header_type
);
261 assert(!packet_context_type
);
262 assert(!event_header_type
);
263 assert(!stream_event_ctx_type
);
264 assert(!event_context_type
);
265 assert(!event_payload_type
);
270 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
272 struct bt_ctf_event_class
*event_class
= NULL
;
275 BT_LOGW_STR("Invalid parameter: event is NULL.");
279 event_class
= event
? bt_get(bt_ctf_event_borrow_event_class(event
)) :
285 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
287 struct bt_ctf_stream
*stream
= NULL
;
290 BT_LOGW_STR("Invalid parameter: event is NULL.");
295 * If the event has a parent, then this is its (writer) stream.
296 * If the event has no parent, then if it has a packet, this
297 * is its (non-writer) stream.
299 if (event
->base
.parent
) {
300 stream
= (struct bt_ctf_stream
*) bt_object_get_parent(event
);
303 stream
= bt_get(event
->packet
->stream
);
311 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
,
313 struct bt_ctf_field
*payload
)
317 if (!event
|| !payload
) {
318 BT_LOGW("Invalid parameter: event or payload field is NULL: "
319 "event-addr=%p, payload-field-addr=%p",
326 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
327 "event-class-name=\"%s\", event-class-id=%" PRId64
,
328 event
, bt_ctf_event_class_get_name(event
->event_class
),
329 bt_ctf_event_class_get_id(event
->event_class
));
335 ret
= bt_ctf_field_structure_set_field(event
->fields_payload
,
338 struct bt_ctf_field_type
*payload_type
;
340 payload_type
= bt_ctf_field_get_type(payload
);
342 if (bt_ctf_field_type_compare(payload_type
,
343 event
->event_class
->fields
) == 0) {
344 bt_put(event
->fields_payload
);
346 event
->fields_payload
= payload
;
348 BT_LOGW("Invalid parameter: payload field type is different from the expected field type: "
349 "event-addr=%p, event-class-name=\"%s\", "
350 "event-class-id=%" PRId64
,
352 bt_ctf_event_class_get_name(event
->event_class
),
353 bt_ctf_event_class_get_id(event
->event_class
));
357 bt_put(payload_type
);
361 BT_LOGW("Failed to set event's payload field: event-addr=%p, "
362 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
363 "payload-field-name=\"%s\", payload-field-addr=%p",
364 event
, bt_ctf_event_class_get_name(event
->event_class
),
365 bt_ctf_event_class_get_id(event
->event_class
),
368 BT_LOGV("Set event's payload field: event-addr=%p, "
369 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
370 "payload-field-name=\"%s\", payload-field-addr=%p",
371 event
, bt_ctf_event_class_get_name(event
->event_class
),
372 bt_ctf_event_class_get_id(event
->event_class
),
380 struct bt_ctf_field
*bt_ctf_event_get_event_payload(struct bt_ctf_event
*event
)
382 struct bt_ctf_field
*payload
= NULL
;
385 BT_LOGW_STR("Invalid parameter: event is NULL.");
389 if (!event
->fields_payload
) {
390 BT_LOGV("Event has no current payload field: addr=%p, "
391 "event-class-name=\"%s\", event-class-id=%" PRId64
,
392 event
, bt_ctf_event_class_get_name(event
->event_class
),
393 bt_ctf_event_class_get_id(event
->event_class
));
397 payload
= event
->fields_payload
;
403 int bt_ctf_event_set_event_payload(struct bt_ctf_event
*event
,
404 struct bt_ctf_field
*payload
)
406 return bt_ctf_event_set_payload(event
, NULL
, payload
);
409 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
412 struct bt_ctf_field
*field
= NULL
;
415 BT_LOGW_STR("Invalid parameter: event is NULL.");
420 field
= bt_ctf_field_structure_get_field(event
->fields_payload
,
423 field
= event
->fields_payload
;
430 struct bt_ctf_field
*bt_ctf_event_get_payload_by_index(
431 struct bt_ctf_event
*event
, uint64_t index
)
433 struct bt_ctf_field
*field
= NULL
;
436 BT_LOGW_STR("Invalid parameter: event is NULL.");
440 field
= bt_ctf_field_structure_get_field_by_index(event
->fields_payload
,
446 struct bt_ctf_field
*bt_ctf_event_get_header(
447 struct bt_ctf_event
*event
)
449 struct bt_ctf_field
*header
= NULL
;
452 BT_LOGW_STR("Invalid parameter: event is NULL.");
456 if (!event
->event_header
) {
457 BT_LOGV("Event has no current header field: addr=%p, "
458 "event-class-name=\"%s\", event-class-id=%" PRId64
,
459 event
, bt_ctf_event_class_get_name(event
->event_class
),
460 bt_ctf_event_class_get_id(event
->event_class
));
464 header
= event
->event_header
;
470 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
471 struct bt_ctf_field
*header
)
474 struct bt_ctf_field_type
*field_type
= NULL
;
475 struct bt_ctf_stream_class
*stream_class
= NULL
;
478 BT_LOGW_STR("Invalid parameter: event is NULL.");
484 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
485 "event-class-name=\"%s\", event-class-id=%" PRId64
,
486 event
, bt_ctf_event_class_get_name(event
->event_class
),
487 bt_ctf_event_class_get_id(event
->event_class
));
492 stream_class
= (struct bt_ctf_stream_class
*) bt_object_get_parent(
495 * Ensure the provided header's type matches the one registered to the
498 field_type
= bt_ctf_field_get_type(header
);
499 if (bt_ctf_field_type_compare(field_type
,
500 stream_class
->event_header_type
)) {
501 BT_LOGW("Invalid parameter: header field type is different from the expected field type: "
502 "event-addr=%p, event-class-name=\"%s\", "
503 "event-class-id=%" PRId64
,
505 bt_ctf_event_class_get_name(event
->event_class
),
506 bt_ctf_event_class_get_id(event
->event_class
));
511 bt_put(event
->event_header
);
512 event
->event_header
= bt_get(header
);
513 BT_LOGV("Set event's header field: event-addr=%p, "
514 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
515 "header-field-addr=%p",
516 event
, bt_ctf_event_class_get_name(event
->event_class
),
517 bt_ctf_event_class_get_id(event
->event_class
), header
);
519 bt_put(stream_class
);
524 struct bt_ctf_field
*bt_ctf_event_get_event_context(
525 struct bt_ctf_event
*event
)
527 struct bt_ctf_field
*context
= NULL
;
530 BT_LOGW_STR("Invalid parameter: event is NULL.");
534 if (!event
->context_payload
) {
535 BT_LOGV("Event has no current context field: addr=%p, "
536 "event-class-name=\"%s\", event-class-id=%" PRId64
,
537 event
, bt_ctf_event_class_get_name(event
->event_class
),
538 bt_ctf_event_class_get_id(event
->event_class
));
542 context
= event
->context_payload
;
548 int bt_ctf_event_set_event_context(struct bt_ctf_event
*event
,
549 struct bt_ctf_field
*context
)
552 struct bt_ctf_field_type
*field_type
= NULL
;
555 BT_LOGW_STR("Invalid parameter: event is NULL.");
561 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
562 "event-class-name=\"%s\", event-class-id=%" PRId64
,
563 event
, bt_ctf_event_class_get_name(event
->event_class
),
564 bt_ctf_event_class_get_id(event
->event_class
));
569 field_type
= bt_ctf_field_get_type(context
);
570 if (bt_ctf_field_type_compare(field_type
,
571 event
->event_class
->context
)) {
572 BT_LOGW("Invalid parameter: context field type is different from the expected field type: "
573 "event-addr=%p, event-class-name=\"%s\", "
574 "event-class-id=%" PRId64
,
576 bt_ctf_event_class_get_name(event
->event_class
),
577 bt_ctf_event_class_get_id(event
->event_class
));
582 bt_put(event
->context_payload
);
583 event
->context_payload
= bt_get(context
);
584 BT_LOGV("Set event's context field: event-addr=%p, "
585 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
586 "context-field-addr=%p",
587 event
, bt_ctf_event_class_get_name(event
->event_class
),
588 bt_ctf_event_class_get_id(event
->event_class
), context
);
594 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
595 struct bt_ctf_event
*event
)
597 struct bt_ctf_field
*stream_event_context
= NULL
;
600 BT_LOGW_STR("Invalid parameter: event is NULL.");
604 if (!event
->stream_event_context
) {
605 BT_LOGV("Event has no current stream event context field: addr=%p, "
606 "event-class-name=\"%s\", event-class-id=%" PRId64
,
607 event
, bt_ctf_event_class_get_name(event
->event_class
),
608 bt_ctf_event_class_get_id(event
->event_class
));
612 stream_event_context
= event
->stream_event_context
;
614 return bt_get(stream_event_context
);
617 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event
*event
,
618 struct bt_ctf_field
*stream_event_context
)
621 struct bt_ctf_field_type
*field_type
= NULL
;
622 struct bt_ctf_stream_class
*stream_class
= NULL
;
625 BT_LOGW_STR("Invalid parameter: event is NULL.");
631 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
632 "event-class-name=\"%s\", event-class-id=%" PRId64
,
633 event
, bt_ctf_event_class_get_name(event
->event_class
),
634 bt_ctf_event_class_get_id(event
->event_class
));
639 stream_class
= bt_ctf_event_class_get_stream_class(event
->event_class
);
641 * We should not have been able to create the event without associating
642 * the event class to a stream class.
644 assert(stream_class
);
646 field_type
= bt_ctf_field_get_type(stream_event_context
);
647 if (bt_ctf_field_type_compare(field_type
,
648 stream_class
->event_context_type
)) {
649 BT_LOGW("Invalid parameter: stream event context field type is different from the expected field type: "
650 "event-addr=%p, event-class-name=\"%s\", "
651 "event-class-id=%" PRId64
,
653 bt_ctf_event_class_get_name(event
->event_class
),
654 bt_ctf_event_class_get_id(event
->event_class
));
659 bt_get(stream_event_context
);
660 BT_MOVE(event
->stream_event_context
, stream_event_context
);
661 BT_LOGV("Set event's stream event context field: event-addr=%p, "
662 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
663 "stream-event-context-field-addr=%p",
664 event
, bt_ctf_event_class_get_name(event
->event_class
),
665 bt_ctf_event_class_get_id(event
->event_class
),
666 stream_event_context
);
668 BT_PUT(stream_class
);
673 /* Pre-2.0 CTF writer backward compatibility */
674 void bt_ctf_event_get(struct bt_ctf_event
*event
)
679 /* Pre-2.0 CTF writer backward compatibility */
680 void bt_ctf_event_put(struct bt_ctf_event
*event
)
685 void bt_ctf_event_destroy(struct bt_object
*obj
)
687 struct bt_ctf_event
*event
;
689 event
= container_of(obj
, struct bt_ctf_event
, base
);
690 BT_LOGD("Destroying event: addr=%p, "
691 "event-class-name=\"%s\", event-class-id=%" PRId64
,
692 event
, bt_ctf_event_class_get_name(event
->event_class
),
693 bt_ctf_event_class_get_id(event
->event_class
));
695 if (!event
->base
.parent
) {
697 * Event was keeping a reference to its class since it shared no
698 * common ancestor with it to guarantee they would both have the
701 bt_put(event
->event_class
);
703 g_hash_table_destroy(event
->clock_values
);
704 BT_LOGD_STR("Putting event's header field.");
705 bt_put(event
->event_header
);
706 BT_LOGD_STR("Putting event's stream event context field.");
707 bt_put(event
->stream_event_context
);
708 BT_LOGD_STR("Putting event's context field.");
709 bt_put(event
->context_payload
);
710 BT_LOGD_STR("Putting event's payload field.");
711 bt_put(event
->fields_payload
);
712 BT_LOGD_STR("Putting event's packet.");
713 bt_put(event
->packet
);
717 struct bt_ctf_clock_value
*bt_ctf_event_get_clock_value(
718 struct bt_ctf_event
*event
, struct bt_ctf_clock_class
*clock_class
)
720 struct bt_ctf_clock_value
*clock_value
= NULL
;
722 if (!event
|| !clock_class
) {
723 BT_LOGW("Invalid parameter: event or clock class is NULL: "
724 "event-addr=%p, clock-class-addr=%p",
729 clock_value
= g_hash_table_lookup(event
->clock_values
, clock_class
);
731 BT_LOGV("No clock value associated to the given clock class: "
732 "event-addr=%p, event-class-name=\"%s\", "
733 "event-class-id=%" PRId64
", clock-class-addr=%p, "
734 "clock-class-name=\"%s\"", event
,
735 bt_ctf_event_class_get_name(event
->event_class
),
736 bt_ctf_event_class_get_id(event
->event_class
),
737 clock_class
, bt_ctf_clock_class_get_name(clock_class
));
746 int bt_ctf_event_set_clock_value(struct bt_ctf_event
*event
,
747 struct bt_ctf_clock_value
*value
)
750 struct bt_ctf_trace
*trace
;
751 struct bt_ctf_stream_class
*stream_class
;
752 struct bt_ctf_event_class
*event_class
;
753 struct bt_ctf_clock_class
*clock_class
= NULL
;
755 if (!event
|| !value
) {
756 BT_LOGW("Invalid parameter: event or clock value is NULL: "
757 "event-addr=%p, clock-value-addr=%p",
764 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
765 "event-class-name=\"%s\", event-class-id=%" PRId64
,
766 event
, bt_ctf_event_class_get_name(event
->event_class
),
767 bt_ctf_event_class_get_id(event
->event_class
));
772 clock_class
= bt_ctf_clock_value_get_class(value
);
773 event_class
= bt_ctf_event_borrow_event_class(event
);
775 stream_class
= bt_ctf_event_class_borrow_stream_class(event_class
);
776 assert(stream_class
);
777 trace
= bt_ctf_stream_class_borrow_trace(stream_class
);
780 if (!bt_ctf_trace_has_clock_class(trace
, clock_class
)) {
781 BT_LOGW("Invalid parameter: clock class is not part of event's trace: "
782 "event-addr=%p, event-class-name=\"%s\", "
783 "event-class-id=%" PRId64
", clock-class-addr=%p, "
784 "clock-class-name=\"%s\"",
785 event
, bt_ctf_event_class_get_name(event
->event_class
),
786 bt_ctf_event_class_get_id(event
->event_class
),
787 clock_class
, bt_ctf_clock_class_get_name(clock_class
));
792 g_hash_table_insert(event
->clock_values
, clock_class
, bt_get(value
));
793 BT_LOGV("Set event's clock value: "
794 "event-addr=%p, event-class-name=\"%s\", "
795 "event-class-id=%" PRId64
", clock-class-addr=%p, "
796 "clock-class-name=\"%s\", clock-value-addr=%p, "
797 "clock-value-cycles=%" PRIu64
,
798 event
, bt_ctf_event_class_get_name(event
->event_class
),
799 bt_ctf_event_class_get_id(event
->event_class
),
800 clock_class
, bt_ctf_clock_class_get_name(clock_class
),
801 value
, value
->value
);
810 int bt_ctf_event_validate(struct bt_ctf_event
*event
)
812 /* Make sure each field's payload has been set */
814 struct bt_ctf_stream_class
*stream_class
= NULL
;
817 ret
= bt_ctf_field_validate(event
->event_header
);
819 BT_LOGD("Invalid event's header field: "
820 "event-addr=%p, event-class-name=\"%s\", "
821 "event-class-id=%" PRId64
,
822 event
, bt_ctf_event_class_get_name(event
->event_class
),
823 bt_ctf_event_class_get_id(event
->event_class
));
827 stream_class
= bt_ctf_event_class_get_stream_class(event
->event_class
);
829 * We should not have been able to create the event without associating
830 * the event class to a stream class.
832 assert(stream_class
);
833 if (stream_class
->event_context_type
) {
834 ret
= bt_ctf_field_validate(event
->stream_event_context
);
836 BT_LOGD("Invalid event's stream event context field: "
837 "event-addr=%p, event-class-name=\"%s\", "
838 "event-class-id=%" PRId64
,
840 bt_ctf_event_class_get_name(event
->event_class
),
841 bt_ctf_event_class_get_id(event
->event_class
));
846 ret
= bt_ctf_field_validate(event
->fields_payload
);
848 BT_LOGD("Invalid event's payload field: "
849 "event-addr=%p, event-class-name=\"%s\", "
850 "event-class-id=%" PRId64
,
852 bt_ctf_event_class_get_name(event
->event_class
),
853 bt_ctf_event_class_get_id(event
->event_class
));
857 if (event
->event_class
->context
) {
858 BT_LOGD("Invalid event's context field: "
859 "event-addr=%p, event-class-name=\"%s\", "
860 "event-class-id=%" PRId64
,
862 bt_ctf_event_class_get_name(event
->event_class
),
863 bt_ctf_event_class_get_id(event
->event_class
));
864 ret
= bt_ctf_field_validate(event
->context_payload
);
867 bt_put(stream_class
);
872 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
873 struct bt_ctf_stream_pos
*pos
,
874 enum bt_ctf_byte_order native_byte_order
)
881 BT_LOGV("Serializing event: "
882 "event-addr=%p, event-class-name=\"%s\", "
883 "event-class-id=%" PRId64
", pos-offset=%" PRId64
", "
885 event
, bt_ctf_event_class_get_name(event
->event_class
),
886 bt_ctf_event_class_get_id(event
->event_class
),
887 pos
->offset
, bt_ctf_byte_order_string(native_byte_order
));
889 BT_LOGV_STR("Serializing context field.");
890 if (event
->context_payload
) {
891 ret
= bt_ctf_field_serialize(event
->context_payload
, pos
,
894 BT_LOGE("Cannot serialize event's context field: "
895 "event-addr=%p, event-class-name=\"%s\", "
896 "event-class-id=%" PRId64
,
898 bt_ctf_event_class_get_name(event
->event_class
),
899 bt_ctf_event_class_get_id(event
->event_class
));
904 BT_LOGV_STR("Serializing payload field.");
905 if (event
->fields_payload
) {
906 ret
= bt_ctf_field_serialize(event
->fields_payload
, pos
,
909 BT_LOGE("Cannot serialize event's payload field: "
910 "event-addr=%p, event-class-name=\"%s\", "
911 "event-class-id=%" PRId64
,
913 bt_ctf_event_class_get_name(event
->event_class
),
914 bt_ctf_event_class_get_id(event
->event_class
));
922 struct bt_ctf_packet
*bt_ctf_event_get_packet(struct bt_ctf_event
*event
)
924 struct bt_ctf_packet
*packet
= NULL
;
927 BT_LOGW_STR("Invalid parameter: event is NULL.");
931 if (!event
->packet
) {
932 BT_LOGV("Event has no current packet: addr=%p, "
933 "event-class-name=\"%s\", event-class-id=%" PRId64
,
934 event
, bt_ctf_event_class_get_name(event
->event_class
),
935 bt_ctf_event_class_get_id(event
->event_class
));
939 packet
= bt_get(event
->packet
);
944 int bt_ctf_event_set_packet(struct bt_ctf_event
*event
,
945 struct bt_ctf_packet
*packet
)
947 struct bt_ctf_stream_class
*event_stream_class
= NULL
;
948 struct bt_ctf_stream_class
*packet_stream_class
= NULL
;
949 struct bt_ctf_stream
*stream
= NULL
;
952 if (!event
|| !packet
) {
953 BT_LOGW("Invalid parameter: event or packet is NULL: "
954 "event-addr=%p, packet-addr=%p",
961 BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
962 "event-class-name=\"%s\", event-class-id=%" PRId64
,
963 event
, bt_ctf_event_class_get_name(event
->event_class
),
964 bt_ctf_event_class_get_id(event
->event_class
));
970 * Make sure the new packet was created by this event's
971 * stream, if it is set.
973 stream
= bt_ctf_event_get_stream(event
);
975 if (packet
->stream
!= stream
) {
976 BT_LOGW("Invalid parameter: packet's stream and event's stream differ: "
977 "event-addr=%p, event-class-name=\"%s\", "
978 "event-class-id=%" PRId64
", packet-stream-addr=%p, "
979 "event-stream-addr=%p",
980 event
, bt_ctf_event_class_get_name(event
->event_class
),
981 bt_ctf_event_class_get_id(event
->event_class
),
982 packet
->stream
, stream
);
988 bt_ctf_event_class_get_stream_class(event
->event_class
);
989 packet_stream_class
=
990 bt_ctf_stream_get_class(packet
->stream
);
992 assert(event_stream_class
);
993 assert(packet_stream_class
);
995 if (event_stream_class
!= packet_stream_class
) {
996 BT_LOGW("Invalid parameter: packet's stream class and event's stream class differ: "
997 "event-addr=%p, event-class-name=\"%s\", "
998 "event-class-id=%" PRId64
", packet-stream-class-addr=%p, "
999 "event-stream-class-addr=%p",
1000 event
, bt_ctf_event_class_get_name(event
->event_class
),
1001 bt_ctf_event_class_get_id(event
->event_class
),
1002 packet_stream_class
, event_stream_class
);
1009 BT_MOVE(event
->packet
, packet
);
1010 BT_LOGV("Set event's packet: event-addr=%p, "
1011 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
1013 event
, bt_ctf_event_class_get_name(event
->event_class
),
1014 bt_ctf_event_class_get_id(event
->event_class
), packet
);
1018 BT_PUT(event_stream_class
);
1019 BT_PUT(packet_stream_class
);
1025 void bt_ctf_event_freeze(struct bt_ctf_event
*event
)
1029 if (event
->frozen
) {
1033 BT_LOGD("Freezing event: addr=%p, "
1034 "event-class-name=\"%s\", event-class-id=%" PRId64
,
1035 event
, bt_ctf_event_class_get_name(event
->event_class
),
1036 bt_ctf_event_class_get_id(event
->event_class
));
1037 bt_ctf_packet_freeze(event
->packet
);
1038 BT_LOGD_STR("Freezing event's header field.");
1039 bt_ctf_field_freeze(event
->event_header
);
1040 BT_LOGD_STR("Freezing event's stream event context field.");
1041 bt_ctf_field_freeze(event
->stream_event_context
);
1042 BT_LOGD_STR("Freezing event's context field.");
1043 bt_ctf_field_freeze(event
->context_payload
);
1044 BT_LOGD_STR("Freezing event's payload field.");
1045 bt_ctf_field_freeze(event
->fields_payload
);