lib: make discarded events/packets support and clock snapshots optional
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Jun 2019 16:16:11 +0000 (12:16 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 6 Jun 2019 21:19:12 +0000 (17:19 -0400)
commit2e90378a2b94006e2743b06e7fe7a1f0e691a56e
treebe100dcd7995fcf44acfc4eeeae563ceffc5d220
parent7fe92073394104c8ffe575b1b05ee4fe1df356ea
lib: make discarded events/packets support and clock snapshots optional

This patch adds functions to the stream class API to make it explicit
that discarded events and/or discarded packets are supported for stream
instances. The same functions are used to specify whether or not
discarded events and discarded packets have time ranges, that is,
default beginning and end clock snapshots.

The basic use cases to support are:

1. CTF 1.8: packet context has `timestamp_begin`, `timestamp_end` packet
   context members, as well as `events_discarded` and/or
   `packet_seq_num` members. This is legit: LTTng produces this.

2. CTF 1.8: packet context has `events_discarded` and/or
   `packet_seq_num` packet context members, but no `timestamp_begin` and
   `timestamp_end` members. This is possible (barectf, other tracers).

3. Source has no concept of discarded events and/or packets.

My initial approach was to have only the "discarded events have default
clock snapshots" and "discarded packets have default clock snapshots"
stream class properties, but they would need to be false by default
(because there's no default clock class by default), and then
`sink.ctf.fs` would, at least temporarily, require those default clock
snapshots to exist for those messages when there's a default clock
class, so simple sources without the discarded events/packets concept
would always need to set both stream class properties. I found this
weird, so the default is:

* No discarded events support.
* No discarded packets support.

When you set that the streams of a given stream class support discarded
events and packets, you specify at the same time if they have default
clock snapshots:

    void bt_stream_class_set_supports_discarded_events(
        bt_stream_class *stream_class,
        bt_bool supports_discarded_events,
        bt_bool with_default_clock_snapshots);

    void bt_stream_class_set_supports_discarded_packets(
        bt_stream_class *stream_class,
        bt_bool supports_discarded_packets,
        bt_bool with_default_clock_snapshots);

This means that a simple source can keep the default properties as is
and not create any discarded events/packets messages; `sink.ctf.fs` will
work fine.

It is a precondition that the stream class has a default clock class
when you call bt_stream_class_set_supports_discarded_events() or
bt_stream_class_set_supports_discarded_packets() with the
`with_default_clock_snapshots` parameter set.

This patch satisfies the three use cases above with those
configurations:

1. Discarded events and/or packets supported with default clock
   snapshots.

2. Discarded events and/or packets supported without default clock
   snapshots.

3. Discarded events and/or packets are not supported.

The component classes are not modified to support custom configurations
yet:

* `src.ctf.fs` always supports discarded events/packets, and always with
  default clock snapshots when the stream class has a default clock
  class.

* `sink.ctf.fs` and `flt.utils.trimmer` expect that, if discarded
  events/packets are supported (and those messages are not intentionally
  ignored for `sink.ctf.fs`) and the stream class has a default clock
  class, discarded events/packets have default clock snapshots.

Support for other configurations will be added in future patches.

This change will also make it possible for `sink.ctf.fs` to not write
any `events_discarded` packet context member when discarded events are
known to be not supported.

Python bindings are updated to support this feature. The four new flags
are added as parameters to the TraceClass.create_stream_class(). The
corresponding (private) property setters in `StreamClass` check that you
cannot make the stream class _not_ support discarded events/packets, but
have discarded events/packets have default clock snapshots. The new
tests in `test_stream_class.py` verify this too.

In `message.py`, I changed how we check, for each type of message, if
the message object has a default clock snapshot or not. It used to rely
on its stream class having a default clock class or not, but it's not
the only condition for packet beginning, packet end, and now discarded
events and discarded packets messages. Now, in any default clock
snapshot property, the function checks its own, custom condition.
Because having the stream class have a default clock class is still a
typical condition, there's the helper
_Message._check_has_default_clock_class(). I renamed
`NoDefaultClockClass` to `NonexistentClockSnapshot` to make the
exception more generic, considering what's written in this paragraph.

I also removed the `_DiscardedMessage.default_clock_class` property
because it could not be found in other types of messages, which is weird,
and you can always access it with

    mein_msg.stream.stream_class.default_clock_class

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I18b0bc65ef61e8bbd01521fb20c223d401d2adc9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1365
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins
22 files changed:
bindings/python/bt2/bt2/__init__.py.in
bindings/python/bt2/bt2/message.py
bindings/python/bt2/bt2/message_iterator.py
bindings/python/bt2/bt2/native_bt_stream_class.i
bindings/python/bt2/bt2/stream_class.py
bindings/python/bt2/bt2/trace_class.py
include/babeltrace/trace-ir/stream-class-const.h
include/babeltrace/trace-ir/stream-class-internal.h
include/babeltrace/trace-ir/stream-class.h
lib/graph/message/discarded-items.c
lib/lib-logging.c
lib/trace-ir/stream-class.c
plugins/ctf/common/metadata/ctf-meta-translate.c
plugins/ctf/fs-sink/fs-sink.c
plugins/lttng-utils/debug-info/debug-info.c
plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
plugins/text/pretty/print.c
plugins/utils/muxer/muxer.c
plugins/utils/trimmer/trimmer.c
tests/bindings/python/bt2/test_event.py
tests/bindings/python/bt2/test_message.py
tests/bindings/python/bt2/test_stream_class.py
This page took 0.028778 seconds and 4 git commands to generate.