ir: add bt_ctf_clock_class object, modify bt_ctf_clock object
[babeltrace.git] / plugins / text / print.c
index b227e399d219fa9510c16cd558822f995d95d05c..c1ae888bcf370fef83cb4f5dcf9732664099bea1 100644 (file)
@@ -32,7 +32,7 @@
 #include <babeltrace/ctf-ir/packet.h>
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock.h>
+#include <babeltrace/ctf-ir/clock-class.h>
 #include <babeltrace/ctf-ir/field-types.h>
 #include <babeltrace/ctf-ir/fields.h>
 #include <babeltrace/ctf-ir/trace.h>
@@ -62,14 +62,14 @@ enum bt_component_status print_field(struct text_component *text,
 
 static
 void print_timestamp_cycles(struct text_component *text,
-               struct bt_ctf_clock *clock,
+               struct bt_ctf_clock_class *clock_class,
                struct bt_ctf_event *event)
 {
        int ret;
        struct bt_ctf_clock_value *clock_value;
        uint64_t cycles;
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock);
+       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
        if (!clock_value) {
                fputs("????????????????????", text->out);
                return;
@@ -82,11 +82,16 @@ void print_timestamp_cycles(struct text_component *text,
                return;
        }
        fprintf(text->out, "%020" PRIu64, cycles);
+
+       if (text->last_cycles_timestamp != -1ULL) {
+               text->delta_cycles = cycles - text->last_cycles_timestamp;
+       }
+       text->last_cycles_timestamp = cycles;
 }
 
 static
 void print_timestamp_wall(struct text_component *text,
-               struct bt_ctf_clock *clock,
+               struct bt_ctf_clock_class *clock_class,
                struct bt_ctf_event *event)
 {
        int ret;
@@ -96,7 +101,7 @@ void print_timestamp_wall(struct text_component *text,
        uint64_t ts_sec_abs, ts_nsec_abs;
        bool is_negative;
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock);
+       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
        if (!clock_value) {
                fputs("??:??:??.?????????", text->out);
                return;
@@ -109,6 +114,11 @@ void print_timestamp_wall(struct text_component *text,
                return;
        }
 
+       if (text->last_real_timestamp != -1ULL) {
+               text->delta_real_timestamp = ts_nsec - text->last_real_timestamp;
+       }
+       text->last_real_timestamp = ts_nsec;
+
        ts_sec += ts_nsec / NSEC_PER_SEC;
        ts_nsec = ts_nsec % NSEC_PER_SEC;
        if (ts_sec >= 0 && ts_nsec >= 0) {
@@ -197,10 +207,8 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
        struct bt_ctf_stream *stream = NULL;
        struct bt_ctf_stream_class *stream_class = NULL;
        struct bt_ctf_trace *trace = NULL;
-       struct bt_ctf_clock *clock = NULL;
+       struct bt_ctf_clock_class *clock_class = NULL;
        FILE *out = text->out;
-       FILE *err = text->err;
-       uint64_t real_timestamp;
 
        stream = bt_ctf_event_get_stream(event);
        if (!stream) {
@@ -218,32 +226,55 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       clock = bt_ctf_trace_get_clock(trace, 0);
-       if (!clock) {
+       clock_class = bt_ctf_trace_get_clock_class(trace, 0);
+       if (!clock_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
        fputs(print_names ? "timestamp = " : "[", out);
        if (text->options.print_timestamp_cycles) {
-               print_timestamp_cycles(text, clock, event);
+               print_timestamp_cycles(text, clock_class, event);
        } else {
-               print_timestamp_wall(text, clock, event);
+               print_timestamp_wall(text, clock_class, event);
        }
 
        if (!print_names)
                fputs("] ", out);
-       *start_line = !print_names;
 
-       if (!text->options.print_delta_field) {
-               goto end;
+       if (text->options.print_delta_field) {
+               if (print_names)
+                       fputs(", delta = ", text->out);
+               else
+                       fputs("(", text->out);
+               if (text->options.print_timestamp_cycles) {
+                       if (text->delta_cycles == -1ULL) {
+                               fputs("+??????????\?\?) ", text->out); /* Not a trigraph. */
+                       } else {
+                               fprintf(text->out, "+%012" PRIu64, text->delta_cycles);
+                       }
+               } else {
+                       if (text->delta_real_timestamp != -1ULL) {
+                               uint64_t delta_sec, delta_nsec, delta;
+
+                               delta = text->delta_real_timestamp;
+                               delta_sec = delta / NSEC_PER_SEC;
+                               delta_nsec = delta % NSEC_PER_SEC;
+                               fprintf(text->out, "+%" PRIu64 ".%09" PRIu64,
+                                       delta_sec, delta_nsec);
+                       } else {
+                               fputs("+?.?????????", text->out);
+                       }
+               }
+               if (!print_names) {
+                       fputs(") ", text->out);
+               }
        }
-
-       //TODO delta
+       *start_line = !print_names;
 
 end:
        bt_put(stream);
-       bt_put(clock);
+       bt_put(clock_class);
        bt_put(stream_class);
        bt_put(trace);
        return ret;
@@ -1002,7 +1033,6 @@ enum bt_component_status print_stream_packet_context(struct text_component *text
        }
        main_field = bt_ctf_packet_get_context(packet);
        if (!main_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        if (!text->start_line) {
@@ -1029,7 +1059,6 @@ enum bt_component_status print_event_header_raw(struct text_component *text,
 
        main_field = bt_ctf_event_get_header(event);
        if (!main_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        if (!text->start_line) {
@@ -1055,7 +1084,6 @@ enum bt_component_status print_stream_event_context(struct text_component *text,
 
        main_field = bt_ctf_event_get_stream_event_context(event);
        if (!main_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        if (!text->start_line) {
@@ -1081,7 +1109,6 @@ enum bt_component_status print_event_context(struct text_component *text,
 
        main_field = bt_ctf_event_get_event_context(event);
        if (!main_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        if (!text->start_line) {
@@ -1107,7 +1134,6 @@ enum bt_component_status print_event_payload(struct text_component *text,
 
        main_field = bt_ctf_event_get_payload_field(event);
        if (!main_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        if (!text->start_line) {
This page took 0.025341 seconds and 4 git commands to generate.