From: Francis Deslauriers Date: Thu, 6 Jun 2019 04:05:53 +0000 (-0400) Subject: src.ctf.fs: trace-info: omit stream `range-ns` field when no TS X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=1d4ac4b6541dcbbe1f676e198ab868fe5254ba49 src.ctf.fs: trace-info: omit stream `range-ns` field when no TS 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 Change-Id: I419f57960a52d8ed2823fdb06982e5c20710b6da Reviewed-on: https://review.lttng.org/c/babeltrace/+/1387 CI-Build: Philippe Proulx Reviewed-by: Philippe Proulx --- diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h index aa073599..9e9ee84d 100644 --- a/plugins/ctf/fs-src/fs.h +++ b/plugins/ctf/fs-src/fs.h @@ -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; }; diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index 0ddd4186..e2018b15 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -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", diff --git a/tests/plugins/ctf/test_query_trace_info.py b/tests/plugins/ctf/test_query_trace_info.py index 053c0e1e..a026a68e 100644 --- a/tests/plugins/ctf/test_query_trace_info.py +++ b/tests/plugins/ctf/test_query_trace_info.py @@ -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()