Add new option --clock-offset-ns
authorIkaheimonen, JP <jp_ikaheimonen@mentor.com>
Thu, 2 May 2013 14:19:33 +0000 (10:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 2 May 2013 14:19:33 +0000 (10:19 -0400)
Add a new option --clock-offset-ns. It requires a parameter
that specifies a clock offset (in nanoseconds) that is added
to each timestamp.

This works exactly as the option --clock-offset, except that
the value is given in nanoseconds instead of full seconds.

The two options --clock-offset and --clock-offset-ns are
compatible with each other, and it's possible to give both.
For example, having the options

--clock-offset 2 --clock-offset-ns 1000000

means that 2.001 seconds is added to each timestamp.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/ctf/ctf.c
include/babeltrace/babeltrace-internal.h

index a34af175f9e817545c3b9ef2cf2863aa487ae151..2fd371c396a9f218c575eaaff704ca2571f33656 100644 (file)
@@ -93,6 +93,7 @@ enum {
        OPT_FIELDS,
        OPT_NO_DELTA,
        OPT_CLOCK_OFFSET,
+       OPT_CLOCK_OFFSET_NS,
        OPT_CLOCK_CYCLES,
        OPT_CLOCK_SECONDS,
        OPT_CLOCK_DATE,
@@ -121,6 +122,7 @@ static struct poptOption long_options[] = {
        { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
        { "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
        { "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
+       { "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
        { "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
        { "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
        { "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
@@ -164,6 +166,7 @@ static void usage(FILE *fp)
        fprintf(fp, "                                     (default: trace:hostname,trace:procname,trace:vpid)\n");
        fprintf(fp, "      --clock-cycles             Timestamp in cycles\n");
        fprintf(fp, "      --clock-offset seconds     Clock offset in seconds\n");
+       fprintf(fp, "      --clock-offset-ns ns       Clock offset in nanoseconds\n");
        fprintf(fp, "      --clock-seconds            Print the timestamps as [sec.ns]\n");
        fprintf(fp, "                                 (default is: [hh:mm:ss.ns])\n");
        fprintf(fp, "      --clock-date               Print clock date\n");
@@ -357,6 +360,29 @@ static int parse_options(int argc, char **argv)
                case OPT_CLOCK_SECONDS:
                        opt_clock_seconds = 1;
                        break;
+               case OPT_CLOCK_OFFSET_NS:
+               {
+                       char *str;
+                       char *endptr;
+
+                       str = (char *) poptGetOptArg(pc);
+                       if (!str) {
+                               fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       errno = 0;
+                       opt_clock_offset_ns = strtoull(str, &endptr, 0);
+                       if (*endptr != '\0' || str == endptr || errno != 0) {
+                               fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
+                               ret = -EINVAL;
+                               free(str);
+                               goto end;
+                       }
+                       free(str);
+                       break;
+               }
+
                case OPT_CLOCK_DATE:
                        opt_clock_date = 1;
                        break;
index 58f937d8f1c9e8708690c81eb15ab95bc7839476..6b292a7e567fff53a00abc1b04f91beae8a7cec3 100644 (file)
@@ -77,6 +77,7 @@ int opt_clock_cycles,
        opt_clock_gmt;
 
 uint64_t opt_clock_offset;
+uint64_t opt_clock_offset_ns;
 
 extern int yydebug;
 
@@ -321,6 +322,9 @@ void ctf_print_timestamp_real(FILE *fp,
 
        ts_nsec = timestamp;
 
+       /* Add command-line offset in ns*/
+        ts_nsec += opt_clock_offset_ns;
+
        /* Add command-line offset */
        ts_sec += opt_clock_offset;
 
index 22866bc9e11573fe9b5de912a69abf9394de4b5c..9b9ffbdf4a7cf2213848c0cbd9437957fddaa8a8 100644 (file)
@@ -220,5 +220,6 @@ extern int opt_all_field_names,
        opt_clock_force_correlate;
 
 extern uint64_t opt_clock_offset;
+extern uint64_t opt_clock_offset_ns;
 
 #endif
This page took 0.027872 seconds and 4 git commands to generate.