From 57f3005ee4ea188f0a78edbd172a6bad9a70d3f5 Mon Sep 17 00:00:00 2001 From: "Signed-off-by: Julien Desfossez" Date: Thu, 23 Feb 2012 07:37:06 -0500 Subject: [PATCH] API : export the offsetted timestamp We export now the offsetted view of the timestamp as well as the raw timestamp to the users. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- formats/ctf/events.c | 31 +++++++++++++++++++++++++++++-- include/babeltrace/ctf/events.h | 9 ++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 22623aa5..d14836b0 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -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) diff --git a/include/babeltrace/ctf/events.h b/include/babeltrace/ctf/events.h index c08314f8..01ee7a99 100644 --- a/include/babeltrace/ctf/events.h +++ b/include/babeltrace/ctf/events.h @@ -123,7 +123,14 @@ struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, const char *bt_ctf_event_name(struct bt_ctf_event *event); /* - * bt_ctf_get_timestamp: returns the timestamp of the event or -1ULL on error + * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in + * the packet or -1ULL on error + */ +uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event); + +/* + * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the + * system clock source or -1ULL on error */ uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event); -- 2.34.1