src.ctf.fs: trace-info: omit stream `range-ns` field when no TS
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 6 Jun 2019 04:05:53 +0000 (00:05 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 7 Jun 2019 22:49:03 +0000 (18:49 -0400)
Don't print -1 timestamps when packet contexts don't have
`timestamp_begin` and `timestamp_end` fields. Simply omit this part of
the query reply.

Remove FIXME comment as the only user of the index now handles absent
timestamps.

Tests
=====
Adapt `test_ctf_plugin` stream sorting function to fall back on using
the `paths` field if `range-ns` field is absent and rename it to
abstract implementation details.

Add test case to test that `range-ns` fields are absent on traces
without `timestamp_begin` and `timestamp_end` fields in their packet
context.

Example
=======
Here is an example of the output of the `trace-info` query on a trace
without packet contexts before this commit:
  -
    streams:
      -
       range-ns:
          begin: -1
          end: -1
       paths:
          - /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context/stream
       class-id: 0
       port-name: /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context | 0 | /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context/stream
    range-ns:
      begin: -1
      end: 0
    name: no-packet-context
    path: /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context

Here is an example of the output of the `trace-info` query on a trace
without packet contexts after this commit:
  -
    streams:
      -
       class-id: 0
       port-name: /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context | 0 | /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context/stream
       paths:
          - /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context/stream
    name: no-packet-context
    path: /home/frdeso/projets/babeltrace/tests/ctf-traces/succeed/no-packet-context

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I419f57960a52d8ed2823fdb06982e5c20710b6da
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1387
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/ctf/fs-src/fs.h
plugins/ctf/fs-src/query.c
tests/plugins/ctf/test_query_trace_info.py

index aa073599128950222364816b126ed7028d5aa819..9e9ee84d86fa91fcaac3e267a29b632d2743e42a 100644 (file)
@@ -155,10 +155,6 @@ struct ctf_fs_ds_file_group {
         * been skipped. Moreover, the index's fields may not all be available
         * depending on the producer (e.g. timestamp_begin/end are not
         * mandatory).
-        *
-        * FIXME In such cases (missing fields), the indexing is aborted as
-        * no the index entries don't have a concept of fields being present
-        * or not.
         */
        struct ctf_fs_ds_index *index;
 };
index 0ddd4186a04033e4cf3511c5b9e58a09eb9021f6..e2018b157a0aef746e6d1c7ea85781bd992dd8a0 100644 (file)
@@ -313,13 +313,18 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
 
        stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns;
        stream_range->end_ns = last_ds_index_entry->timestamp_end_ns;
-       stream_range->set = true;
 
-       if (stream_range->set) {
-               ret = add_range(group_info, stream_range, "range-ns");
-               if (ret) {
-                       goto end;
-               }
+       /*
+        * If any of the begin and end timestamps is not set it means that
+        * packets don't include `timestamp_begin` _and_ `timestamp_end` fields
+        * in their packet context so we can't set the range.
+        */
+       stream_range->set = stream_range->begin_ns != UINT64_C(-1) &&
+               stream_range->end_ns != UINT64_C(-1);
+
+       ret = add_range(group_info, stream_range, "range-ns");
+       if (ret) {
+               goto end;
        }
 
        status = bt_value_map_insert_entry(group_info, "paths",
index 053c0e1e43c20b4a7f8892d96100bb09c8903ccd..a026a68ecebb4b7c9057309738f891bd2784fb2f 100644 (file)
@@ -23,11 +23,12 @@ import re
 test_ctf_traces_path = os.environ['TEST_CTF_TRACES_PATH']
 
 
-# Key to streams by their being timestamp.  Used to get the list of streams in
-# a predictable order.
-
-def sort_by_begin(stream):
-    return stream['range-ns']['begin']
+# Key to sort streams in a predictable order.
+def sort_predictably(stream):
+    if 'range-ns' in stream:
+        return stream['range-ns']['begin']
+    else:
+        return stream['paths'][0]
 
 
 class QueryTraceInfoClockOffsetTestCase(unittest.TestCase):
@@ -45,7 +46,7 @@ class QueryTraceInfoClockOffsetTestCase(unittest.TestCase):
         self.assertEqual(trace['intersection-range-ns']['begin'], 13515309000000070 + offset)
         self.assertEqual(trace['intersection-range-ns']['end'], 13515309000000100 + offset)
 
-        streams = sorted(trace['streams'], key=sort_by_begin)
+        streams = sorted(trace['streams'], key=sort_predictably)
         self.assertEqual(streams[0]['range-ns']['begin'], 13515309000000000 + offset)
         self.assertEqual(streams[0]['range-ns']['end'], 13515309000000100 + offset)
         self.assertEqual(streams[1]['range-ns']['begin'], 13515309000000070 + offset)
@@ -144,7 +145,7 @@ class QueryTraceInfoPortNameTestCase(unittest.TestCase):
         )
         self.assertEqual(len(res), 1)
         trace = res[0]
-        streams = sorted(trace["streams"], key=sort_by_begin)
+        streams = sorted(trace["streams"], key=sort_predictably)
         self.assertEqual(len(streams), 2)
         self.assertRegexpMatches(
             str(streams[0]["port-name"]),
@@ -163,7 +164,7 @@ class QueryTraceInfoPortNameTestCase(unittest.TestCase):
         )
         self.assertEqual(len(res), 1)
         trace = res[0]
-        streams = sorted(trace["streams"], key=sort_by_begin)
+        streams = sorted(trace["streams"], key=sort_predictably)
         self.assertEqual(len(streams), 1)
         self.assertRegexpMatches(
             str(streams[0]["port-name"]),
@@ -171,5 +172,32 @@ class QueryTraceInfoPortNameTestCase(unittest.TestCase):
         )
 
 
+class QueryTraceInfoRangeTestCase(unittest.TestCase):
+    def setUp(self):
+        ctf = bt2.find_plugin("ctf")
+        self._fs = ctf.source_component_classes["fs"]
+
+        self._executor = bt2.QueryExecutor()
+
+    def test_trace_no_range(self):
+        # This trace has no `timestamp_begin` and `timestamp_end` in its packet
+        # context. The `trace-info` query should omit the `range-ns` fields in
+        # the `trace` and `stream` data structures.
+
+        res = self._executor.query(
+            self._fs,
+            "trace-info",
+            {"paths": [os.path.join(test_ctf_traces_path, "succeed", "succeed1")]},
+        )
+
+        self.assertEqual(len(res), 1)
+        trace = res[0]
+        streams = trace["streams"]
+        self.assertEqual(len(streams), 1)
+
+        self.assertRaises(KeyError, lambda: trace['range-ns'])
+        self.assertRaises(KeyError, lambda: streams[0]['range-ns'])
+
+
 if __name__ == '__main__':
     unittest.main()
This page took 0.027072 seconds and 4 git commands to generate.