Support for --clock-offset and --clock-offset-ns
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 21 Mar 2017 17:41:28 +0000 (13:41 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:39 +0000 (12:57 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/common/metadata/ast.h
plugins/ctf/common/metadata/visitor-generate-ir.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h
plugins/ctf/fs/metadata.c

index c8843270657ea012bdb1e03d00efea6d519eb86b..232c2e75a945bc1a28ec5eec7b6a605d04b8ba02 100644 (file)
@@ -307,7 +307,7 @@ struct ctf_trace;
 
 BT_HIDDEN
 int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node,
-               struct bt_ctf_trace **trace);
+               struct bt_ctf_trace **trace, uint64_t clock_offset_ns);
 
 BT_HIDDEN
 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
index c16c97065a868c5676c61289c2da091f58929fde..da979078956216f84bf97e5b1f005c94c82ee0b1 100644 (file)
@@ -4382,7 +4382,53 @@ error:
 }
 
 static
-int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
+uint64_t cycles_from_ns(uint64_t frequency, uint64_t ns)
+{
+       uint64_t cycles;
+
+       /* 1GHz */
+       if (frequency == 1000000000ULL) {
+               cycles = ns;
+       } else {
+               cycles = (uint64_t) (((double) ns * (double) frequency) / 1e9);
+       }
+
+       return cycles;
+}
+
+static
+int apply_clock_offset(struct ctx *ctx, struct bt_ctf_clock_class *clock,
+               uint64_t clock_offset_ns)
+{
+       int ret;
+       uint64_t freq;
+       int64_t offset_cycles;
+
+       freq = bt_ctf_clock_class_get_frequency(clock);
+       if (freq == -1ULL) {
+               _PERROR("%s", "No clock frequency");
+               ret = -1;
+               goto end;
+       }
+
+       ret = bt_ctf_clock_class_get_offset_cycles(clock, &offset_cycles);
+       if (ret) {
+               _PERROR("%s", "Getting offset cycles");
+               ret = -1;
+               goto end;
+       }
+
+       offset_cycles += cycles_from_ns(freq, clock_offset_ns);
+
+       ret = bt_ctf_clock_class_set_offset_cycles(clock, offset_cycles);
+
+end:
+       return ret;
+}
+
+static
+int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node,
+               uint64_t clock_offset_ns)
 {
        int ret = 0;
        int set = 0;
@@ -4422,6 +4468,12 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                goto error;
        }
 
+       ret = apply_clock_offset(ctx, clock, clock_offset_ns);
+       if (ret) {
+               _PERROR("%s", "cannot apply clock offset ");
+               goto error;
+       }
+
        ret = bt_ctf_trace_add_clock_class(ctx->trace, clock);
        if (ret) {
                _PERROR("%s", "cannot add clock to trace");
@@ -4514,7 +4566,7 @@ end:
 }
 
 int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node,
-       struct bt_ctf_trace **trace)
+       struct bt_ctf_trace **trace, uint64_t clock_offset_ns)
 {
        int ret = 0;
        struct ctx *ctx = NULL;
@@ -4582,7 +4634,7 @@ int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node,
                 * to one.
                 */
                bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
-                       ret = visit_clock_decl(ctx, iter);
+                       ret = visit_clock_decl(ctx, iter, clock_offset_ns);
                        if (ret) {
                                _PERROR("error while visiting clock declaration (%d)",
                                        ret);
index ea33974bde4045609ece5e481b483e538970cbe7..ece7ff97cbe1e0a9fdfa19ee18c286134d7beda4 100644 (file)
@@ -402,8 +402,49 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
 
        ctf_fs->trace_path = g_string_new(path);
        if (!ctf_fs->trace_path) {
+               BT_PUT(value);
                goto error;
        }
+       bt_put(value);
+
+       value = bt_value_map_get(params, "offset-s");
+       if (value) {
+               int64_t offset;
+
+               if (!bt_value_is_integer(value)) {
+                       fprintf(stderr,
+                               "offset-s should be an integer\n");
+                       goto error;
+               }
+               ret = bt_value_integer_get(value, &offset);
+               if (ret != BT_VALUE_STATUS_OK) {
+                       fprintf(stderr,
+                               "Failed to get offset-s value\n");
+                       goto error;
+               }
+               ctf_fs->options.clock_offset = offset;
+               bt_put(value);
+       }
+
+       value = bt_value_map_get(params, "offset-ns");
+       if (value) {
+               int64_t offset;
+
+               if (!bt_value_is_integer(value)) {
+                       fprintf(stderr,
+                               "offset-ns should be an integer\n");
+                       goto error;
+               }
+               ret = bt_value_integer_get(value, &offset);
+               if (ret != BT_VALUE_STATUS_OK) {
+                       fprintf(stderr,
+                               "Failed to get offset-ns value\n");
+                       goto error;
+               }
+               ctf_fs->options.clock_offset_ns = offset;
+               bt_put(value);
+       }
+
        ctf_fs->error_fp = stderr;
        ctf_fs->page_size = (size_t) getpagesize();
 
@@ -434,7 +475,6 @@ error:
        ctf_fs_destroy_data(ctf_fs);
        ctf_fs = NULL;
 end:
-       BT_PUT(value);
        return ctf_fs;
 }
 
index 720102987572484766a41a4c89be2f10df7c4954..0e286f1770c8431c75d6bcfec8f812f624cdbe0a 100644 (file)
@@ -78,6 +78,8 @@ struct ctf_fs_stream {
 };
 
 struct ctf_fs_component_options {
+       uint64_t clock_offset;
+       uint64_t clock_offset_ns;
 };
 
 struct ctf_fs_port_data {
index 063ebe56c7d74a77f765b6589d61b5a491573db1..5c64113c3b5d7eef3f3b9e2b478ae8151ecbd427 100644 (file)
@@ -43,6 +43,8 @@
 
 #define TSDL_MAGIC     0x75d11d57
 
+#define NSEC_PER_SEC 1000000000LL
+
 struct packet_header {
        uint32_t magic;
        uint8_t  uuid[16];
@@ -398,7 +400,9 @@ int ctf_fs_metadata_set_trace(struct ctf_fs_component *ctf_fs)
        }
 
        ret = ctf_visitor_generate_ir(ctf_fs->error_fp, &scanner->ast->root,
-               &ctf_fs->metadata->trace);
+               &ctf_fs->metadata->trace,
+               ctf_fs->options.clock_offset * NSEC_PER_SEC +
+               ctf_fs->options.clock_offset_ns);
        if (ret) {
                PERR("Cannot create trace object from metadata AST\n");
                goto error;
This page took 0.029246 seconds and 4 git commands to generate.