API : export the offsetted timestamp
[babeltrace.git] / formats / ctf / events.c
index 8ecb7c487f74384847b6f02aced03035c7ce3ee1..d14836b07135e25a447e23b68dd4c42e4f5229d6 100644 (file)
@@ -224,7 +224,7 @@ const char *bt_ctf_field_name(const struct definition *def)
        return NULL;
 }
 
-enum ctf_type_id bt_ctf_field_type(struct definition *def)
+enum ctf_type_id bt_ctf_field_type(const struct definition *def)
 {
        if (def)
                return def->declaration->id;
@@ -317,12 +317,39 @@ error:
        return -1;
 }
 
-uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event)
+uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event)
 {
        if (event && event->stream->has_timestamp)
                return event->stream->timestamp;
        else
-               return 0;
+               return -1ULL;
+}
+
+uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event)
+{
+       uint64_t ts_nsec;
+       struct ctf_trace *trace;
+       struct trace_collection *tc;
+       uint64_t tc_offset;
+       uint64_t timestamp;
+
+       if (!event->stream->has_timestamp) {
+               return -1ULL;
+       }
+
+       trace = event->stream->stream_class->trace;
+       tc = trace->collection;
+       tc_offset = tc->single_clock_offset_avg;
+       timestamp = event->stream->timestamp;
+       if (event->stream->current_clock->freq == 1000000000ULL) {
+               ts_nsec = timestamp;
+       } else {
+               ts_nsec = (uint64_t) ((double) timestamp * 1000000000.0
+                               / (double) event->stream->current_clock->freq);
+       }
+       ts_nsec += tc_offset;
+
+       return ts_nsec;
 }
 
 static void bt_ctf_field_set_error(int error)
@@ -339,7 +366,7 @@ int bt_ctf_field_get_error(void)
        return ret;
 }
 
-uint64_t bt_ctf_get_uint64(struct definition *field)
+uint64_t bt_ctf_get_uint64(const struct definition *field)
 {
        unsigned int ret = 0;
 
@@ -351,7 +378,7 @@ uint64_t bt_ctf_get_uint64(struct definition *field)
        return ret;
 }
 
-int64_t bt_ctf_get_int64(struct definition *field)
+int64_t bt_ctf_get_int64(const struct definition *field)
 {
        int ret = 0;
 
@@ -364,7 +391,7 @@ int64_t bt_ctf_get_int64(struct definition *field)
 
 }
 
-char *bt_ctf_get_char_array(struct definition *field)
+char *bt_ctf_get_char_array(const struct definition *field)
 {
        char *ret = NULL;
 
@@ -376,7 +403,7 @@ char *bt_ctf_get_char_array(struct definition *field)
        return ret;
 }
 
-char *bt_ctf_get_string(struct definition *field)
+char *bt_ctf_get_string(const struct definition *field)
 {
        char *ret = NULL;
 
This page took 0.024307 seconds and 4 git commands to generate.