Combine duplicated API/pretty-print timestamp code
[babeltrace.git] / formats / ctf / events.c
index d14836b07135e25a447e23b68dd4c42e4f5229d6..39620383879b3aae0076bb9aedf710e2d9c88d22 100644 (file)
@@ -29,6 +29,8 @@
 #include <babeltrace/ctf/metadata.h>
 #include <glib.h>
 
+#include "events-private.h"
+
 /*
  * thread local storage to store the last error that occured
  * while reading a field, this variable must be accessed by
@@ -320,36 +322,19 @@ error:
 uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event)
 {
        if (event && event->stream->has_timestamp)
-               return event->stream->timestamp;
+               return ctf_get_timestamp_raw(event->stream,
+                               event->stream->timestamp);
        else
                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) {
+       if (event && event->stream->has_timestamp)
+               return ctf_get_timestamp(event->stream,
+                               event->stream->timestamp);
+       else
                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)
This page took 0.024075 seconds and 4 git commands to generate.