From 59a09b0ee1d2e2cb8430d10cbea84b789d184e67 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 29 May 2017 16:15:00 -0400 Subject: [PATCH] stream.c: allow stream PC's `events_discarded` field to be set by user MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If a stream packet context `events_discarded` field is set a flush time, check if its value keeps the count monotonic, and use this value to set the stream's current discarded events count if so. If it's not set, do like before and set it automatically from the stream's current count. This will make it possible for a ctf.fs sink component to write the original `events_discarded` field without having to read it, compute the difference with the previous value, and use bt_ctf_stream_append_discarded_events() to change the stream's discarded events count. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/ctf-ir/stream.c | 55 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/ctf-ir/stream.c b/lib/ctf-ir/stream.c index e14a0146..ce3936da 100644 --- a/lib/ctf-ir/stream.c +++ b/lib/ctf-ir/stream.c @@ -353,18 +353,50 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream) goto end; } - ret = bt_ctf_field_unsigned_integer_set_value(field, - stream->discarded_events); - if (ret) { - BT_LOGW("Cannot set packet context field's `events_discarded` integer field's value: " - "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64, - stream, bt_ctf_stream_get_name(stream), - field, stream->discarded_events); + /* + * If the field is set by the user, make sure that the value is + * greater than or equal to the stream's current count of + * discarded events. We do not allow wrapping here. If it's + * valid, update the stream's current count. + */ + if (bt_ctf_field_is_set(field)) { + uint64_t user_val; + + ret = bt_ctf_field_unsigned_integer_get_value(field, + &user_val); + if (ret) { + BT_LOGW("Cannot get packet context `events_discarded` field's unsigned value: " + "stream-addr=%p, stream-name=\"%s\", field-addr=%p", + stream, bt_ctf_stream_get_name(stream), field); + goto end; + } + + if (user_val < stream->discarded_events) { + BT_LOGW("Invalid packet context `events_discarded` field's unsigned value: " + "value is lesser than the stream's current discarded events count: " + "stream-addr=%p, stream-name=\"%s\", field-addr=%p, " + "value=%" PRIu64 ", " + "stream-discarded-events-count=%" PRIu64, + stream, bt_ctf_stream_get_name(stream), field, + user_val, stream->discarded_events); + goto end; + } + + stream->discarded_events = user_val; } else { - BT_LOGV("Set packet context field's `events_discarded` field's value: " - "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64, - stream, bt_ctf_stream_get_name(stream), - field, stream->discarded_events); + ret = bt_ctf_field_unsigned_integer_set_value(field, + stream->discarded_events); + if (ret) { + BT_LOGW("Cannot set packet context field's `events_discarded` integer field's value: " + "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64, + stream, bt_ctf_stream_get_name(stream), + field, stream->discarded_events); + } else { + BT_LOGV("Set packet context field's `events_discarded` field's value: " + "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64, + stream, bt_ctf_stream_get_name(stream), + field, stream->discarded_events); + } } end: @@ -1621,6 +1653,7 @@ end: reset_structure_field(stream->packet_context, "timestamp_end"); reset_structure_field(stream->packet_context, "packet_size"); reset_structure_field(stream->packet_context, "content_size"); + reset_structure_field(stream->packet_context, "events_discarded"); if (ret < 0) { /* -- 2.34.1