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);
}
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;
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");
}
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;
* 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);
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();
ctf_fs_destroy_data(ctf_fs);
ctf_fs = NULL;
end:
- BT_PUT(value);
return ctf_fs;
}
};
struct ctf_fs_component_options {
+ uint64_t clock_offset;
+ uint64_t clock_offset_ns;
};
struct ctf_fs_port_data {
#define TSDL_MAGIC 0x75d11d57
+#define NSEC_PER_SEC 1000000000LL
+
struct packet_header {
uint32_t magic;
uint8_t uuid[16];
}
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;