From: Philippe Proulx Date: Mon, 29 May 2017 20:15:00 +0000 (-0400) Subject: stream.c: allow stream PC's `events_discarded` field to be set by user X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=59a09b0ee1d2e2cb8430d10cbea84b789d184e67;p=deliverable%2Fbabeltrace.git stream.c: allow stream PC's `events_discarded` field to be set by user 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 --- diff --git a/lib/ctf-ir/stream.c b/lib/ctf-ir/stream.c index e14a01461..ce3936da9 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) { /*