Fix: Make traces with no data stream type ID readable by babeltrace
authorErica Bugden <ebugden@efficios.com>
Tue, 25 Apr 2023 16:01:36 +0000 (12:01 -0400)
committerErica Bugden <ebugden@efficios.com>
Fri, 28 Apr 2023 14:50:06 +0000 (10:50 -0400)
Currently, when the barectf configuration property
‘data-stream-type-id-field-type’ is false, barectf produces traces that
babeltrace (and Trace Compass) cannot parse.

To resolve this, remove all mentions of the data stream type ID from the
metadata file when there is no stream type ID field type feature.

Apparent cause:

When data stream type IDs are disabled, the barectf metadata file will
specify that the one data stream type has an ID of 0. This superfluous
information appears to be confusing to babeltrace even when the packet
header is explicitly empty (i.e. there is no mention of the stream type
ID in the actual trace data). This case falls into a grey area in the
CTF 1.8 specifcation (see below) and could arguably be a bug in
babeltrace since all the information needed to parse the trace
unambiguously is present in the metadata file. For example, the CTF
reader yactfr successfully reads such a trace. The stream type ID
information that barectf includes is superfluous, but not contradictory
of any data present in the trace.

However, add this fix because:
    a. Two common CTF trace format readers (babeltrace and
       Trace Compass) are unable to read these traces, and
    b. It is an easy fix in barectf.

CTF 1.8 specification:

This metadata issue is in a grey area of the CTF specification. The
specification says, “[The data stream type ID] field is optional if
there is only one [data stream type] in the metadata” and, “The [data
stream type ID] can be left out if there is only one [data stream type]
in the trace.” However, it does not say the data stream type ID _must_
be left out of the metadata if there is only one data stream type.

Implementation:

The condition added to the metadata Jinja template simply checks that
‘data-stream-type-id-field-type’ is not None. This works when
‘data-stream-type-id-field-type’ is set to false in the configuration,
because the data stream type ID field type will be set to None when the
trace type is created in config_parse_v3.py:

    dst_id_ft = self._feature_ft(...)

Testing:

The test does not check that babeltrace can read the trace, but it does
test that the lines mentioning the stream id are not present in the
generated metadata. Removing these lines has been manually verified to
be sufficient to allow babeltrace to read the trace.

The test source is adapted from the barectf test two-packets.c

Change-Id: I9de677440b98c41afe592d21a2ec18aa3c2e5bec
Signed-off-by: Erica Bugden <ebugden@efficios.com>
barectf/templates/metadata/metadata.j2
tests/tracing/configs/basic/ds/no-dst-id.yaml [new file with mode: 0644]
tests/tracing/expect/basic/ds/no-dst-id.data.expect [new file with mode: 0644]
tests/tracing/expect/basic/ds/no-dst-id.metadata.expect [new file with mode: 0644]
tests/tracing/src/basic/ds/no-dst-id.c [new file with mode: 0644]

index ec1e43ab68d84b36141d0b3218504fd92d40c8a4..b1f2c18f1f4921ba832104e62ea86f8469495444 100644 (file)
@@ -76,7 +76,9 @@ clock {
 {% for dst in cfg.trace.type.data_stream_types | sort %}
 /* Data stream type `{{ dst.name }}` */
 stream {
+       {% if cfg.trace.type.features.data_stream_type_id_field_type %}
        id = {{ dst.id }};
+       {% endif %}
        {{ root_ft('packet.context', dst._pkt_ctx_ft) | indent_tab }}
        {% if dst._er_header_ft %}
        {{ root_ft('event.header', dst._er_header_ft) | indent_tab }}
@@ -89,7 +91,9 @@ stream {
        {# data stream type's event record types #}
        {% for ert in dst.event_record_types | sort %}
 event {
+       {% if cfg.trace.type.features.data_stream_type_id_field_type %}
        stream_id = {{ dst.id }};
+       {% endif %}
        id = {{ ert.id }};
        name = "{{ ert.name }}";
                {% if ert.log_level %}
diff --git a/tests/tracing/configs/basic/ds/no-dst-id.yaml b/tests/tracing/configs/basic/ds/no-dst-id.yaml
new file mode 100644 (file)
index 0000000..08fad38
--- /dev/null
@@ -0,0 +1,66 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# Test Purpose
+#
+# This test configuration aims to verify that when the config property
+# 'data-stream-type-id-field-type' is set to false, that the metadata
+# file generated by barectf will not mention the  type id (in either the
+# stream type description or in the event type descriptions).
+#
+# This makes sure that two common CTF trace readers (Babeltrace and
+# Trace Compass) will be able to read the traces produced.
+
+%YAML 1.2
+--- !<tag:barectf.org,2020/3/config>
+trace:
+  type:
+    $include:
+      - base.yaml
+      - stdmisc.yaml
+    $features:
+      magic-field-type: false
+      uuid-field-type: false
+      data-stream-type-id-field-type: false
+    data-stream-types:
+      default:
+        $features:
+          packet:
+            total-size-field-type:
+              class: unsigned-integer
+              size: 16
+            content-size-field-type:
+              class: unsigned-integer
+              size: 16
+            beginning-timestamp-field-type: false
+            end-timestamp-field-type: false
+          event-record:
+            type-id-field-type: false
+            timestamp-field-type: false
+        event-record-types:
+          my_event:
+            payload-field-type:
+              class: structure
+              members:
+                - my_field: string
diff --git a/tests/tracing/expect/basic/ds/no-dst-id.data.expect b/tests/tracing/expect/basic/ds/no-dst-id.data.expect
new file mode 100644 (file)
index 0000000..adad9a6
Binary files /dev/null and b/tests/tracing/expect/basic/ds/no-dst-id.data.expect differ
diff --git a/tests/tracing/expect/basic/ds/no-dst-id.metadata.expect b/tests/tracing/expect/basic/ds/no-dst-id.metadata.expect
new file mode 100644 (file)
index 0000000..f252294
--- /dev/null
@@ -0,0 +1,76 @@
+/* CTF 1.8 */
+
+/*
+ * The MIT License (MIT)
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ *
+ *
+ * For more details, see <https://barectf.org/>.
+ */
+
+trace {
+       major = 1;
+       minor = 8;
+       byte_order = le;
+       packet.header := struct {
+       } align(8);
+};
+
+env {
+       domain = "bare";
+       tracer_name = "barectf";
+};
+
+/* Data stream type `default` */
+stream {
+       packet.context := struct {
+               integer {
+                       signed = false;
+                       size = 16;
+                       align = 8;
+                       byte_order = native;
+                       base = 10;
+               } packet_size;
+               integer {
+                       signed = false;
+                       size = 16;
+                       align = 8;
+                       byte_order = native;
+                       base = 10;
+               } content_size;
+       } align(8);
+       event.header := struct {
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "my_event";
+       fields := struct {
+               string {
+                       encoding = UTF8;
+               } my_field;
+       } align(1);
+};
diff --git a/tests/tracing/src/basic/ds/no-dst-id.c b/tests/tracing/src/basic/ds/no-dst-id.c
new file mode 100644 (file)
index 0000000..8bb300a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+
+#include "test-platform.h"
+#include "barectf.h"
+
+int main(void)
+{
+       struct test_platform_ctx * const platform_ctx = test_platform_init(128);
+
+       assert(platform_ctx);
+       barectf_default_trace_my_event(test_platform_barectf_ctx(platform_ctx),
+               "When she was younger, Akko went to a magic show hosted by a witch named Shiny Chariot.");
+       barectf_default_trace_my_event(test_platform_barectf_ctx(platform_ctx),
+               "Akko was so inspired that she dreamed to someday be a cool witch.");
+       test_platform_fini(platform_ctx);
+       return 0;
+}
This page took 0.028769 seconds and 4 git commands to generate.