lib/graph/notification/packet.c: add logging
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 19 Jun 2017 22:42:11 +0000 (18:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Jul 2017 20:04:54 +0000 (16:04 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/graph/notification/packet.c

index fa6a0ee335e1b95a96cb30965462d1a2aa1273e2..712d1c410de426c414257ff7cb91c3d6989d25e1 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "NOTIF-PACKET"
+#include <babeltrace/lib-logging-internal.h>
+
 #include <babeltrace/compiler-internal.h>
+#include <babeltrace/ctf-ir/packet.h>
+#include <babeltrace/ctf-ir/packet-internal.h>
+#include <babeltrace/ctf-ir/stream.h>
+#include <babeltrace/ctf-ir/stream-internal.h>
 #include <babeltrace/graph/notification-packet-internal.h>
+#include <inttypes.h>
 
 static
 void bt_notification_packet_begin_destroy(struct bt_object *obj)
@@ -33,6 +41,9 @@ void bt_notification_packet_begin_destroy(struct bt_object *obj)
        struct bt_notification_packet_begin *notification =
                        (struct bt_notification_packet_begin *) obj;
 
+       BT_LOGD("Destroying packet beginning notification: addr=%p",
+               notification);
+       BT_LOGD_STR("Putting packet.");
        BT_PUT(notification->packet);
        g_free(notification);
 }
@@ -43,6 +54,9 @@ void bt_notification_packet_end_destroy(struct bt_object *obj)
        struct bt_notification_packet_end *notification =
                        (struct bt_notification_packet_end *) obj;
 
+       BT_LOGD("Destroying packet end notification: addr=%p",
+               notification);
+       BT_LOGD_STR("Putting packet.");
        BT_PUT(notification->packet);
        g_free(notification);
 }
@@ -51,16 +65,44 @@ struct bt_notification *bt_notification_packet_begin_create(
                struct bt_ctf_packet *packet)
 {
        struct bt_notification_packet_begin *notification;
+       struct bt_ctf_stream *stream;
+       struct bt_ctf_stream_class *stream_class;
 
        if (!packet) {
+               BT_LOGW_STR("Invalid parameter: packet is NULL.");
                goto error;
        }
 
+       stream = bt_ctf_packet_borrow_stream(packet);
+       assert(stream);
+       stream_class = bt_ctf_stream_borrow_stream_class(stream);
+       assert(stream_class);
+       BT_LOGD("Creating packet beginning notification object: "
+               "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
+               "stream-class-addr=%p, stream-class-name=\"%s\", "
+               "stream-class-id=%" PRId64,
+               packet, stream, bt_ctf_stream_get_name(stream),
+               stream_class,
+               bt_ctf_stream_class_get_name(stream_class),
+               bt_ctf_stream_class_get_id(stream_class));
        notification = g_new0(struct bt_notification_packet_begin, 1);
+       if (!notification) {
+               BT_LOGE_STR("Failed to allocate one packet beginning notification.");
+               goto error;
+       }
+
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_PACKET_BEGIN,
                        bt_notification_packet_begin_destroy);
        notification->packet = bt_get(packet);
+       BT_LOGD("Created packet beginning notification object: "
+               "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
+               "stream-class-addr=%p, stream-class-name=\"%s\", "
+               "stream-class-id=%" PRId64 ", addr=%p",
+               packet, stream, bt_ctf_stream_get_name(stream),
+               stream_class,
+               bt_ctf_stream_class_get_name(stream_class),
+               bt_ctf_stream_class_get_id(stream_class), notification);
        return &notification->parent;
 error:
        return NULL;
@@ -72,7 +114,16 @@ struct bt_ctf_packet *bt_notification_packet_begin_get_packet(
        struct bt_ctf_packet *ret = NULL;
        struct bt_notification_packet_begin *packet_begin;
 
+       if (!notification) {
+               BT_LOGW_STR("Invalid parameter: notification is NULL.");
+               goto end;
+       }
+
        if (notification->type != BT_NOTIFICATION_TYPE_PACKET_BEGIN) {
+               BT_LOGW("Invalid parameter: notification is not a packet beginning notification: "
+                       "addr%p, notif-type=%s",
+                       notification, bt_notification_type_string(
+                               bt_notification_get_type(notification)));
                goto end;
        }
 
@@ -87,16 +138,44 @@ struct bt_notification *bt_notification_packet_end_create(
                struct bt_ctf_packet *packet)
 {
        struct bt_notification_packet_end *notification;
+       struct bt_ctf_stream *stream;
+       struct bt_ctf_stream_class *stream_class;
 
        if (!packet) {
+               BT_LOGW_STR("Invalid parameter: packet is NULL.");
                goto error;
        }
 
+       stream = bt_ctf_packet_borrow_stream(packet);
+       assert(stream);
+       stream_class = bt_ctf_stream_borrow_stream_class(stream);
+       assert(stream_class);
+       BT_LOGD("Creating packet end notification object: "
+               "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
+               "stream-class-addr=%p, stream-class-name=\"%s\", "
+               "stream-class-id=%" PRId64,
+               packet, stream, bt_ctf_stream_get_name(stream),
+               stream_class,
+               bt_ctf_stream_class_get_name(stream_class),
+               bt_ctf_stream_class_get_id(stream_class));
        notification = g_new0(struct bt_notification_packet_end, 1);
+       if (!notification) {
+               BT_LOGE_STR("Failed to allocate one packet end notification.");
+               goto error;
+       }
+
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_PACKET_END,
                        bt_notification_packet_end_destroy);
        notification->packet = bt_get(packet);
+       BT_LOGD("Created packet end notification object: "
+               "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
+               "stream-class-addr=%p, stream-class-name=\"%s\", "
+               "stream-class-id=%" PRId64 ", addr=%p",
+               packet, stream, bt_ctf_stream_get_name(stream),
+               stream_class,
+               bt_ctf_stream_class_get_name(stream_class),
+               bt_ctf_stream_class_get_id(stream_class), notification);
        return &notification->parent;
 error:
        return NULL;
@@ -108,7 +187,16 @@ struct bt_ctf_packet *bt_notification_packet_end_get_packet(
        struct bt_ctf_packet *ret = NULL;
        struct bt_notification_packet_end *packet_end;
 
+       if (!notification) {
+               BT_LOGW_STR("Invalid parameter: notification is NULL.");
+               goto end;
+       }
+
        if (notification->type != BT_NOTIFICATION_TYPE_PACKET_END) {
+               BT_LOGW("Invalid parameter: notification is not a packet end notification: "
+                       "addr%p, notif-type=%s",
+                       notification, bt_notification_type_string(
+                               bt_notification_get_type(notification)));
                goto end;
        }
 
This page took 0.026841 seconds and 4 git commands to generate.