TraceCollectionMessageIterator currently makes it mandatory to pass an
`inputs` parameter to source components when using the stream
intersection mode. It then picks out that parameter and passes just by
itself to the `babeltrace.trace-info` query.
This is not right for two reasons:
1. The `babeltrace.trace-info` query should be executed with the same
parameters as what the component will be created with. This is because
some parameters can influence the response of the query, such as
`clock-class-offset-ns` for `src.ctf.fs`.
2. The `inputs` parameter is not mandatory. It is a convention to which
source component classes can adhere to work with auto source discovery,
but it's not mandatory. Stream intersection mode should work even with
a source component class that doesn't use it.
A test is added, where a CTF trace is read using the stream intersection
mode, as well as a `clock-class-offset-s` parameter. Without this
patch, the test would fail because the trimmer components would be
created with a range that doesn't consider the offset. Therefore all
messages produced by the source (which have the offset applied) fall
outside the trimmers' ranges. With this patch, the
`babeltrace.trace-info` query returns stream ranges with the offset
applied, so the trimmers have the correct ranges.
Change-Id: I79c86cafafe123c6d306d196d5dde71002b711f7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1998
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
self._stream_inter_port_to_range = {}
for src_comp_and_spec in self._src_comps_and_specs:
self._stream_inter_port_to_range = {}
for src_comp_and_spec in self._src_comps_and_specs:
- try:
- inputs = src_comp_and_spec.spec.params['inputs']
- except KeyError as e:
- raise ValueError(
- 'all source components must be created with an "inputs" parameter in stream intersection mode'
- ) from e
-
- params = {'inputs': inputs}
-
# query the port's component for the `babeltrace.trace-info`
# object which contains the range for each stream, from which we can
# compute the intersection of the streams in each trace.
query_exec = bt2.QueryExecutor(
# query the port's component for the `babeltrace.trace-info`
# object which contains the range for each stream, from which we can
# compute the intersection of the streams in each trace.
query_exec = bt2.QueryExecutor(
- src_comp_and_spec.spec.component_class, 'babeltrace.trace-info', params
+ src_comp_and_spec.spec.component_class,
+ 'babeltrace.trace-info',
+ src_comp_and_spec.spec.params,
)
trace_infos = query_exec.query()
)
trace_infos = query_exec.query()
hist = _count_msgs_by_type(msgs)
self.assertEqual(hist[bt2._EventMessage], 3)
hist = _count_msgs_by_type(msgs)
self.assertEqual(hist[bt2._EventMessage], 3)
- def test_iter_intersection_no_inputs_param(self):
+ def test_iter_intersection_params(self):
+ # Check that all params used to create the source component are passed
+ # to the `babeltrace.trace-info` query.
specs = [
bt2.ComponentSpec.from_named_plugin_and_component_class(
specs = [
bt2.ComponentSpec.from_named_plugin_and_component_class(
- 'text', 'dmesg', {'read-from-stdin': True}
+ 'ctf',
+ 'fs',
+ {
+ 'inputs': [_3EVENTS_INTERSECT_TRACE_PATH],
+ 'clock-class-offset-s': 1000,
+ },
- with self.assertRaises(ValueError):
- bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=True)
+ msg_iter = bt2.TraceCollectionMessageIterator(
+ specs, stream_intersection_mode=True
+ )
+
+ event_msgs = [x for x in msg_iter if type(x) is bt2._EventMessage]
+ self.assertEqual(len(event_msgs), 3)
+ self.assertEqual(
+ event_msgs[0].default_clock_snapshot.ns_from_origin, 13516309000000071
+ )
+ self.assertEqual(
+ event_msgs[1].default_clock_snapshot.ns_from_origin, 13516309000000072
+ )
+ self.assertEqual(
+ event_msgs[2].default_clock_snapshot.ns_from_origin, 13516309000000082
+ )
def test_iter_no_intersection_two_traces(self):
spec = bt2.ComponentSpec.from_named_plugin_and_component_class(
def test_iter_no_intersection_two_traces(self):
spec = bt2.ComponentSpec.from_named_plugin_and_component_class(