/* For bt_message, bt_event */
#include <babeltrace/types.h>
+/* For bt_clock_snapshot_state */
+#include <babeltrace/trace-ir/clock-snapshot-const.h>
+
#ifdef __cplusplus
extern "C" {
#endif
extern const bt_event *bt_message_event_borrow_event_const(
const bt_message *message);
+extern bt_clock_snapshot_state
+bt_message_event_borrow_default_clock_snapshot_const(
+ const bt_message *msg, const bt_clock_snapshot **snapshot);
+
#ifdef __cplusplus
}
#endif
struct bt_message_event {
struct bt_message parent;
struct bt_event *event;
+ struct bt_clock_snapshot *default_cs;
};
BT_HIDDEN
* SOFTWARE.
*/
+#include <stdint.h>
+
/*
* For bt_self_message_iterator, bt_event, bt_packet,
* bt_event_class, bt_message
const bt_event_class *event_class,
const bt_packet *packet);
+extern
+bt_message *bt_message_event_create_with_default_clock_snapshot(
+ bt_self_message_iterator *message_iterator,
+ const bt_event_class *event_class,
+ const bt_packet *packet, uint64_t raw_clock_value);
+
extern bt_event *bt_message_event_borrow_event(
bt_message *message);
* http://www.efficios.com/ctf
*/
-/* For bt_clock_snapshot_state */
-#include <babeltrace/trace-ir/clock-snapshot-const.h>
-
-/* For bt_event, bt_clock_snapshot, bt_event_class, bt_field, bt_packet */
+/* For bt_event, bt_event_class, bt_field, bt_packet */
#include <babeltrace/types.h>
#ifdef __cplusplus
extern const bt_field *bt_event_borrow_payload_field_const(
const bt_event *event);
-extern bt_clock_snapshot_state bt_event_borrow_default_clock_snapshot_const(
- const bt_event *event,
- const bt_clock_snapshot **clock_snapshot);
-
#ifdef __cplusplus
}
#endif
#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/value.h>
-#include <babeltrace/trace-ir/clock-snapshot-internal.h>
#include <babeltrace/trace-ir/stream-class.h>
#include <babeltrace/trace-ir/stream.h>
#include <babeltrace/trace-ir/stream-internal.h>
struct bt_field *common_context_field;
struct bt_field *specific_context_field;
struct bt_field *payload_field;
- struct bt_clock_snapshot *default_cs;
bool frozen;
};
BT_ASSERT(event);
BT_LIB_LOGD("Resetting event: %!+e", event);
bt_event_set_is_frozen(event, false);
-
- if (event->default_cs) {
- bt_clock_snapshot_reset(event->default_cs);
- }
-
bt_object_put_no_null_check(&event->packet->base);
event->packet = NULL;
}
extern bt_field *bt_event_borrow_payload_field(bt_event *event);
-extern void bt_event_set_default_clock_snapshot(bt_event *event,
- uint64_t value_cycles);
-
#ifdef __cplusplus
}
#endif
const struct bt_message_event *event_msg =
(const void *) msg;
- clk_snapshot = event_msg->event->default_cs;
+ clk_snapshot = event_msg->default_cs;
BT_ASSERT_PRE(clk_snapshot,
"Event has no default clock snapshot: %!+e",
event_msg->event);
#include <babeltrace/trace-ir/event-class-internal.h>
#include <babeltrace/trace-ir/stream-class-internal.h>
#include <babeltrace/trace-ir/trace.h>
+#include <babeltrace/trace-ir/clock-snapshot-internal.h>
#include <babeltrace/graph/graph-internal.h>
#include <babeltrace/graph/message-event-const.h>
#include <babeltrace/graph/message-event.h>
return (void *) message;
}
-struct bt_message *bt_message_event_create(
+static inline
+struct bt_message *create_event_message(
struct bt_self_message_iterator *self_msg_iter,
const struct bt_event_class *c_event_class,
- const struct bt_packet *c_packet)
+ const struct bt_packet *c_packet, bool with_cs,
+ uint64_t raw_value)
{
struct bt_self_component_port_input_message_iterator *msg_iter =
(void *) self_msg_iter;
struct bt_message_event *message = NULL;
struct bt_event_class *event_class = (void *) c_event_class;
+ struct bt_stream_class *stream_class;
struct bt_packet *packet = (void *) c_packet;
struct bt_event *event;
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
BT_ASSERT_PRE(event_class_has_trace(event_class),
"Event class is not part of a trace: %!+E", event_class);
- BT_LIB_LOGD("Creating event message object: %![ec-]+E",
- event_class);
+ stream_class = bt_event_class_borrow_stream_class_inline(event_class);
+ BT_ASSERT(stream_class);
+ BT_ASSERT_PRE((with_cs && stream_class->default_clock_class) ||
+ (!with_cs && !stream_class->default_clock_class),
+ "Creating an event message with a default clock snapshot, but without "
+ "a default clock class, or without a default clock snapshot, "
+ "but with a default clock class: ",
+ "%![ec-]+E, %![sc-]+S, with-cs=%d, "
+ "cs-val=%" PRIu64,
+ event_class, stream_class, with_cs, raw_value);
+ BT_LIB_LOGD("Creating event message object: %![ec-]+E", event_class);
event = bt_event_create(event_class, packet);
if (unlikely(!event)) {
BT_LIB_LOGE("Cannot create event from event class: "
goto error;
}
+ if (with_cs) {
+ BT_ASSERT(stream_class->default_clock_class);
+ message->default_cs = bt_clock_snapshot_create(
+ stream_class->default_clock_class);
+ if (!message->default_cs) {
+ goto error;
+ }
+
+ bt_clock_snapshot_set_raw_value(message->default_cs, raw_value);
+ }
+
BT_ASSERT(!message->event);
message->event = event;
bt_packet_set_is_frozen(packet, true);
return (void *) message;
}
+struct bt_message *bt_message_event_create(
+ struct bt_self_message_iterator *msg_iter,
+ const struct bt_event_class *event_class,
+ const struct bt_packet *packet)
+{
+ return create_event_message(msg_iter, event_class, packet, false, 0);
+}
+
+struct bt_message *bt_message_event_create_with_default_clock_snapshot(
+ struct bt_self_message_iterator *msg_iter,
+ const struct bt_event_class *event_class,
+ const struct bt_packet *packet,
+ uint64_t raw_value)
+{
+ return create_event_message(msg_iter, event_class, packet,
+ true, raw_value);
+}
+
BT_HIDDEN
void bt_message_event_destroy(struct bt_message *msg)
{
event_msg->event = NULL;
}
+ if (event_msg->default_cs) {
+ bt_clock_snapshot_recycle(event_msg->default_cs);
+ event_msg->default_cs = NULL;
+ }
+
g_free(msg);
}
BT_ASSERT(event_msg->event);
bt_event_recycle(event_msg->event);
event_msg->event = NULL;
+
+ if (event_msg->default_cs) {
+ bt_clock_snapshot_recycle(event_msg->default_cs);
+ event_msg->default_cs = NULL;
+ }
+
graph = msg->graph;
msg->graph = NULL;
bt_object_pool_recycle_object(&graph->event_msg_pool, msg);
{
return borrow_event((void *) message);
}
+
+enum bt_clock_snapshot_state
+bt_message_event_borrow_default_clock_snapshot_const(
+ const struct bt_message *msg,
+ const struct bt_clock_snapshot **snapshot)
+{
+ struct bt_message_event *event_msg = (void *) msg;
+ struct bt_stream_class *stream_class;
+
+ BT_ASSERT_PRE_NON_NULL(msg, "Message");
+ BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_EVENT);
+ BT_ASSERT(msg);
+ stream_class = bt_event_class_borrow_stream_class(
+ event_msg->event->class);
+ BT_ASSERT(stream_class);
+ BT_ASSERT_PRE(stream_class->default_clock_class,
+ "Message's stream's class has no default clock class: "
+ "%![msg-]+n, %![sc-]+S", msg, stream_class);
+ BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
+ *snapshot = event_msg->default_cs;
+ return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
+}
}
}
- if (event->default_cs) {
- SET_TMP_PREFIX("default-cs-");
- format_clock_snapshot(buf_ch, true, tmp_prefix,
- event->default_cs);
- }
-
packet = bt_event_borrow_packet_const(event);
if (!packet) {
return;
#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/trace-ir/field-internal.h>
#include <babeltrace/trace-ir/field-class-internal.h>
-#include <babeltrace/trace-ir/clock-class.h>
-#include <babeltrace/trace-ir/clock-snapshot-const.h>
-#include <babeltrace/trace-ir/clock-snapshot-internal.h>
-#include <babeltrace/trace-ir/clock-class-internal.h>
#include <babeltrace/trace-ir/event-const.h>
#include <babeltrace/trace-ir/event-internal.h>
#include <babeltrace/trace-ir/event-class.h>
}
}
- if (stream_class->default_clock_class) {
- event->default_cs = bt_clock_snapshot_create(
- stream_class->default_clock_class);
- if (!event->default_cs) {
- /* bt_clock_snapshot_create() logs errors */
- goto error;
- }
- }
-
goto end;
error:
BT_LOGD_STR("Putting event's class.");
bt_object_put_ref(event->class);
-
- if (event->default_cs) {
- bt_clock_snapshot_recycle(event->default_cs);
- event->default_cs = NULL;
- }
-
BT_LOGD_STR("Putting event's packet.");
BT_OBJECT_PUT_REF_AND_RESET(event->packet);
g_free(event);
}
-void bt_event_set_default_clock_snapshot(struct bt_event *event,
- uint64_t value_cycles)
-{
- struct bt_stream_class *sc;
-
- BT_ASSERT_PRE_NON_NULL(event, "Event");
- BT_ASSERT_PRE_EVENT_HOT(event);
- sc = bt_event_class_borrow_stream_class_inline(event->class);
- BT_ASSERT(sc);
- BT_ASSERT_PRE(sc->default_clock_class,
- "Event's stream class has no default clock class: "
- "%![ev-]+e, %![sc-]+S", event, sc);
- BT_ASSERT(event->default_cs);
- bt_clock_snapshot_set_raw_value(event->default_cs, value_cycles);
- BT_LIB_LOGV("Set event's default clock snapshot: %![event-]+e, "
- "value=%" PRIu64, event, value_cycles);
-}
-
-enum bt_clock_snapshot_state bt_event_borrow_default_clock_snapshot_const(
- const struct bt_event *event,
- const struct bt_clock_snapshot **clock_snapshot)
-{
- BT_ASSERT_PRE_NON_NULL(event, "Event");
- BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)");
- *clock_snapshot = event->default_cs;
- return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
-}
-
struct bt_packet *bt_event_borrow_packet(struct bt_event *event)
{
BT_ASSERT_PRE_NON_NULL(event, "Event");
notit->meta.ec->name->str,
notit->packet);
BT_ASSERT(notit->msg_iter);
- msg = bt_message_event_create(notit->msg_iter,
- notit->meta.ec->ir_ec, notit->packet);
+ BT_ASSERT(notit->meta.sc);
+
+ if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
+ msg = bt_message_event_create_with_default_clock_snapshot(
+ notit->msg_iter, notit->meta.ec->ir_ec,
+ notit->packet, notit->default_clock_snapshot);
+ } else {
+ msg = bt_message_event_create(notit->msg_iter,
+ notit->meta.ec->ir_ec, notit->packet);
+ }
+
if (!msg) {
BT_LOGE("Cannot create event message: "
"notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
return ret_fc;
}
-static
-void set_event_default_clock_snapshot(struct bt_msg_iter *notit)
-{
- bt_event *event = bt_message_event_borrow_event(notit->event_msg);
- bt_stream_class *sc = notit->meta.sc->ir_sc;
-
- BT_ASSERT(event);
-
- if (bt_stream_class_borrow_default_clock_class(sc)) {
- bt_event_set_default_clock_snapshot(event,
- notit->default_clock_snapshot);
- }
-}
-
static
void create_msg_stream_beginning(struct bt_msg_iter *notit,
bt_message **message)
switch (notit->state) {
case STATE_EMIT_MSG_EVENT:
BT_ASSERT(notit->event_msg);
- set_event_default_clock_snapshot(notit);
*message = notit->event_msg;
notit->event_msg = NULL;
goto end;
goto error;
}
- msg = bt_message_event_create(msg_iter->pc_msg_iter,
- dmesg_comp->event_class, dmesg_comp->packet);
+ if (dmesg_comp->clock_class) {
+ msg = bt_message_event_create_with_default_clock_snapshot(
+ msg_iter->pc_msg_iter,
+ dmesg_comp->event_class, dmesg_comp->packet, ts);
+ msg_iter->last_clock_value = ts;
+ } else {
+ msg = bt_message_event_create(msg_iter->pc_msg_iter,
+ dmesg_comp->event_class, dmesg_comp->packet);
+ }
+
if (!msg) {
BT_LOGE_STR("Cannot create event message.");
goto error;
event = bt_message_event_borrow_event(msg);
BT_ASSERT(event);
-
- if (dmesg_comp->clock_class) {
- bt_event_set_default_clock_snapshot(event, ts);
- msg_iter->last_clock_value = ts;
- }
-
goto end;
error:
static
void print_timestamp_cycles(struct pretty_component *pretty,
- const bt_event *event)
+ const bt_clock_snapshot *clock_snapshot)
{
- const bt_clock_snapshot *clock_snapshot;
uint64_t cycles;
- bt_clock_snapshot_state cs_state;
-
- cs_state = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot);
- if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN || !clock_snapshot) {
- g_string_append(pretty->string, "????????????????????");
- return;
- }
cycles = bt_clock_snapshot_get_value(clock_snapshot);
g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
if (pretty->last_cycles_timestamp != -1ULL) {
pretty->delta_cycles = cycles - pretty->last_cycles_timestamp;
}
+
pretty->last_cycles_timestamp = cycles;
}
static
int print_event_timestamp(struct pretty_component *pretty,
- const bt_event *event, bool *start_line)
+ const bt_message *event_msg, bool *start_line)
{
bool print_names = pretty->options.print_header_field_names;
int ret = 0;
const bt_stream *stream = NULL;
const bt_stream_class *stream_class = NULL;
const bt_clock_snapshot *clock_snapshot = NULL;
- bt_clock_snapshot_state cs_state;
+ const bt_event *event = bt_message_event_borrow_event_const(event_msg);
stream = bt_event_borrow_stream_const(event);
- if (!stream) {
- ret = -1;
- goto end;
- }
-
stream_class = bt_stream_borrow_class_const(stream);
- if (!stream_class) {
- ret = -1;
+
+ if (!bt_stream_class_borrow_default_clock_class_const(stream_class)) {
+ /* No default clock class: skip the timestamp without an error */
goto end;
}
- cs_state = bt_event_borrow_default_clock_snapshot_const(event,
- &clock_snapshot);
- if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN || !clock_snapshot) {
+ if (bt_message_event_borrow_default_clock_snapshot_const(event_msg,
+ &clock_snapshot) != BT_CLOCK_SNAPSHOT_STATE_KNOWN) {
/* No default clock value: skip the timestamp without an error */
goto end;
}
g_string_append(pretty->string, COLOR_TIMESTAMP);
}
if (pretty->options.print_timestamp_cycles) {
- print_timestamp_cycles(pretty, event);
+ print_timestamp_cycles(pretty, clock_snapshot);
} else {
- clock_snapshot = NULL;
- cs_state = bt_event_borrow_default_clock_snapshot_const(event,
- &clock_snapshot);
print_timestamp_wall(pretty, clock_snapshot);
}
if (pretty->use_colors) {
static
int print_event_header(struct pretty_component *pretty,
- const bt_event *event)
+ const bt_message *event_msg)
{
bool print_names = pretty->options.print_header_field_names;
int ret = 0;
const bt_packet *packet = NULL;
const bt_stream *stream = NULL;
const bt_trace *trace = NULL;
+ const bt_event *event = bt_message_event_borrow_event_const(event_msg);
int dom_print = 0;
bt_property_availability prop_avail;
packet = bt_event_borrow_packet_const(event);
stream = bt_packet_borrow_stream_const(packet);
trace = bt_stream_borrow_trace_const(stream);
- ret = print_event_timestamp(pretty, event, &pretty->start_line);
+ ret = print_event_timestamp(pretty, event_msg, &pretty->start_line);
if (ret) {
goto end;
}
BT_ASSERT(event);
pretty->start_line = true;
g_string_assign(pretty->string, "");
- ret = print_event_header(pretty, event);
+ ret = print_event_header(pretty, event_msg);
if (ret != 0) {
goto end;
}
{
const bt_clock_class *clock_class = NULL;
const bt_clock_snapshot *clock_snapshot = NULL;
- const bt_event *event = NULL;
int ret = 0;
const unsigned char *cc_uuid;
const char *cc_name;
switch (bt_message_get_type(msg)) {
case BT_MESSAGE_TYPE_EVENT:
- event = bt_message_event_borrow_event_const(msg);
- BT_ASSERT(event);
- cs_state = bt_event_borrow_default_clock_snapshot_const(event,
- &clock_snapshot);
+ cs_state = bt_message_event_borrow_default_clock_snapshot_const(
+ msg, &clock_snapshot);
break;
case BT_MESSAGE_TYPE_INACTIVITY: