lib: add discarded packets message
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Feb 2019 21:25:45 +0000 (16:25 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This patch implements the "discarded packets" message API. You can
create such a message to communicate that packets were discarded at the
source level.

This message conveys redundant information considering the "packet
counter" property of a packet object. However, this property will be
removed before 2.0-rc1, and the discarded packet message will be the
only way to indicate discarded packets. The rationale behind this is
that the beginning and end times of the packet object do not represent a
stream activity time range (this is indicated by stream activity
beginning and end messages now); they are used for discarded event and
packet counter time ranges (when using multiple packets). To make this
less confusing, discarded events and packets are their own messages. For
the time being, both the properties and the messages coexist.

There are two ways to create a discarded packets message:

bt_message_discarded_packets_create():
    Create a message using a stream of which the class has no default
    clock class. This indicates that a number of packets were discarded
    at this point within the message flow.

bt_message_discarded_packets_create_with_default_clock_snapshots():
    Create a message using a stream of which the class has a default
    clock class. In this case, you must pass the beginning and end clock
    snapshot raw values which delimit the time range when packets were
    discarded by the tracer.

    Within the message flow, the beginning time must be greater than or
    equal to the previous message's time (depending on its type). The
    end time must be less than or equal to the next message's time. For
    example, the `ctf` plugin sources will push such a message following
    a packet end message, and the time range will be said packet end
    message's packet's end time to the next packet's beginning time.

In the message flow, you can only insert this message, for a given
stream:

* Between packet end and packet beginning messages.
* Before the first packet beginning message.
* After the last packet end message.

In other words, you cannot insert this message in the middle of a
packet.

By default, the message indicates that "a number" of packets were
discarded. In other words, bt_message_discarded_packets_get_count()
returns `BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE`. To be more accurate,
use bt_message_discarded_packets_set_count() to set a specific discarded
packet count.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/graph/message-const.h
include/babeltrace/graph/message-discarded-packets-const.h [new file with mode: 0644]
include/babeltrace/graph/message-discarded-packets.h [new file with mode: 0644]
lib/graph/message/discarded-items.c
lib/graph/message/message.c
lib/lib-logging.c

index 81437113de9e941d4a7b743b23b70e2af1b68689..4d850a1b293a1013aed0105d4d55afc098fcf8d4 100644 (file)
@@ -170,6 +170,8 @@ babeltracegraphinclude_HEADERS = \
        babeltrace/graph/message-const.h \
        babeltrace/graph/message-discarded-events-const.h \
        babeltrace/graph/message-discarded-events.h \
+       babeltrace/graph/message-discarded-packets-const.h \
+       babeltrace/graph/message-discarded-packets.h \
        babeltrace/graph/message-event-const.h \
        babeltrace/graph/message-event.h \
        babeltrace/graph/message-inactivity-const.h \
index 913b4da7d88452dbb4ff2ea3c0931fee36e72f36..19b998d1e29ffbea3ff46497c1fc9a9759c1529b 100644 (file)
 #include <babeltrace/graph/message-const.h>
 #include <babeltrace/graph/message-discarded-events-const.h>
 #include <babeltrace/graph/message-discarded-events.h>
+#include <babeltrace/graph/message-discarded-packets-const.h>
+#include <babeltrace/graph/message-discarded-packets.h>
 #include <babeltrace/graph/message-event-const.h>
 #include <babeltrace/graph/message-event.h>
 #include <babeltrace/graph/message-inactivity-const.h>
index 2e859f54c97dc218dd5bbaddec2df9b1b630a3e0..414124bb9af10c74cc3f750a007e6069b2dd87fd 100644 (file)
@@ -44,6 +44,7 @@ typedef enum bt_message_type {
        BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING = 6,
        BT_MESSAGE_TYPE_STREAM_ACTIVITY_END = 7,
        BT_MESSAGE_TYPE_DISCARDED_EVENTS = 8,
+       BT_MESSAGE_TYPE_DISCARDED_PACKETS = 9,
 } bt_message_type;
 
 /**
diff --git a/include/babeltrace/graph/message-discarded-packets-const.h b/include/babeltrace/graph/message-discarded-packets-const.h
new file mode 100644 (file)
index 0000000..ab067d7
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_CONST_H
+#define BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_CONST_H
+
+/*
+ * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/* For bt_message, bt_clock_snapshot, bt_stream */
+#include <babeltrace/types.h>
+
+/* For bt_clock_snapshot_state */
+#include <babeltrace/trace-ir/clock-snapshot-const.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bt_clock_snapshot_state
+bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
+               const bt_message *msg, const bt_clock_snapshot **snapshot);
+
+extern bt_clock_snapshot_state
+bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
+               const bt_message *msg, const bt_clock_snapshot **snapshot);
+
+extern const bt_stream *
+bt_message_discarded_packets_borrow_stream_const(const bt_message *message);
+
+extern bt_property_availability bt_message_discarded_packets_get_count(
+               const bt_message *message, uint64_t *count);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_CONST_H */
diff --git a/include/babeltrace/graph/message-discarded-packets.h b/include/babeltrace/graph/message-discarded-packets.h
new file mode 100644 (file)
index 0000000..cb8dc73
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_H
+#define BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_H
+
+/*
+ * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+
+/* For bt_message, bt_self_message_iterator, bt_stream */
+#include <babeltrace/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bt_message *bt_message_discarded_packets_create(
+               bt_self_message_iterator *message_iterator,
+               bt_stream *stream);
+
+extern bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots(
+               bt_self_message_iterator *message_iterator,
+               bt_stream *stream, uint64_t beginning_raw_value,
+               uint64_t end_raw_value);
+
+extern bt_stream *bt_message_discarded_packets_borrow_stream(
+               bt_message *message);
+
+extern void bt_message_discarded_packets_set_count(bt_message *message,
+               uint64_t count);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_H */
index c0e76e390fec4e372f2b338a220025b28c7c2bcb..9393f6caa6523bcc26d9fe0b96e82c38f6334703 100644 (file)
@@ -35,6 +35,8 @@
 #include <babeltrace/graph/message-discarded-items-internal.h>
 #include <babeltrace/graph/message-discarded-events.h>
 #include <babeltrace/graph/message-discarded-events-const.h>
+#include <babeltrace/graph/message-discarded-packets.h>
+#include <babeltrace/graph/message-discarded-packets-const.h>
 
 static
 void destroy_discarded_items_message(struct bt_object *obj)
@@ -260,3 +262,75 @@ enum bt_property_availability bt_message_discarded_events_get_count(
        BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
        return get_discarded_items_message_count(message, count);
 }
+
+struct bt_message *bt_message_discarded_packets_create(
+               struct bt_self_message_iterator *message_iterator,
+               struct bt_stream *stream)
+{
+       return create_discarded_items_message(message_iterator,
+               BT_MESSAGE_TYPE_DISCARDED_PACKETS, stream,
+               false, 0, 0);
+}
+
+struct bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots(
+               struct bt_self_message_iterator *message_iterator,
+               struct bt_stream *stream, uint64_t beginning_raw_value,
+               uint64_t end_raw_value)
+{
+       return create_discarded_items_message(message_iterator,
+               BT_MESSAGE_TYPE_DISCARDED_PACKETS, stream,
+               true, beginning_raw_value, end_raw_value);
+}
+
+struct bt_stream *bt_message_discarded_packets_borrow_stream(
+               struct bt_message *message)
+{
+       BT_ASSERT_PRE_NON_NULL(message, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       return borrow_discarded_items_message_stream(message);
+}
+
+void bt_message_discarded_packets_set_count(struct bt_message *message,
+               uint64_t count)
+{
+       BT_ASSERT_PRE_NON_NULL(message, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       set_discarded_items_message_count(message, count);
+}
+
+enum bt_clock_snapshot_state
+bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
+               const struct bt_message *msg,
+               const struct bt_clock_snapshot **snapshot)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
+               msg, snapshot);
+}
+
+enum bt_clock_snapshot_state
+bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
+               const struct bt_message *msg,
+               const struct bt_clock_snapshot **snapshot)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       return borrow_discarded_items_message_default_end_clock_snapshot_const(
+               msg, snapshot);
+}
+
+const struct bt_stream *
+bt_message_discarded_packets_borrow_stream_const(const struct bt_message *message)
+{
+       return (void *) bt_message_discarded_packets_borrow_stream(
+               (void *) message);
+}
+
+enum bt_property_availability bt_message_discarded_packets_get_count(
+               const struct bt_message *message, uint64_t *count)
+{
+       BT_ASSERT_PRE_NON_NULL(message, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       return get_discarded_items_message_count(message, count);
+}
index 989e0e44f11abc682fe2ee9860914aa46022811b..2d30d04a7b5df5f586d139307c72fcba3671ad4b 100644 (file)
@@ -36,7 +36,7 @@ void bt_message_init(struct bt_message *message,
                bt_object_release_func release,
                struct bt_graph *graph)
 {
-       BT_ASSERT(type >= 0 && type <= BT_MESSAGE_TYPE_DISCARDED_EVENTS);
+       BT_ASSERT(type >= 0 && type <= BT_MESSAGE_TYPE_DISCARDED_PACKETS);
        message->type = type;
        bt_object_init_shared(&message->base, release);
        message->graph = graph;
index 0c6865759316dc73aae5e804e7adbf49ec873e68..c48149be002e2ba80d4c73bd25382138a523ac60 100644 (file)
@@ -967,6 +967,7 @@ static inline void format_message(char **buf_ch, bool extended,
                break;
        }
        case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+       case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
        {
                const struct bt_message_discarded_items *msg_disc_items =
                        (const void *) msg;
This page took 0.03142 seconds and 4 git commands to generate.