text output plugin: print time delta
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 24 Nov 2016 23:08:15 +0000 (18:08 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/text/print.c
plugins/text/text.c
plugins/text/text.h

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);
index f5a62c63aeaa69ea82fb8758d7548f92e40c9589..89fa59901d63cac78c253175822b8e155d253017 100644 (file)
@@ -613,6 +613,12 @@ enum bt_component_status text_component_init(
        text->out = stdout;
        text->err = stderr;
 
+       text->delta_cycles = -1ULL;
+       text->last_cycles_timestamp = -1ULL;
+
+       text->delta_real_timestamp = -1ULL;
+       text->last_real_timestamp = -1ULL;
+
        ret = apply_params(text, params);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
index 2c846da8b4c6401398a0873bb6aee0ae1c2fd9f7..5697e2ee5e974c3c7a98d56dffcb4bd3acd09325 100644 (file)
@@ -70,11 +70,16 @@ struct text_component {
        struct text_options options;
        FILE *out, *err;
        bool processed_first_event;
-       uint64_t last_real_timestamp;
        int depth;      /* nesting, used for tabulation alignment. */
        bool start_line;
        GString *string;
        struct bt_value *plugin_opt_map;        /* Temporary parameter map. */
+
+       uint64_t last_cycles_timestamp;
+       uint64_t delta_cycles;
+
+       uint64_t last_real_timestamp;
+       uint64_t delta_real_timestamp;
 };
 
 BT_HIDDEN
This page took 0.027526 seconds and 4 git commands to generate.