text output plugin: print time delta
[babeltrace.git] / plugins / text / print.c
index b227e399d219fa9510c16cd558822f995d95d05c..3a683a8388a12984729e71a4cd574437970f3773 100644 (file)
@@ -82,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
@@ -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) {
@@ -233,13 +243,36 @@ 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);
+               }
        }
-
-       //TODO delta
+       *start_line = !print_names;
 
 end:
        bt_put(stream);
This page took 0.024112 seconds and 4 git commands to generate.