From 4237f1f2ad5a6745990fa5511169b8d088e94541 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 11 Feb 2019 16:25:45 -0500 Subject: [PATCH] lib: add discarded packets message 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 --- include/Makefile.am | 2 + include/babeltrace/babeltrace.h | 2 + include/babeltrace/graph/message-const.h | 1 + .../graph/message-discarded-packets-const.h | 54 ++++++++++++++ .../graph/message-discarded-packets.h | 54 ++++++++++++++ lib/graph/message/discarded-items.c | 74 +++++++++++++++++++ lib/graph/message/message.c | 2 +- lib/lib-logging.c | 1 + 8 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 include/babeltrace/graph/message-discarded-packets-const.h create mode 100644 include/babeltrace/graph/message-discarded-packets.h diff --git a/include/Makefile.am b/include/Makefile.am index 81437113..4d850a1b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 \ diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index 913b4da7..19b998d1 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -112,6 +112,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/include/babeltrace/graph/message-const.h b/include/babeltrace/graph/message-const.h index 2e859f54..414124bb 100644 --- a/include/babeltrace/graph/message-const.h +++ b/include/babeltrace/graph/message-const.h @@ -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 index 00000000..ab067d78 --- /dev/null +++ b/include/babeltrace/graph/message-discarded-packets-const.h @@ -0,0 +1,54 @@ +#ifndef BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_CONST_H +#define BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_CONST_H + +/* + * Copyright 2019 Philippe Proulx + * + * 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 + +/* For bt_clock_snapshot_state */ +#include + +#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 index 00000000..cb8dc738 --- /dev/null +++ b/include/babeltrace/graph/message-discarded-packets.h @@ -0,0 +1,54 @@ +#ifndef BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_H +#define BABELTRACE_GRAPH_MESSAGE_DISCARDED_PACKETS_H + +/* + * Copyright 2019 Philippe Proulx + * + * 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 + +/* For bt_message, bt_self_message_iterator, bt_stream */ +#include + +#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 */ diff --git a/lib/graph/message/discarded-items.c b/lib/graph/message/discarded-items.c index c0e76e39..9393f6ca 100644 --- a/lib/graph/message/discarded-items.c +++ b/lib/graph/message/discarded-items.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include 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); +} diff --git a/lib/graph/message/message.c b/lib/graph/message/message.c index 989e0e44..2d30d04a 100644 --- a/lib/graph/message/message.c +++ b/lib/graph/message/message.c @@ -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; diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 0c686575..c48149be 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -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; -- 2.34.1