From 3af83b5a0b18de8603239be8d7d50020d76c3d21 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 24 Nov 2016 18:08:15 -0500 Subject: [PATCH] text output plugin: print time delta MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- plugins/text/print.c | 43 ++++++++++++++++++++++++++++++++++++++----- plugins/text/text.c | 6 ++++++ plugins/text/text.h | 7 ++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/plugins/text/print.c b/plugins/text/print.c index b227e399..3a683a83 100644 --- a/plugins/text/print.c +++ b/plugins/text/print.c @@ -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); diff --git a/plugins/text/text.c b/plugins/text/text.c index f5a62c63..89fa5990 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -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; diff --git a/plugins/text/text.h b/plugins/text/text.h index 2c846da8..5697e2ee 100644 --- a/plugins/text/text.h +++ b/plugins/text/text.h @@ -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 -- 2.34.1