lib: iterator.c: auto-seek: handle new message types
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 13 Feb 2019 18:34:03 +0000 (13:34 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:37 +0000 (18:19 -0400)
When reading the time of a given message for auto-seeking purposes:

* Skip packet beginning/end messages as packet object beginning/end time
  properties are about to be removed.

* Use a stream activity beginning time if known, otherwise skip the
  message for infinite and unknown times.

* Use a stream activity end time if known, otherwise skip the message
  for an unknown time (a positive infinite time is always greater than
  any requested time).

* Use the beginning time of a discarded events/packets message because
  this beginning time must be greater than or equal to the previous
  message's time for the same stream.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib/graph/iterator.c

index a0da4e6650b9f75755b702286cd1868f56a08a3f..bc8faf85aa2b7f7320f198d8311cd493708f7c73 100644 (file)
@@ -55,6 +55,8 @@
 #include <babeltrace/graph/message-stream-end-const.h>
 #include <babeltrace/graph/message-stream-internal.h>
 #include <babeltrace/graph/message-inactivity-internal.h>
+#include <babeltrace/graph/message-discarded-items-internal.h>
+#include <babeltrace/graph/message-stream-activity-internal.h>
 #include <babeltrace/graph/port-const.h>
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/graph-const.h>
@@ -994,34 +996,88 @@ int get_message_ns_from_origin(const struct bt_message *msg,
                const struct bt_message_inactivity *inactivity_msg =
                        (const void *) msg;
 
-               BT_ASSERT(inactivity_msg->default_cs);
                clk_snapshot = inactivity_msg->default_cs;
+               BT_ASSERT(clk_snapshot);
                break;
        }
-       case BT_MESSAGE_TYPE_STREAM_BEGINNING:
-       case BT_MESSAGE_TYPE_STREAM_END:
+       case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+       case BT_MESSAGE_TYPE_PACKET_END:
                /* Ignore */
                goto end;
-       case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+       case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+       case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
        {
-               const struct bt_message_packet *pkt_msg =
+               const struct bt_message_discarded_items *disc_items_msg =
                        (const void *) msg;
 
-               clk_snapshot = pkt_msg->packet->default_beginning_cs;
+               clk_snapshot = disc_items_msg->default_begin_cs;
+               BT_ASSERT_PRE(clk_snapshot,
+                       "Discarded events/packets message has no default clock snapshot: %!+n",
+                       msg);
                break;
        }
-       case BT_MESSAGE_TYPE_PACKET_END:
+       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
        {
-               const struct bt_message_packet *pkt_msg =
+               const struct bt_message_stream_activity *stream_act_msg =
                        (const void *) msg;
 
-               clk_snapshot = pkt_msg->packet->default_end_cs;
+               switch (stream_act_msg->default_cs_state) {
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN:
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE:
+                       /*
+                        * -inf is always less than any requested time,
+                        * and we can't assume any specific time for an
+                        * unknown clock snapshot, so skip this.
+                        */
+                       goto set_ignore;
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN:
+                       clk_snapshot = stream_act_msg->default_cs;
+                       BT_ASSERT(clk_snapshot);
+                       break;
+               default:
+                       abort();
+               }
+
                break;
        }
+       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
+       {
+               const struct bt_message_stream_activity *stream_act_msg =
+                       (const void *) msg;
+
+               switch (stream_act_msg->default_cs_state) {
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN:
+                       /*
+                        * We can't assume any specific time for an
+                        * unknown clock snapshot, so skip this.
+                        */
+                       goto set_ignore;
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE:
+                       /*
+                        * +inf is always greater than any requested
+                        * time.
+                        */
+                       *ns_from_origin = INT64_MAX;
+                       goto end;
+               case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN:
+                       clk_snapshot = stream_act_msg->default_cs;
+                       BT_ASSERT(clk_snapshot);
+                       break;
+               default:
+                       abort();
+               }
+
+               break;
+       }
+       case BT_MESSAGE_TYPE_STREAM_BEGINNING:
+       case BT_MESSAGE_TYPE_STREAM_END:
+               /* Ignore */
+               break;
        default:
                abort();
        }
 
+set_ignore:
        if (!clk_snapshot) {
                *ignore = true;
                goto end;
This page took 0.026756 seconds and 4 git commands to generate.