ir: do not try to create initial packet/event fields when opt. FT is NULL
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 2 Jun 2017 18:11:49 +0000 (14:11 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 21:02:58 +0000 (17:02 -0400)
If a trace has not packet header field type, then when creating a
packet, do not attempt to create the initial packet header field without
checking that the field type is NULL because this is a violation of
preconditions. The main side effect here is a WARN-level log message
even if the situation is normal.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/ctf-ir/event.c
lib/ctf-ir/packet.c

index 1ab1be57db83fbcffb06b7de26290d8d38b6a463..9a552e7b09773682f13618ae5a28464b6cfaaebb 100644 (file)
@@ -174,14 +174,21 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
        event->event_class = bt_get(event_class);
        event->clock_values = g_hash_table_new_full(g_direct_hash,
                        g_direct_equal, bt_put, bt_put);
-       event_header =
-               bt_ctf_field_create(validation_output.event_header_type);
-       if (!event_header) {
-               BT_LOGE_STR("Cannot create initial event header field object.");
-               goto error;
+
+       if (validation_output.event_header_type) {
+               BT_LOGD("Creating initial event header field: ft-addr=%p",
+                       validation_output.event_header_type);
+               event_header =
+                       bt_ctf_field_create(validation_output.event_header_type);
+               if (!event_header) {
+                       BT_LOGE_STR("Cannot create initial event header field object.");
+                       goto error;
+               }
        }
 
        if (validation_output.stream_event_ctx_type) {
+               BT_LOGD("Creating initial stream event context field: ft-addr=%p",
+                       validation_output.stream_event_ctx_type);
                stream_event_context = bt_ctf_field_create(
                        validation_output.stream_event_ctx_type);
                if (!stream_event_context) {
@@ -191,6 +198,8 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
        }
 
        if (validation_output.event_context_type) {
+               BT_LOGD("Creating initial event context field: ft-addr=%p",
+                       validation_output.event_context_type);
                event_context = bt_ctf_field_create(
                        validation_output.event_context_type);
                if (!event_context) {
@@ -200,6 +209,8 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
        }
 
        if (validation_output.event_payload_type) {
+               BT_LOGD("Creating initial event payload field: ft-addr=%p",
+                       validation_output.event_payload_type);
                event_payload = bt_ctf_field_create(
                        validation_output.event_payload_type);
                if (!event_payload) {
index 75588149d47d536de587e4f4bf459538dbd1240d..9ec77deac18fbec382496ee2600dcbe4d4b358ee 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #define BT_LOG_TAG "PACKET"
+#include <babeltrace/lib-logging-internal.h>
 
 #include <babeltrace/ctf-ir/fields-internal.h>
 #include <babeltrace/ctf-ir/packet.h>
@@ -35,9 +36,9 @@
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/ctf-ir/stream-internal.h>
 #include <babeltrace/ctf-ir/trace-internal.h>
-#include <babeltrace/lib-logging-internal.h>
 #include <babeltrace/object-internal.h>
 #include <babeltrace/ref.h>
+#include <inttypes.h>
 
 struct bt_ctf_stream *bt_ctf_packet_get_stream(struct bt_ctf_packet *packet)
 {
@@ -224,13 +225,19 @@ struct bt_ctf_packet *bt_ctf_packet_create(
        struct bt_ctf_stream_class *stream_class = NULL;
        struct bt_ctf_trace *trace = NULL;
 
-       BT_LOGD("Creating packet object: stream-addr=%p", stream);
-
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
                goto end;
        }
 
+       BT_LOGD("Creating packet object: stream-addr=%p, "
+               "stream-name=\"%s\", stream-class-addr=%p, "
+               "stream-class-name=\"%s\", stream-class-id=%" PRId64,
+               stream, bt_ctf_stream_get_name(stream),
+               stream->stream_class,
+               bt_ctf_stream_class_get_name(stream->stream_class),
+               bt_ctf_stream_class_get_id(stream->stream_class));
+
        if (stream->pos.fd >= 0) {
                BT_LOGW_STR("Invalid parameter: stream is a CTF writer stream.");
                goto end;
@@ -248,19 +255,28 @@ struct bt_ctf_packet *bt_ctf_packet_create(
 
        bt_object_init(packet, bt_ctf_packet_destroy);
        packet->stream = bt_get(stream);
-       packet->header = bt_ctf_field_create(trace->packet_header_type);
-       if (!packet->header && trace->packet_header_type) {
-               BT_LOGE_STR("Cannot create initial packet header field object.");
-               BT_PUT(packet);
-               goto end;
+
+       if (trace->packet_header_type) {
+               BT_LOGD("Creating initial packet header field: ft-addr=%p",
+                       trace->packet_header_type);
+               packet->header = bt_ctf_field_create(trace->packet_header_type);
+               if (!packet->header) {
+                       BT_LOGE_STR("Cannot create initial packet header field object.");
+                       BT_PUT(packet);
+                       goto end;
+               }
        }
 
-       packet->context = bt_ctf_field_create(
-               stream->stream_class->packet_context_type);
-       if (!packet->context && stream->stream_class->packet_context_type) {
-               BT_LOGE_STR("Cannot create initial packet header field object.");
-               BT_PUT(packet);
-               goto end;
+       if (stream->stream_class->packet_context_type) {
+               BT_LOGD("Creating initial packet context field: ft-addr=%p",
+                       stream->stream_class->packet_context_type);
+               packet->context = bt_ctf_field_create(
+                       stream->stream_class->packet_context_type);
+               if (!packet->context) {
+                       BT_LOGE_STR("Cannot create initial packet header field object.");
+                       BT_PUT(packet);
+                       goto end;
+               }
        }
 
        BT_LOGD("Created packet object: addr=%p", packet);
This page took 0.027018 seconds and 4 git commands to generate.