From: Mathieu Desnoyers Date: Sat, 7 Jan 2012 19:28:29 +0000 (-0500) Subject: Add time delta to ctf-text X-Git-Tag: v0.9~38 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=8d8ed9afdf03dc0808e25c0e68279bb31d54742f Add time delta to ctf-text Signed-off-by: Mathieu Desnoyers --- diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 2870df8f..6af4a8b9 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -58,6 +58,7 @@ enum { OPT_VERBOSE, OPT_DEBUG, OPT_NAMES, + OPT_NO_DELTA, }; static struct poptOption long_options[] = { @@ -69,6 +70,7 @@ static struct poptOption long_options[] = { { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL }, { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL }, { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL }, + { "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL }, { NULL, 0, 0, NULL, 0, NULL, NULL }, }; @@ -95,6 +97,7 @@ static void usage(FILE *fp) fprintf(fp, " (or set BABELTRACE_VERBOSE environment variable)\n"); fprintf(fp, " -d, --debug Debug mode\n"); fprintf(fp, " (or set BABELTRACE_DEBUG environment variable)\n"); + fprintf(fp, " --no-delta Do not print time delta between consecutive events\n"); fprintf(fp, " -n, --names name1<,name2,...> Print field names.\n"); fprintf(fp, " Available field names:\n"); fprintf(fp, " (payload OR args OR arg)\n"); @@ -187,6 +190,9 @@ static int parse_options(int argc, char **argv) case OPT_DEBUG: babeltrace_debug = 1; break; + case OPT_NO_DELTA: + opt_delta = 0; + break; default: ret = -EINVAL; goto end; diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 19e92fca..b1018c65 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -45,7 +45,8 @@ int opt_all_field_names, opt_trace_domain, opt_trace_procname, opt_trace_vpid, - opt_loglevel; + opt_loglevel, + opt_delta = 1; enum field_item { ITEM_SCOPE, @@ -200,6 +201,33 @@ int ctf_text_write_event(struct stream_pos *ppos, else fprintf(pos->fp, " "); } + if (opt_delta && stream->has_timestamp) { + uint64_t delta, delta_sec, delta_nsec; + + set_field_names_print(pos, ITEM_HEADER); + if (pos->print_names) + fprintf(pos->fp, "delta = "); + else + fprintf(pos->fp, "("); + if (pos->last_timestamp != -1ULL) { + delta = stream->timestamp - pos->last_timestamp; + delta_sec = delta / NSEC_PER_SEC; + delta_nsec = delta % NSEC_PER_SEC; + fprintf(pos->fp, "+%" PRIu64 ".%09" PRIu64, + delta_sec, delta_nsec); + } else { + fprintf(pos->fp, "+?.?????????"); + } + if (!pos->print_names) + fprintf(pos->fp, ")"); + + if (pos->print_names) + fprintf(pos->fp, ", "); + else + fprintf(pos->fp, " "); + pos->last_timestamp = stream->timestamp; + } + if ((opt_trace_name || opt_all_field_names) && stream_class->trace->path[0] != '\0') { set_field_names_print(pos, ITEM_HEADER); if (pos->print_names) { @@ -379,6 +407,7 @@ struct trace_descriptor *ctf_text_open_trace(const char *collection_path, pos = g_new0(struct ctf_text_stream_pos, 1); + pos->last_timestamp = -1ULL; switch (flags & O_ACCMODE) { case O_RDWR: if (!path) diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 991e23c4..e556092b 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -38,6 +38,7 @@ extern int opt_all_field_names, opt_trace_domain, opt_trace_procname, opt_trace_vpid, - opt_loglevel; + opt_loglevel, + opt_delta; #endif diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 7d9b5bfb..101873a9 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -39,6 +39,7 @@ struct ctf_text_stream_pos { int dummy; /* disable output */ int print_names; /* print field names */ int field_nr; + uint64_t last_timestamp; /* to print delta */ GString *string; /* Current string */ };