bt2: pass all params to `babeltrace.trace-info` query when computing stream intersection
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 3 Sep 2019 14:35:23 +0000 (10:35 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2019 15:38:52 +0000 (11:38 -0400)
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>
src/bindings/python/bt2/bt2/trace_collection_message_iterator.py
tests/bindings/python/bt2/test_trace_collection_message_iterator.py

index 4e7347a92a01128a6265f4b2328739540d3044c5..ea1d7eb3f370a9ad143204e3531027ed25234b41 100644 (file)
@@ -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()
 
index 3abbe358b5a579441139928192b4bd3e6cad26a8..065b46e9af534b3987fbc8e18cc13c447bd8a84b 100644 (file)
@@ -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(
This page took 0.028619 seconds and 4 git commands to generate.