Fix compiler warnings
[babeltrace.git] / plugins / text / print.c
index 53adab4c738d56bd43aa65a3f4cc7cc8da23c0f3..df0bea5ef6cc8fd78e7be0dd9f2f82e387f37ebb 100644 (file)
@@ -4,6 +4,7 @@
  * Babeltrace CTF Text Output Plugin Event Printing
  *
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
@@ -81,6 +82,11 @@ 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
@@ -108,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) {
@@ -136,7 +147,7 @@ void print_timestamp_wall(struct text_component *text,
                ts_nsec_abs = -ts_nsec;
        }
 
-       if (/*!opt_clock_seconds*/true) {
+       if (!text->options.clock_seconds) {
                struct tm tm;
                time_t time_s = (time_t) ts_sec_abs;
 
@@ -145,7 +156,7 @@ void print_timestamp_wall(struct text_component *text,
                        goto seconds;
                }
 
-               if (/*!opt_clock_gmt*/true) {
+               if (!text->options.clock_gmt) {
                        struct tm *res;
 
                        res = localtime_r(&time_s, &tm);
@@ -162,7 +173,7 @@ void print_timestamp_wall(struct text_component *text,
                                goto seconds;
                        }
                }
-               if (/*opt_clock_date*/false) {
+               if (text->options.clock_date) {
                        char timestr[26];
                        size_t res;
 
@@ -198,8 +209,6 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
        struct bt_ctf_trace *trace = NULL;
        struct bt_ctf_clock *clock = NULL;
        FILE *out = text->out;
-       FILE *err = text->err;
-       uint64_t real_timestamp;
 
        stream = bt_ctf_event_get_stream(event);
        if (!stream) {
@@ -207,10 +216,21 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
                goto end;
        }
 
-       /* FIXME - error checking */
        stream_class = bt_ctf_stream_get_class(stream);
+       if (!stream_class) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
        trace = bt_ctf_stream_class_get_trace(stream_class);
+       if (!trace) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
        clock = bt_ctf_trace_get_clock(trace, 0);
+       if (!clock) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
 
        fputs(print_names ? "timestamp = " : "[", out);
        if (text->options.print_timestamp_cycles) {
@@ -221,11 +241,37 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
 
        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);
+               }
        }
+       *start_line = !print_names;
+
 end:
        bt_put(stream);
        bt_put(clock);
@@ -433,16 +479,6 @@ enum bt_component_status print_event_header(struct text_component *text,
                        bt_put(uri_str);
                }
        }
-       if (text->options.print_callsite_field) {
-               if (!text->start_line) {
-                       fputs(", ", text->out);
-               }
-               text->start_line = false;
-               if (print_names) {
-                       fputs("callsite = ", text->out);
-               }
-               /* TODO */
-       }
        if (!text->start_line) {
                fputs(", ", text->out);
        }
@@ -997,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) {
@@ -1024,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) {
@@ -1050,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) {
@@ -1076,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) {
@@ -1102,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.02674 seconds and 4 git commands to generate.