Support for --clock-offset and --clock-offset-ns
[babeltrace.git] / plugins / ctf / fs / fs.c
index ea45fbca792bbd9061844281a3054ff2a77ab558..ece7ff97cbe1e0a9fdfa19ee18c286134d7beda4 100644 (file)
@@ -34,6 +34,7 @@
 #include <babeltrace/graph/private-notification-iterator.h>
 #include <babeltrace/graph/component.h>
 #include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <plugins-common.h>
 #include <glib.h>
 #include <assert.h>
@@ -140,6 +141,7 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs)
                g_free(ctf_fs->metadata);
        }
 
+       bt_put(ctf_fs->cc_prio_map);
        g_free(ctf_fs);
 }
 
@@ -325,6 +327,42 @@ end:
        return ret;
 }
 
+static
+int create_cc_prio_map(struct ctf_fs_component *ctf_fs)
+{
+       int ret = 0;
+       size_t i;
+       int count;
+
+       assert(ctf_fs);
+       ctf_fs->cc_prio_map = bt_clock_class_priority_map_create();
+       if (!ctf_fs->cc_prio_map) {
+               ret = -1;
+               goto end;
+       }
+
+       count = bt_ctf_trace_get_clock_class_count(ctf_fs->metadata->trace);
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               struct bt_ctf_clock_class *clock_class =
+                       bt_ctf_trace_get_clock_class(ctf_fs->metadata->trace,
+                               i);
+
+               assert(clock_class);
+               ret = bt_clock_class_priority_map_add_clock_class(
+                       ctf_fs->cc_prio_map, clock_class, 0);
+               BT_PUT(clock_class);
+
+               if (ret) {
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
 static
 struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
                struct bt_value *params)
@@ -364,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();
 
@@ -380,6 +459,11 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
                goto error;
        }
 
+       ret = create_cc_prio_map(ctf_fs);
+       if (ret) {
+               goto error;
+       }
+
        ret = create_ports(ctf_fs);
        if (ret) {
                goto error;
@@ -391,7 +475,6 @@ error:
        ctf_fs_destroy_data(ctf_fs);
        ctf_fs = NULL;
 end:
-       BT_PUT(value);
        return ctf_fs;
 }
 
This page took 0.026154 seconds and 4 git commands to generate.