clock: use freq field
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 9 Feb 2012 13:44:48 +0000 (08:44 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 9 Feb 2012 13:44:48 +0000 (08:44 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/ctf-ir/metadata.h

index f1c0de478ba7f5cc60a1c9e0ffa99555136eab49..80bd37869ed897f947c1b99e3f871b3d93d9692d 100644 (file)
@@ -107,6 +107,9 @@ struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
        .close_trace = ctf_close_trace,
 };
 
+/*
+ * Update stream current timestamp, keep at clock frequency.
+ */
 static
 void ctf_update_timestamp(struct ctf_stream *stream,
                          struct definition_integer *integer_definition)
 static
 void ctf_update_timestamp(struct ctf_stream *stream,
                          struct definition_integer *integer_definition)
@@ -134,6 +137,10 @@ void ctf_update_timestamp(struct ctf_stream *stream,
        stream->timestamp = updateval;
 }
 
        stream->timestamp = updateval;
 }
 
+/*
+ * Print timestamp, rescaling clock frequency to nanoseconds and
+ * applying offsets as needed (unix time).
+ */
 void ctf_print_timestamp(FILE *fp,
                        struct ctf_stream *stream,
                        uint64_t timestamp)
 void ctf_print_timestamp(FILE *fp,
                        struct ctf_stream *stream,
                        uint64_t timestamp)
@@ -143,7 +150,12 @@ void ctf_print_timestamp(FILE *fp,
        struct trace_collection *tc = trace->collection;
        uint64_t tc_offset = tc->single_clock_offset_avg;
 
        struct trace_collection *tc = trace->collection;
        uint64_t tc_offset = tc->single_clock_offset_avg;
 
-       ts_nsec = timestamp;
+       if (stream->current_clock->freq == 1000000000ULL) {
+               ts_nsec = timestamp;
+       } else {
+               ts_nsec = (uint64_t) ((double) timestamp * 1000000000.0
+                               / (double) stream->current_clock->freq);
+       }
 
        /* Add offsets */
        if (!opt_clock_raw) {
 
        /* Add offsets */
        if (!opt_clock_raw) {
@@ -1249,6 +1261,10 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
        ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
                goto error_def;
        ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
                goto error_def;
+       /*
+        * For now, only a single slock is supported.
+        */
+       file_stream->parent.current_clock = td->single_clock;
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
index 4a71a27e04024dae8ecfab95d69cd5854391bc13..5b26ec66c1ab142b02524de7d5f958ff356b9ea4 100644 (file)
@@ -2273,6 +2273,8 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
        struct ctf_clock *clock;
 
        clock = g_new0(struct ctf_clock, 1);
        struct ctf_clock *clock;
 
        clock = g_new0(struct ctf_clock, 1);
+       /* Default clock frequency is set to 1000000000 */
+       clock->freq = 1000000000ULL;
        cds_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
                ret = ctf_clock_declaration_visit(fd, depth + 1, iter, clock, trace);
                if (ret)
        cds_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
                ret = ctf_clock_declaration_visit(fd, depth + 1, iter, clock, trace);
                if (ret)
@@ -2283,6 +2285,12 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
                fprintf(fd, "[error] %s: missing namefield in clock declaration\n", __func__);
                goto error;
        }
                fprintf(fd, "[error] %s: missing namefield in clock declaration\n", __func__);
                goto error;
        }
+       if (g_hash_table_size(trace->clocks) > 0) {
+               fprintf(stderr, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
+               ret = -EINVAL;
+               goto error;
+       }
+       trace->single_clock = clock;
        g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
        return 0;
 
        g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
        return 0;
 
index d445a011c0bc2740a337e721b2e1873a190515d6..79af77a768c0dda06e02023ba25850a8bde41dac 100644 (file)
@@ -32,6 +32,8 @@ struct ctf_trace;
 struct ctf_stream_class;
 struct ctf_stream;
 struct ctf_event;
 struct ctf_stream_class;
 struct ctf_stream;
 struct ctf_event;
+struct ctf_stream;
+struct ctf_clock;
 
 struct ctf_stream {
        struct ctf_stream_class *stream_class;
 
 struct ctf_stream {
        struct ctf_stream_class *stream_class;
@@ -48,6 +50,8 @@ struct ctf_stream {
        struct definition_scope *parent_def_scope;      /* for initialization */
        int stream_definitions_created;
 
        struct definition_scope *parent_def_scope;      /* for initialization */
        int stream_definitions_created;
 
+       struct ctf_clock *current_clock;
+
        /* Event discarded information */
        uint32_t events_discarded;
        uint64_t prev_timestamp;        /* Last event */
        /* Event discarded information */
        uint32_t events_discarded;
        uint64_t prev_timestamp;        /* Last event */
@@ -133,6 +137,7 @@ struct ctf_trace {
        GPtrArray *streams;                     /* Array of struct ctf_stream_class pointers */
        struct ctf_stream *metadata;
        GHashTable *clocks;
        GPtrArray *streams;                     /* Array of struct ctf_stream_class pointers */
        struct ctf_stream *metadata;
        GHashTable *clocks;
+       struct ctf_clock *single_clock;         /* currently supports only one clock */
        struct trace_collection *collection;    /* Container of this trace */
 
        struct declaration_struct *packet_header_decl;
        struct trace_collection *collection;    /* Container of this trace */
 
        struct declaration_struct *packet_header_decl;
This page took 0.027976 seconds and 4 git commands to generate.