src.ctf.fs: add `force-clock-class-origin-unix-epoch` param
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 19 Sep 2019 19:56:44 +0000 (15:56 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 20 Sep 2019 19:11:35 +0000 (15:11 -0400)
The `force-clock-class-origin-unix-epoch` initialization parameter makes
all the created clock classes have a Unix epoch origin. This is useful
to force the clock classes of multiple traces to be compatible even if
they are not inherently.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: If311081052e9be28ca5782ee684b4ef7bba66176
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2069
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/common/metadata/decoder.h
src/plugins/ctf/common/metadata/visitor-generate-ir.c
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/metadata.c
src/plugins/ctf/fs-src/metadata.h
tests/data/plugins/src.ctf.fs/succeed/trace-2packets-barectf-event-before-packet.expect [new file with mode: 0644]
tests/plugins/src.ctf.fs/succeed/test_succeed

index d94128e1bfce4fa0e0e1f4756997526460d3a732..21a297802002cee88597bf9836a3f07279d808a2 100644 (file)
@@ -49,6 +49,7 @@ struct ctf_metadata_decoder_config {
        /* Additional clock class offset to apply */
        int64_t clock_class_offset_s;
        int64_t clock_class_offset_ns;
+       bool force_clock_class_origin_unix_epoch;
 
        /* True to create trace class objects */
        bool create_trace_class;
index f2ac49504df8d1f206044dc6f8d1319f0f9ca9b8..22379aa9d4ee3cc1f4a2cb232684bdd5f51a5f59 100644 (file)
@@ -4423,6 +4423,17 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds,
        }
 }
 
+static
+void apply_clock_class_is_absolute(struct ctx *ctx,
+               struct ctf_clock_class *clock)
+{
+       if (ctx->decoder_config.force_clock_class_origin_unix_epoch) {
+               clock->is_absolute = true;
+       }
+
+       return;
+}
+
 static
 void apply_clock_class_offset(struct ctx *ctx,
                struct ctf_clock_class *clock)
@@ -4550,6 +4561,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        clock->offset_seconds = offset_seconds;
        clock->offset_cycles = offset_cycles;
        apply_clock_class_offset(ctx, clock);
+       apply_clock_class_is_absolute(ctx, clock);
        g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
        clock = NULL;
 
index 454b4aeea88eb13613b4afdd3e3ffbe9d54f050b..f82ef74cafb38099050166a45639157641c51b27 100644 (file)
@@ -2275,6 +2275,20 @@ bool read_src_fs_parameters(const bt_value *params,
                        bt_value_integer_signed_get(value);
        }
 
+       /* force-clock-class-origin-unix-epoch parameter */
+       value = bt_value_map_borrow_entry_value_const(params,
+               "force-clock-class-origin-unix-epoch");
+       if (value) {
+               if (!bt_value_is_bool(value)) {
+                       BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class,
+                               "force-clock-class-origin-unix-epoch must be a boolean");
+                       goto error;
+               }
+
+               ctf_fs->metadata_config.force_clock_class_origin_unix_epoch =
+                       bt_value_bool_get(value);
+       }
+
        /* trace-name parameter */
        *trace_name = bt_value_map_borrow_entry_value_const(params, "trace-name");
        if (*trace_name) {
index 41948b79e690561833398f4607ffdee6d604a974..78cc593997e232a3b0a9efe4f149443789880c7d 100644 (file)
@@ -102,6 +102,8 @@ int ctf_fs_metadata_set_trace_class(
                .self_comp = self_comp,
                .clock_class_offset_s = config ? config->clock_class_offset_s : 0,
                .clock_class_offset_ns = config ? config->clock_class_offset_ns : 0,
+               .force_clock_class_origin_unix_epoch =
+                       config ? config->force_clock_class_origin_unix_epoch : false,
                .create_trace_class = true,
        };
        bt_logging_level log_level = ctf_fs_trace->log_level;
index a5d0986d34cd18905b094f5e2f7d9278eb567608..9a17fa43cba9e3f2ebff83abd7dbf82c0107458d 100644 (file)
@@ -34,6 +34,7 @@ struct ctf_fs_trace;
 struct ctf_fs_metadata;
 
 struct ctf_fs_metadata_config {
+       bool force_clock_class_origin_unix_epoch;
        int64_t clock_class_offset_s;
        int64_t clock_class_offset_ns;
 };
diff --git a/tests/data/plugins/src.ctf.fs/succeed/trace-2packets-barectf-event-before-packet.expect b/tests/data/plugins/src.ctf.fs/succeed/trace-2packets-barectf-event-before-packet.expect
new file mode 100644 (file)
index 0000000..5cb95aa
--- /dev/null
@@ -0,0 +1,64 @@
+Trace class:
+  Stream class (ID 0):
+    Supports packets: Yes
+    Packets have beginning default clock snapshot: Yes
+    Packets have end default clock snapshot: Yes
+    Supports discarded events: Yes
+    Discarded events have default clock snapshots: Yes
+    Supports discarded packets: Yes
+    Discarded packets have default clock snapshots: Yes
+    Default clock class:
+      Name: monotonic
+      Description: Monotonic Clock
+      Frequency (Hz): 1,000,000,000
+      Precision (cycles): 0
+      Offset (s): 1,561,498,843
+      Offset (cycles): 433,067,926
+      Origin is Unix epoch: Yes
+      UUID: db965ea1-f862-45a3-ab65-602642fdad90
+    Packet context field class: Structure (1 member):
+      cpu_id: Unsigned integer (32-bit, Base 10)
+    Event common context field class: Structure (1 member):
+      vpid: Signed integer (32-bit, Base 10)
+    Event class `lttng_ust_statedump:procname` (ID 0):
+      Log level: Debug (line)
+      Payload field class: Structure (1 member):
+        procname: String
+
+[Unknown] {0 0 2} Stream beginning
+
+Trace class:
+  Stream class (ID 0):
+    Supports packets: Yes
+    Packets have beginning default clock snapshot: Yes
+    Packets have end default clock snapshot: Yes
+    Supports discarded events: Yes
+    Discarded events have default clock snapshots: Yes
+    Supports discarded packets: No
+    Default clock class:
+      Name: default
+      Frequency (Hz): 1,000,000,000
+      Precision (cycles): 0
+      Offset (s): 1,434,072,888
+      Offset (cycles): 0
+      Origin is Unix epoch: Yes
+    Event class `simple_uint32` (ID 0):
+      Log level: Critical
+      Payload field class: Structure (1 member):
+        value: Unsigned integer (32-bit, Base 10)
+
+[Unknown] {1 0 0} Stream beginning
+[1,048,932,916,574,076 1,435,121,820,916,574,076] {1 0 0} Packet beginning
+[1,048,932,916,580,091 1,435,121,820,916,580,091] {1 0 0} Event `simple_uint32` (0)
+[1,048,932,916,584,407 1,435,121,820,916,584,407] {1 0 0} Packet end
+[1,048,932,916,605,259 1,435,121,820,916,605,259] {1 0 0} Packet beginning
+[1,048,932,916,605,259 1,435,121,820,916,605,259] {1 0 0} Event `simple_uint32` (0)
+[1,048,932,916,609,657 1,435,121,820,916,609,657] {1 0 0} Packet end
+[Unknown] {1 0 0} Stream end
+[257,960,472,138,367 1,561,756,803,905,206,293] {0 0 2} Packet beginning
+[257,960,490,358,932 1,561,756,803,923,426,858] {0 0 2} Event `lttng_ust_statedump:procname` (0)
+[257,963,419,223,089 1,561,756,806,852,291,015] {0 0 2} Packet end
+[257,971,894,873,186 1,561,756,815,327,941,112] {0 0 2} Packet beginning
+[257,971,894,873,186 1,561,756,815,327,941,112] {0 0 2} Event `lttng_ust_statedump:procname` (0)
+[257,974,030,386,677 1,561,756,817,463,454,603] {0 0 2} Packet end
+[Unknown] {0 0 2} Stream end
index b5c4b2b5f72d81020799c84efe221b3241a11af6..0cc3569912124fa5403f1428cab4f4b5f96c54f5 100755 (executable)
@@ -90,8 +90,48 @@ test_packet_end() {
        rm -f "$temp_stdout_output_file" "$temp_stderr_output_file" "$temp_greped_stdout_output_file"
 }
 
-plan_tests 7
+test_force_origin_unix_epoch() {
+       local name1="$1"
+       local name2="$2"
+       local expected_stdout="$expect_dir/trace-$name1-$name2.expect"
+       local ret=0
+       local ret_stdout
+       local ret_stderr
+       local src_ctf_fs_args=("-p" "force-clock-class-origin-unix-epoch=true")
+       local details_comp=("-c" "sink.text.details")
+       local details_args=("-p" "with-trace-name=no,with-stream-name=no,with-metadata=yes,compact=yes")
+       local temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
+       local temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
+
+       bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" \
+               "$succeed_trace_dir/$name1" "${src_ctf_fs_args[@]}" \
+               "$succeed_trace_dir/$name2" "${src_ctf_fs_args[@]}" \
+               "${details_comp[@]}" "${details_args[@]}"
+
+       bt_diff "$expected_stdout" "$temp_stdout_output_file"
+       ret_stdout=$?
+
+       if ((ret_stdout != 0)); then
+               ret=1
+       fi
+
+       ok $ret "Trace '$name1' and '$name2' give the expected stdout"
+
+       bt_diff /dev/null "$temp_stderr_output_file"
+       ret_stderr=$?
+
+       if ((ret_stderr != 0)); then
+               ret=1
+       fi
+
+       ok $ret "Trace '$name1' and '$name2' give the expected stderr"
+
+       rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
+}
+
+plan_tests 9
 
+test_force_origin_unix_epoch 2packets barectf-event-before-packet
 test_ctf_gen_single simple
 test_ctf_single smalltrace
 test_ctf_single 2packets
This page took 0.032862 seconds and 4 git commands to generate.