From 3f3d89b4f77852d8df9c11e909e9ed5fa03218ed Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 3 Sep 2019 10:35:23 -0400 Subject: [PATCH] bt2: pass all params to `babeltrace.trace-info` query when computing stream intersection 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1998 Tested-by: jenkins Reviewed-by: Philippe Proulx --- .../bt2/trace_collection_message_iterator.py | 13 ++------- .../test_trace_collection_message_iterator.py | 28 ++++++++++++++++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py b/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py index 4e7347a9..ea1d7eb3 100644 --- a/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py +++ b/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py @@ -345,20 +345,13 @@ class TraceCollectionMessageIterator(bt2_message_iterator._MessageIterator): 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( - 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() diff --git a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py index 3abbe358..065b46e9 100644 --- a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py +++ b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py @@ -296,15 +296,35 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): 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( - '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( -- 2.34.1