Add time delta to ctf-text
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 Jan 2012 19:28:29 +0000 (14:28 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 Jan 2012 19:28:29 +0000 (14:28 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/ctf-text/ctf-text.c
include/babeltrace/babeltrace-internal.h
include/babeltrace/ctf-text/types.h

index 2870df8fdbdb03216b18c15c2f0e3bd2644b84ce..6af4a8b9bccf1a816c4993bf10b42507b0b8f19e 100644 (file)
@@ -58,6 +58,7 @@ enum {
        OPT_VERBOSE,
        OPT_DEBUG,
        OPT_NAMES,
        OPT_VERBOSE,
        OPT_DEBUG,
        OPT_NAMES,
+       OPT_NO_DELTA,
 };
 
 static struct poptOption long_options[] = {
 };
 
 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 },
        { "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 },
 };
 
        { 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, "                                 (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");
        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_DEBUG:
                        babeltrace_debug = 1;
                        break;
+               case OPT_NO_DELTA:
+                       opt_delta = 0;
+                       break;
                default:
                        ret = -EINVAL;
                        goto end;
                default:
                        ret = -EINVAL;
                        goto end;
index 19e92fcabdf836fe909c703450f0133b8847b6a2..b1018c6576f2084fa3fb300225c8b1e72ea98271 100644 (file)
@@ -45,7 +45,8 @@ int opt_all_field_names,
        opt_trace_domain,
        opt_trace_procname,
        opt_trace_vpid,
        opt_trace_domain,
        opt_trace_procname,
        opt_trace_vpid,
-       opt_loglevel;
+       opt_loglevel,
+       opt_delta = 1;
 
 enum field_item {
        ITEM_SCOPE,
 
 enum field_item {
        ITEM_SCOPE,
@@ -200,6 +201,33 @@ int ctf_text_write_event(struct stream_pos *ppos,
                else
                        fprintf(pos->fp, " ");
        }
                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) {
        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 = g_new0(struct ctf_text_stream_pos, 1);
 
+       pos->last_timestamp = -1ULL;
        switch (flags & O_ACCMODE) {
        case O_RDWR:
                if (!path)
        switch (flags & O_ACCMODE) {
        case O_RDWR:
                if (!path)
index 991e23c45a145af2c62e41344578c085811d3404..e556092b76136799d1873988092464c5cd482c8c 100644 (file)
@@ -38,6 +38,7 @@ extern int opt_all_field_names,
        opt_trace_domain,
        opt_trace_procname,
        opt_trace_vpid,
        opt_trace_domain,
        opt_trace_procname,
        opt_trace_vpid,
-       opt_loglevel;
+       opt_loglevel,
+       opt_delta;
 
 #endif
 
 #endif
index 7d9b5bfb70b8a7da34ad88ff7c3b0566e9f1be44..101873a9d5af801bff4508bef1183728ff75e329 100644 (file)
@@ -39,6 +39,7 @@ struct ctf_text_stream_pos {
        int dummy;              /* disable output */
        int print_names;        /* print field names */
        int field_nr;
        int dummy;              /* disable output */
        int print_names;        /* print field names */
        int field_nr;
+       uint64_t last_timestamp;        /* to print delta */
        GString *string;        /* Current string */
 };
 
        GString *string;        /* Current string */
 };
 
This page took 0.027042 seconds and 4 git commands to generate.